如何解决主题选项菜单项已添加到每个主题
| 我一直在这个主题选项页面上工作了好几个星期,然后又遇到了另一个问题。今天,我向公众发布了主题“酷橙”,认为一切都很好。然后,进入管理面板,切换到另一个主题进行处理,并且“ Cool Orange Theme Options”作为菜单项显示,但未激活Cool Orange!仅应针对当前激活的主题显示主题选项页面。 奇怪的是,主题选项页显示为应该在Windows Administrator帐户中显示的状态,而不是在我正在使用的Limited帐户中显示的状态。不过,我认为这不会有所作为。谁能看下面我的代码,然后告诉我可能是什么错误。<?PHP
// This options page mainly follows the wordpress Settings API Tutorial at
// http://ottodestruct.com/blog/2009/wordpress-settings-api-tutorial/
add_action(\'admin_init\',\'co_admin_init\');
add_action(\'admin_menu\',\'co_admin_add_page\');
function co_admin_add_page() {
add_theme_page(
\'Cool Orange Theme Options\',\'Cool Orange Theme Options\',\'manage_options\',\'coolorange\',\'co_theme_options_page\'
);
}
function co_admin_init() {
register_setting(
\'coolorange_theme_options\',\'coolorange_theme_options\',\'coolorange_options_validate\'
);
// what each parameter represents:
// add_settings_field($id,$title,$callback,$page,$section,$args);
add_settings_section(
\'coolorange_logo_main\',\'logo Section Settings\',\'logo_section_text\',\'coolorange\'
);
add_settings_field(
\'upload_image_button\',\'<strong>Upload logo to the Media Library</strong>\',\'file_upload_button\',\'coolorange_logo_main\'
); // Upload logo button
add_settings_field(
\'image_url\',\'<strong>logo location</strong>\',\'file_location\',\'coolorange_logo_main\'
); // logo url field
...more add_settings_field sections
}
function co_theme_options_page() {
?>
<div class=\"wrap\" style=\"margin-bottom: 20px;\">
<div id=\"icon-themes\" class=\"icon32\"><br /></div><h2>Cool Orange Theme Options</h2>
<?PHP if($_REQUEST[\'settings-updated\'] == \'true\') {
echo \'<div id=\"message\" class=\"updated fade\"><p>Cool Orange options saved.</p></div>\';
} ?>
<form action=\"options.PHP\" method=\"post\" name=\"options_form\">
<?PHP settings_fields(\'coolorange_theme_options\'); ?>
<?PHP do_settings_sections(\'coolorange\'); ?>
<div style=\"text-align: center; padding: 20px;\"><input name=\"Submit\" class=\"button-primary\" type=\"submit\" value=\"<?PHP esc_attr_e(\'Save Changes\'); ?>\" /></div>
</form>
</div>
<?PHP
}
function logo_section_text() { ?>
<p>In this section,you can replace the standard blog title heading with a custom logo. The logo cannot be wider than <strong>960 pixels</strong>.</p>
<p><strong>How to upload a logo to replace the heading:</strong></p>
<div style=\"background-color: #FFFFFF; border: 1px solid #BBBBBB; padding: 30px; margin-bottom: 10px;\">
...logo upload instructions
</div>
<?PHP }
function file_upload_button() {
$options = get_option(\'coolorange_theme_options\');
echo \'<input id=\"upload_image_button\" class=\"button-secondary\" type=\"button\" name=\"coolorange_theme_options[upload_image_button]\" value=\"Upload logo\" />\';
}
//Scripts to load WP\'s Media Library panel
//http://www.webmaster-source.com/2010/01/08/using-the-wordpress-uploader-in-your-plugin-or-theme/
// Associated with file_upload_button function
function my_admin_scripts() {
wp_enqueue_script(\'media-upload\');
wp_enqueue_script(\'thickBox\');
wp_register_script(\'my-upload\',trailingslashit( get_stylesheet_directory_uri()).\'scripts/invoke_uploader.js\',array(\'jquery\',\'media-upload\',\'thickBox\'));
wp_enqueue_script(\'my-upload\');
}
function my_admin_styles() {
wp_enqueue_style(\'thickBox\');
}
if (isset($_GET[\'page\']) && $_GET[\'page\'] == \'coolorange\') {
add_action(\'admin_print_scripts\',\'my_admin_scripts\');
add_action(\'admin_print_styles\',\'my_admin_styles\');
} ?>
<?PHP
... more settings functions
function logo_css() {
global $coolorange_theme_options;
$coolorange_settings = get_option(\'coolorange_theme_options\');
$backgroundurl = $coolorange_settings[\'image_url\'];
$imagewidth = $coolorange_settings[\'image_width\'];
$imageheight = $coolorange_settings[\'image_height\'];
$paddingtop = $coolorange_settings[\'padding_top\'];
$paddingright = $coolorange_settings[\'padding_right\'];
$paddingbottom = $coolorange_settings[\'padding_bottom\'];
$paddingleft = $coolorange_settings[\'padding_left\'];
$removetitle = $coolorange_settings[\'remove_blogtitle\']; ?>
<style type=\"text/css\">
<!--
#logo {
<?PHP if ($backgroundurl) echo \"background: url(\" . $coolorange_settings[\'image_url\'] . \") top center no-repeat\";
else echo \"background: transparent\"; ?>;
width: <?PHP if ($imagewidth) echo $imagewidth; else echo \"auto\"; ?>;
height: <?PHP if ($imageheight) echo $imageheight; else echo \"auto\"; ?>;
padding-top: <?PHP if ($paddingtop) echo $paddingtop; else echo \"1em\"; ?>;
padding-right: <?PHP if ($paddingright) echo $paddingright; else echo \"2em\"; ?>;
padding-bottom: <?PHP if ($paddingbottom) echo $paddingbottom; else echo \"1em\"; ?>;
padding-left: <?PHP if ($paddingleft) echo $paddingleft; else echo \"2em\"; ?>;
margin: 0 auto;
}
#blog-title a {
display: block;
width: <?PHP if ($imagewidth) echo $imagewidth; else echo \"auto\"; ?>;
height: <?PHP if ($imageheight) echo $imageheight; else echo \"auto\"; ?>;
text-indent: <?PHP if ( $removetitle ) echo \"-2000px\"; else echo \"0\"; ?>;
}
#blog-description {
text-indent: <?PHP if ( $removetitle ) echo \"-2000px\"; else echo \"0\"; ?>;
}
-->
</style>
<?PHP } //closes logo_css function
add_action(\'wp_head\',\'logo_css\');
//Validation
function coolorange_options_validate($input) { // opens coolorange_options_validate function
$options = get_option(\'coolorange_theme_options\');
//check filetypes for image url
$options[\'image_url\'] = trim($input[\'image_url\']);
//var_dump($options); // for debugging
if ( !preg_match ( \'/\\.(gif|jpg|jpeg|png)$/\',$options[\'image_url\'] ) ) { //opens if statement
$options[\'image_url\'] = \'\';
//echo \'<div id=\"message\" style=\"color: red;\"><p>File type must have the file extension .jpg,.jpeg,.gif or .png</p></div>\';
} // closes if statement
...more validation code
//check input on padding left to make sure it includes only numbers,letters and the percentage sign
$options[\'padding_left\'] = trim($input[\'padding_left\']);
if ( !preg_match ( \'/[0-9](px|em|%)/\',$options[\'padding_left\'] ) ) {
$options[\'padding_left\'] = \'\';
//echo \'<div id=\"message\" style=\"color: red;\"><p>Padding top must be specified in px,em or %</p></div>\';
}
//check if checkBox has been checked
$options[\'remove_blogtitle\'] = $input[\'remove_blogtitle\'];
if ( !isset( $input[\'remove_blogtitle\'] ) ) {
$input[\'remove_blogtitle\'] = null;
}
return $options;
} // closes coolorange_options_validate function
//if (isset($_GET[\'page\']) && isset($_GET[\'page\']) == \'coolorange\')
// add_action(\'admin_notices\',\'coolorange_options_validate\'); //shows validation errors at the top of the page
?>
为了简洁起见,我省略了一些重复的代码。
解决方法
谢谢Stack 101的评论。事实证明,我一直使用的主题是“酷橙”,因为它以cookie的形式存储在我的浏览器中。在我写这篇文章的时候,我没有想到我激活了主题切换器插件并使用它来切换到酷橙主题这一事实。
主题切换器存储cookie中使用的主题。该Cookie会覆盖WP管理面板的主题激活。当我从浏览器中删除了Cool Orange的单个cookie时,每个主题的“外观”面板都恢复了正常状态。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。