Note that there are some explanatory texts on larger screens.

plurals
  1. POTheme options menu item being added to every theme
    text
    copied!<p>I've been working on this theme options page for literally weeks and weeks and ran into one problem after another. Today I released the theme "Cool Orange" to the public thinking everything was ok. Then I went into my Admin panel, switching to another theme to work on and "Cool Orange Theme Options" was showing up as a menu item, but Cool Orange was not activated! A theme options page is only supposed to show up for the currently activated theme.</p> <p>What is strange is that the theme options page showed up as it was supposed to in a Windows Administrator account, but not in the Limited account I'm using. I don't think that should make a difference, though. Can anyone look at my code below and tell me what might be wrong.</p> <pre><code>&lt;?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', '&lt;strong&gt;Upload logo to the Media Library&lt;/strong&gt;', 'file_upload_button', 'coolorange', 'coolorange_logo_main' ); // Upload Logo button add_settings_field( 'image_url', '&lt;strong&gt;Logo location&lt;/strong&gt;', 'file_location', 'coolorange', 'coolorange_logo_main' ); // logo url field ...more add_settings_field sections } function co_theme_options_page() { ?&gt; &lt;div class="wrap" style="margin-bottom: 20px;"&gt; &lt;div id="icon-themes" class="icon32"&gt;&lt;br /&gt;&lt;/div&gt;&lt;h2&gt;Cool Orange Theme Options&lt;/h2&gt; &lt;?php if($_REQUEST['settings-updated'] == 'true') { echo '&lt;div id="message" class="updated fade"&gt;&lt;p&gt;Cool Orange options saved.&lt;/p&gt;&lt;/div&gt;'; } ?&gt; &lt;form action="options.php" method="post" name="options_form"&gt; &lt;?php settings_fields('coolorange_theme_options'); ?&gt; &lt;?php do_settings_sections('coolorange'); ?&gt; &lt;div style="text-align: center; padding: 20px;"&gt;&lt;input name="Submit" class="button-primary" type="submit" value="&lt;?php esc_attr_e('Save Changes'); ?&gt;" /&gt;&lt;/div&gt; &lt;/form&gt; &lt;/div&gt; &lt;?php } function logo_section_text() { ?&gt; &lt;p&gt;In this section, you can replace the standard blog title heading with a custom logo. The logo cannot be wider than &lt;strong&gt;960 pixels&lt;/strong&gt;.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;How to upload a logo to replace the heading:&lt;/strong&gt;&lt;/p&gt; &lt;div style="background-color: #FFFFFF; border: 1px solid #BBBBBB; padding: 30px; margin-bottom: 10px;"&gt; ...logo upload instructions &lt;/div&gt; &lt;?php } function file_upload_button() { $options = get_option('coolorange_theme_options'); echo '&lt;input id="upload_image_button" class="button-secondary" type="button" name="coolorange_theme_options[upload_image_button]" value="Upload Logo" /&gt;'; } //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']) &amp;&amp; $_GET['page'] == 'coolorange') { add_action('admin_print_scripts', 'my_admin_scripts'); add_action('admin_print_styles', 'my_admin_styles'); } ?&gt; &lt;?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']; ?&gt; &lt;style type="text/css"&gt; &lt;!-- #logo { &lt;?php if ($backgroundurl) echo "background: url(" . $coolorange_settings['image_url'] . ") top center no-repeat"; else echo "background: transparent"; ?&gt;; width: &lt;?php if ($imagewidth) echo $imagewidth; else echo "auto"; ?&gt;; height: &lt;?php if ($imageheight) echo $imageheight; else echo "auto"; ?&gt;; padding-top: &lt;?php if ($paddingtop) echo $paddingtop; else echo "1em"; ?&gt;; padding-right: &lt;?php if ($paddingright) echo $paddingright; else echo "2em"; ?&gt;; padding-bottom: &lt;?php if ($paddingbottom) echo $paddingbottom; else echo "1em"; ?&gt;; padding-left: &lt;?php if ($paddingleft) echo $paddingleft; else echo "2em"; ?&gt;; margin: 0 auto; } #blog-title a { display: block; width: &lt;?php if ($imagewidth) echo $imagewidth; else echo "auto"; ?&gt;; height: &lt;?php if ($imageheight) echo $imageheight; else echo "auto"; ?&gt;; text-indent: &lt;?php if ( $removetitle ) echo "-2000px"; else echo "0"; ?&gt;; } #blog-description { text-indent: &lt;?php if ( $removetitle ) echo "-2000px"; else echo "0"; ?&gt;; } --&gt; &lt;/style&gt; &lt;?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 '&lt;div id="message" style="color: red;"&gt;&lt;p&gt;File type must have the file extension .jpg, .jpeg, .gif or .png&lt;/p&gt;&lt;/div&gt;'; } // 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 '&lt;div id="message" style="color: red;"&gt;&lt;p&gt;Padding top must be specified in px, em or %&lt;/p&gt;&lt;/div&gt;'; } //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']) &amp;&amp; isset($_GET['page']) == 'coolorange') // add_action('admin_notices', 'coolorange_options_validate'); //shows validation errors at the top of the page ?&gt; </code></pre> <p>I left out some repetitive code for brevity.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload