Advertisement
Guest User

WordPress Options Page

a guest
Dec 31st, 2011
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.60 KB | None | 0 0
  1. <?php
  2.  
  3. // My First Options Page = mfop
  4.  
  5. /*-- GLOBAL VARIABLES -- */
  6. $mfop_options = get_option('mfop_theme_options');
  7.  
  8. /**
  9. * add Theme options page - under "Appearance" submenu
  10. */
  11.  
  12. function mfop_admin_page() {
  13.     add_theme_page(
  14.         __( 'Theme Options Page', 'mytheme' ),
  15.         __( 'Theme Options Menu', 'mytheme' ),
  16.         'edit_theme_options',
  17.         'sections_name',
  18.         'mfop_options_builder');
  19. }
  20. add_action('admin_menu', 'mfop_admin_page');
  21.  
  22.    /**
  23.     * Initialize admin pages
  24.     */
  25.  
  26. function mfop_admin_init(){
  27.  
  28.     register_setting( 'mfop_options', 'mfop_theme_options', 'mfop_options_validate' );
  29.     add_settings_section('mfop_main', __( 'Main Settings Page:', 'mytheme' ), 'mfop_section_text', 'sections_name');
  30.     add_settings_field('enable_checkbox', __( 'Enable Box:', 'mytheme' ), 'mfop_setting_checkbox', 'sections_name', 'mfop_main');
  31.     add_settings_field('mfop_text_string', __( 'Text Input:', 'mytheme' ), 'mfop_setting_text', 'sections_name', 'mfop_main');
  32.      add_settings_field('color_scheme', __( 'Color Scheme Selection:', 'mytheme' ), 'mfop_color_scheme_setting', 'sections_name', 'mfop_main');
  33.  
  34. }
  35. add_action('admin_init', 'mfop_admin_init');
  36.  
  37. /*
  38. * Options builder - using Settings API
  39. * No more Tables!
  40. */
  41.  
  42. function mfop_options_builder() {
  43.     ?>
  44.     <div class="wrap">
  45.         <?php screen_icon(); ?>
  46.         <h2><?php _e( 'My Theme Options Page', 'mytheme' ); ?></h2>
  47.        
  48.         <form method="post" action="options.php">
  49.             <?php
  50.                 settings_fields( 'mfop_options' );
  51.                 do_settings_sections( 'sections_name' );
  52.                 submit_button();
  53.             ?>
  54.         </form>
  55.     </div>
  56.     <?php
  57. }
  58.  
  59.    
  60.     /**
  61.     *  Callback ee add_settings_field() waxa la waafajinayaa
  62.     */
  63.    
  64. // CHECKBOX
  65. function mfop_setting_checkbox() {
  66.     global $mfop_options;
  67.     if($mfop_options['enable']) { $checked = ' checked="checked" '; }
  68.     echo "<input ".$checked." id='enable_checkbox' name='mfop_theme_options[enable]' type='checkbox' />";
  69. }
  70.  
  71. // TWITTER
  72. function mfop_setting_text() {
  73.     global $mfop_options;
  74.     echo "<input id='mfop_text_string' name='mfop_theme_options[twitter_url]' size='40' type='text' value='{$mfop_options['twitter_url']}' />";
  75. }
  76.  
  77. // COLOR SCHEME
  78.  
  79. function mfop_color_scheme_setting() {
  80.    global $mfop_options;
  81.    $items = array("Red", "Blue");
  82.  
  83.    echo "<select name='mfop_theme_options[color_scheme]'>";
  84.    foreach ($items as $item) {
  85.       $selected = ( $mfop_options['color_scheme'] === $item ) ? 'selected = "selected"' : '';
  86.       echo "<option value='$item' $selected>$item</option>";
  87.    }
  88.    echo "</select>";
  89. }              
  90.     /**
  91.     * Validate options
  92.     */
  93. function mfop_options_validate  () {}
  94. function mfop_section_text () {}
  95. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement