kaed

7/2/13 - better-options.php

Jul 2nd, 2013
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.20 KB | None | 0 0
  1. <?php
  2. //this is better-options.  a successor to the non-working theme-options.php
  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. ?>
Advertisement
Add Comment
Please, Sign In to add comment