我正在开发一个库插件。因此,我创建了一个自定义的帖子类型,并在它下面创建了一个子菜单页面,用于更改图库选项,如边框宽度、边框颜色、边框半径等。当我更新值时,所有值都在工作,但更新通知不显示。我在这里写主要代码。请告诉我出了什么问题。
function gallery_setting_pages() {
add_submenu_page(
'edit.php?post_type=gallary',
'Gallery Settings',
'Settings',
'manage_options',
'gallery-setting',
'gallery_option_page_functions'
);
}
add_action('admin_menu','gallery_setting_pages');
if ( is_admin() ) :
function ppmscrollbar_register_settings() {
register_setting('gallery_plugin_options','rt_gallery_options','rt_gallery_validate_options');
}
add_action('admin_init','ppmscrollbar_register_settings');
function gallery_option_page_functions() {
global $rt_gallery_options;
if ( ! isset ($_REQUEST['updated'] ) )
$_REQUEST['updated']=false;
?>
<?php if ( false !==$_REQUEST['updated'] ) : ?>
<div class="updated fade"><p><strong><?php _e('options saved'); ?></strong></p></div>
<?php endif; // If the form has just been submitted, this show the notification ?>
<form method="post" action="options.php">
<?php $settings=get_option( 'rt_gallery_options', $rt_gallery_options); ?>
<?php settings_fields('gallery_plugin_options'); ?>
<table class="form-table">
<tr valign="top">
<th scope="row"><label for="cursor_color">Select Gallery Border Color</label></th>
<td>
<input id="cursor_color" type="text" name="rt_gallery_options[cursor_color]" value="<?php echo stripslashes($settings['cursor_color']); ?>" class="my-color-field" /><p class="description">In a few words, explain what is this.</p>
</td>
</tr>
</table>
<p class="submit"><input type="submit" value="Save Changes" class="button button-primary" id="submit" name="submit"></p>
</form>
</div>
<?php
}
function rt_gallery_validate_options( $input ){
global $rt_gallery_options;
$settings = get_option( 'rt_gallery_options', $rt_gallery_options );
//We strip all tags from the text field, to avoid vulnerablilties like XSS
$input['cursor_color']=wp_filter_post_kses( $input['cursor_color']);
return $input;
}
endif; //EndIf is_admin()
感谢您在stackoverflow上发布此问题以获取答案。我们是来帮助你的。请提及您在上面使用的页面名称,并让我知道您在哪里更新页面中的变量"updated"。问题可能是,若并没有设置变量,那个么条件总是失败,并且不会显示通知。