Advertisement
kaed

7/5/12 - better-options.php

Jul 5th, 2013
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.40 KB | None | 0 0
  1. <?php
  2. //this is better-options.  a successor to the non-working theme-options
  3.  
  4. //format for select args: 'options'..., 'label text'
  5. //format for text input args: 'id', 'label text'
  6.  
  7. //settings registration
  8. add_action('admin_init', 'fuckinround_initialize_theme_options');
  9. function fuckinround_initialize_theme_options() {
  10.    
  11.     //register sections
  12.     add_settings_section(
  13.         'general_settings_section',
  14.         'General Settings',
  15.         'fuckinround_general_options_callback',
  16.         'general'
  17.     );
  18.    
  19.     //register fields
  20.     add_settings_field(
  21.         'type_of_logo',
  22.         'Type of Logo',
  23.         'fuckinround_type_of_logo_callback',
  24.         'general',
  25.         'general_settings_section',
  26.         array(
  27.             'text', 'logo',
  28.             'Choose whether you\'d like a text or image logo.'
  29.         )
  30.     );
  31.    
  32.     add_settings_field(
  33.         'logo_text',
  34.         'Logo Text',
  35.         'fuckinround_logo_text_input_callback',
  36.         'general',
  37.         'general_settings_section',
  38.         array(
  39.             'logo_text',
  40.             'Enter text for the logo.'
  41.         )
  42.     );
  43.    
  44.     add_settings_field(
  45.         'logo_slogan',
  46.         'Logo Slogan',
  47.         'fuckinround_logo_text_input_callback',
  48.         'general',
  49.         'general_settings_section',
  50.         array(
  51.             'logo_slogan',
  52.             'Enter text for the slogan'
  53.         )
  54.     );
  55.    
  56.     //register fields w/ wp
  57.     register_setting(
  58.         'general',
  59.         'type_of_logo'
  60.     );
  61.    
  62.     register_setting(
  63.         'general',
  64.         'logo_text'
  65.     );
  66.    
  67.     register_setting(
  68.         'general',
  69.         'logo_slogan'
  70.     );
  71.    
  72. }
  73.  
  74.  
  75. //section callbacks
  76. function fuckinround_general_options_callback(){
  77.     echo '<p>This is the general settings area.</p>';
  78. }
  79.  
  80.  
  81. //field callbacks
  82. function fuckinround_type_of_logo_callback($args){
  83.     $html = '<select id="type_of_logo" name="type_of_logo">';
  84.     foreach($args as $arg){
  85.         if ($args[Count($args)-1] != $arg){
  86.             $html .= '<option value="' . $arg . '"' . selected(get_option('type_of_logo'), $arg, false) . '>' . $arg . '</option>';
  87.         }
  88.     }
  89.     $html .= '</select>';
  90.     $html .= '<label for="type_of_logo">' . $args[Count($args)-1] . '</label>';
  91.     echo $html;
  92. }
  93.  
  94. function fuckinround_logo_text_input_callback($args){
  95.     $html = '<input type="text" id="' . $args[0] . '" name="' . $args[0] . '" value="' . get_option($args[0]) . '" />';
  96.     $html .= '<label for="' . $args[0] . '">' . $args[1] . '</label>';
  97.     echo $html;
  98. }
  99.  
  100.  
  101. //menu/submenu/theme options page
  102. function fuckinround_create_menu_page(){
  103.  
  104.     add_menu_page(
  105.         'Aw Yiss.  Motha. Fuckin. Menu',
  106.         'Click here hoe',
  107.         'administrator',
  108.         'fuckinround',
  109.         'fuckinround_menu_page_display',
  110.         ''
  111.     );
  112.    
  113.     add_submenu_page(
  114.         'fuckinround',
  115.         'Aw Yiss.  Motha. Fuckin. Sub Menu.',
  116.         '#YOLO420SWAG',
  117.         'administrator',
  118.         'fuckinround_options',
  119.         'fuckinround_options_display'
  120.     );
  121.    
  122.     add_theme_page(
  123.         'Aw Yiss. Motha. Fuckin. Options.',
  124.         'Aw Yiss. Motha. Fuckin. Options.',
  125.         'administrator',
  126.         'fuckinround_theme_options',
  127.         'fuckinround_theme_display'
  128.     );
  129.    
  130. }
  131. add_action('admin_menu', 'fuckinround_create_menu_page');  
  132.  
  133. function fuckinround_menu_page_display(){
  134.     $html = '<div class="wrap">';
  135.         $html .= '<h2>' . wp_get_theme()->Name . ' Awesome Ass Menu</h2>';
  136.     $html .= '</div>';
  137.     echo $html;
  138. }
  139.  
  140. function fuckinround_options_display(){
  141.     $html = '<div class="wrap">';
  142.         $html .= '<h2>' . wp_get_theme()->Name . ' Awesome Ass SubMenu</h2>';
  143.     $html .= '</div>';
  144.     echo $html;
  145. }
  146.  
  147. function fuckinround_theme_display(){
  148.     $html = '<div class="wrap">';
  149.         $html .= '<h2>' . wp_get_theme()->Name . ' Awesome Ass Options</h2>';
  150.     $html .= '</div>';
  151.     echo $html;
  152. }
  153. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement