Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: Editor Options
- */
- /*
- Copyright (C) 2010 - t31os (not that i really care anyway)
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
- if( !class_exists( 'editor_options' ) ) {
- class editor_options {
- // Constructor
- function editor_options() {
- if( is_admin() )
- add_action( 'admin_menu' , array( &$this , 'register_plugin_pages' ) );
- }
- // Register the plugin pages
- function register_plugin_pages() {
- // Parent menu, options general
- add_menu_page(
- 'General Settings', // Page title - What you see in the browser title
- 'Settings', // Menu title - What the menu item is named
- 'update_options_general', // Capability - Capability required to manage this plugin
- 'editor_options_general', // Admin Page - The page name used to query for the plugin
- array( &$this , 'do_options' ) // Callback - The function to be called when the plugin page is requested
- );
- // Add options general as a submenu so the menu title can differ from the menu heading (above)
- add_submenu_page(
- 'editor_options_general', // Parent menu (self)
- 'General Settings', // Page title - What you see in the browser title
- 'General', // Menu title - What the menu item is named
- 'update_options_general', // Capability - Capability required to manage this plugin
- 'editor_options_general', // Admin Page - The page name used to query for the plugin
- array( &$this , 'do_options' ) // Callback - The function to be called when the plugin page is requested
- );
- // Add the privacy submenu
- add_submenu_page(
- 'editor_options_general', // Parent menu
- 'Privacy Settings', // Page title - What you see in the browser title
- 'Privacy', // Menu title - What the menu item is named
- 'update_options_privacy', // Capability - Capability required to manage this plugin
- 'editor_options_privacy', // Admin Page - The page name used to query for the plugin
- array( &$this , 'do_options' ) // Callback - The function to be called when the plugin page is requested
- );
- }
- // Print out the plugin page
- function do_options() {
- // There should always be a request page, it's part of the URL for the pages
- if( !isset( $_REQUEST['page'] ) )
- wp_die('The plugin page was not requested');
- // Now we know it's set, store
- $requested_page = $_REQUEST['page'];
- // Make sure user has the privs
- if( 'editor_options_privacy' == $requested_page ) {
- if( !current_user_can( 'update_options_privacy' ) )
- wp_die('Cheatin Huh!');
- $plugin_page = 'Privacy';
- }
- // Make sure user has the privs
- elseif( 'editor_options_general' == $requested_page ) {
- if( !current_user_can( 'update_options_general' ) )
- wp_die('Cheatin Huh!');
- $plugin_page = 'General';
- }
- else {
- // Else something went wrong, bail out.
- wp_die('Are you sure you requested the right page?');
- }
- // Build valid options array
- $valid_options = array('Submit');
- // If changes were submitted
- if( $_POST ) {
- // Add general options
- if( 'General' == $plugin_page ) {
- $valid_options[] = 'blogname';
- $valid_options[] = 'blogdescription';
- }
- // Add privacy option
- elseif( 'Privacy' == $plugin_page ) {
- $valid_options[] = 'blog_public';
- }
- // If anything else was submitted along with the data, well it's not suppose to be there, so again just bail out..
- foreach( $_POST as $name => $data ) {
- if( !in_array( $name, $valid_options ) ) {
- wp_die('Invalid option found on submission, settings could not be saved.');
- }
- }
- // If we've made this far, we should have options to save (and only valid ones)
- $options = array();
- // Check which page was requested again
- if( 'General' == $plugin_page ) {
- // General options, let's escape any HTML
- $options = array_map('esc_html', $_POST );
- }
- elseif( 'Privacy' == $plugin_page ) {
- // Privacy page, on / off setting, so only need a 0 vs 1 comparision check
- if( isset( $_POST['blog_public'] ) ) {
- if( 1 == $_POST['blog_public'] )
- $options['blog_public'] = '1';
- else
- $options['blog_public'] = '0';
- }
- }
- if( !empty( $options ) ) {
- unset($_POST['submit']); // Let's not save the submit buttons value
- foreach( $options as $option_name => $option_value ) {
- update_option($option_name,$option_value);
- }
- }
- }
- ?>
- <div class="wrap">
- <?php screen_icon('options-general'); ?>
- <h2><?php echo $plugin_page; ?> Settings</h2>
- <form method="post" action="admin.php?page=<?php echo $requested_page; ?>">
- <table class="form-table">
- <?php
- switch( $plugin_page ) {
- case 'General':
- ?>
- <tr valign="top">
- <th scope="row"><label for="blogname"><?php _e('Site Title') ?></label></th>
- <td><input name="blogname" type="text" id="blogname" value="<?php form_option('blogname'); ?>" class="regular-text" /></td>
- </tr>
- <tr valign="top">
- <th scope="row"><label for="blogdescription"><?php _e('Tagline') ?></label></th>
- <td><input name="blogdescription" type="text" id="blogdescription" value="<?php form_option('blogdescription'); ?>" class="regular-text" />
- <span class="description"><?php _e('In a few words, explain what this site is about.') ?></span></td>
- </tr>
- <?php
- break;
- case 'Privacy':
- ?>
- <tr valign="top">
- <th scope="row"><?php _e('Site Visibility') ?> </th>
- <td><fieldset><legend class="screen-reader-text"><span><?php _e('Site Visibility') ?> </span></legend>
- <input id="blog-public" type="radio" name="blog_public" value="1" <?php checked('1', get_option('blog_public')); ?> />
- <label for="blog-public"><?php _e('I would like my site to be visible to everyone, including search engines (like Google, Bing, Technorati) and archivers');?></label><br/>
- <input id="blog-norobots" type="radio" name="blog_public" value="0" <?php checked('0', get_option('blog_public')); ?> />
- <label for="blog-norobots"><?php _e('I would like to block search engines, but allow normal visitors'); ?></label>
- <?php do_action('blog_privacy_selector'); ?>
- </fieldset></td>
- </tr>
- <?php
- break;
- }
- ?>
- </table>
- <p class="submit">
- <input type="submit" name="Submit" class="button-secondary action" value="Save" />
- </p>
- </form>
- </div>
- <?php
- }
- }
- // Instantiate the class
- $editor_options = new editor_options();
- }
- // End class exists statement
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement