我有一个表单,它将数据发送到options.php。之后,保存的值将被导入并导入textarea。
<form method="post" action="options.php">
<?php
settings_fields( 'my_option_group' );
do_settings_sections( 'my_settings_admin' );
submit_button();
?>
</form>
此代码有效,但如果我想手动保存DB某个默认值,则该值不会进入textarea的值。我使用add_option
或update_option
。
答案 0 :(得分:0)
了解此流程以将值保存到数据库
/* code for adding menu and options in admin */
add_action('admin_menu','admin_menu_adding');
add_action('admin_init','admin_reg_settings');
function admin_menu_adding(){
add_menu_page('Mega Page','Mega Page','administrator','mega-page','settings_page_test');
}
function settings_page_test(){
echo "test";
?>
<form method="post" action="<?php echo admin_url('admin.php'); ?>">
<?php
settings_fields('local-settings');
do_settings_sections('local-settings');
?>
<?php submit_button(); ?>
<input type="hidden" name="action" value="trotbgo" />
</form>
<?php
}
add_action('admin_action_trotbgo','save_value_here');
function save_value_here(){
update_option() //update option goes here
exit;
}
function admin_reg_settings(){
register_setting('local-settings','fieldone');
register_setting('local-settings','fieldtwo');
}
您需要通过add_option/update_option
内部save_value_here()
功能