2011-06-12 87 views
0

我一直在这个主题选项页面上工作几个星期和几周,并遇到一个接一个的问题。今天,我向公众发布了主题“酷橙”,认为一切都很好。然后我进入我的管理面板,切换到另一个主题进行工作,“酷橙主题选项”显示为菜单项,但酷橙没有激活!主题选项页面只能显示当前激活的主题。主题选项菜单项被添加到每个主题

奇怪的是,主题选项页面显示为它应该在Windows管理员帐户中,但不是在我使用的有限帐户中。不过,我认为这不应该有所作为。任何人都可以看看我的代码,告诉我什么可能是错的。

<?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', 
     'coolorange_logo_main' 
    ); // Upload Logo button 
    add_settings_field(
     'image_url', 
     '<strong>Logo location</strong>', 
     'file_location', 
     'coolorange', 
     '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 
?> 

为了简洁,我省略了一些重复的代码。

+0

你试过检查当前主题吗? 'get_current_theme()',如果它是你的,否则跳过。 – Sparkup 2011-06-12 06:39:19

回答

0

谢谢Stack 101的评论。事实证明,我一直在使用的主题是Cool Orange,因为它在我的浏览器中存储为cookie。在我写这篇文章的时候,我没有想到我已经启用了Theme Switcher插件并且正在使用它切换到Cool Orange主题。

主题切换器存储在cookie中使用哪个主题。此Cookie将覆盖WP管理控制台的主题激活。当我从浏览器中删除Cool Orange的单个cookie时,每个主题的外观面板恢复正常。

相关问题