所以我有一个插件,有两个用户可自定义的设置。(虽然还不完整,但我正在准备好框架。)当这两个设置位于“常规”设置页面时,它们工作正常。。。
add_action(\'admin_init\', \'mj_admin_init\');
function mj_admin_init(){
register_setting(\'general\', \'mj_options\', \'mj_validate_input\');
add_settings_section(\'mjid\', \'MJ Settings\', \'mj_callback\', \'general\');
add_settings_field(\'mj_notify_email\', \'Email\', \'mj_email_input\', \'general\', \'mjid\');
add_settings_field(\'mj_cm_enabled\', \'Enable Messages\', \'mj_cm_enabled_input\', \'general\', \'mjid\');
}
add_action(\'admin_menu\', \'mj_admin_menu\');
function mj_admin_menu(){
do_settings_sections(\'mjid\');
}
function mj_admin(){
// to-do later
}
function mj_callback(){
echo \'<p>MJ Callback function produced this</p>\';
}
function mj_email_input(){
$options = get_option(\'mj_options\');
$value = $options[\'mj_email\'];
echo \'<input id="mj_email" name="mj_options[mj_email]" type="text" value="\'.esc_attr($value).\'" /> <em>Email address</em>\';
}
function mj_cm_enabled_input(){
$options = get_option(\'mj_options\');
$value = $options[\'cm-enabled\'];
echo \'<input id="cm-enabled" name="mj_options[cm-enabled]" type="checkbox" value=1 \'.checked(1, esc_attr($value), false).\' /> <em>Checkbox for enabled messages</em>\';
}
function mj_validate_input($input){
$valid = array();
$valid[\'mj_email\'] = sanitize_email( $input[\'mj_email\']);
if($valid[\'mj_email\'] != $input[\'mj_email\']) {
add_settings_error(\'mj_email_setting\', \'mj_texterror\', \'Invalid email\', \'error\');
}
$valid[\'cm-enabled\'] = intval($input[\'cm-enabled\']);
return $valid;
}
但我想把它们放在一个单独的子菜单页上,称为“mj管理设置”。但是,不管我怎么努力,他们都不会出现。我得到的只是“mj\\U回调”函数的输出。即使debug设置为true,错误日志中也没有错误。
为了完成上述操作,我更改了mj_admin_init
和mj_admin_menu
功能如下:
add_action(\'admin_init\', \'mj_admin_init\');
function mj_admin_init(){
register_setting(\'mj-admin-settings\', \'mj_options\', \'mj_validate_input\');
add_settings_section(\'mjid\', \'MJ Settings\', \'mj_callback\', \'mj-admin-settings\');
add_settings_field(\'mj_notify_email\', \'Email\', \'mj_email_input\', \'mj-admin-settings\', \'mjid\');
add_settings_field(\'mj_cm_enabled\', \'Enable Messages\', \'mj_cm_enabled_input\', \'mj-admin-settings\', \'mjid\');
}
add_action(\'admin_menu\', \'mj_admin_menu\');
function mj_admin_menu(){
add_menu_page(\'MJ Admin\', \'MJ Admin\', \'manage_options\', \'mj-admin-options\', \'mj_admin\');
add_submenu_page(\'mj-admin-options\', \'MJ Admin - Settings\', \'Settings\', \'manage_options\', \'mj-admin-settings\', \'mj_callback\');
do_settings_sections(\'mjid\');
}
有没有人对如何在子菜单中显示设置有任何想法?我已经翻遍了所有的抄本,我被难住了!