Advertisement
kaed

theme-options.php [working] - 7/11/13

Jul 11th, 2013
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.83 KB | None | 0 0
  1. <?php
  2. //b4b Theme Options Panel
  3. //textarea args = 'id', 'desc'
  4. //checkbox args = 'id','desc'
  5. //select args = 'opt1', 'opt2', 'opt3', 'opt...', 'id', 'desc'
  6.  
  7. function b4b_create_menu_page(){
  8.     add_theme_page(
  9.         'Boundaries For Breaking Options',
  10.         'B4B Options',
  11.         'administrator',
  12.         'b4b_theme_options',
  13.         'b4b_theme_display'
  14.     );
  15. }
  16. add_action('admin_menu', 'b4b_create_menu_page');
  17.  
  18. function b4b_theme_display(){
  19. ?>
  20.     <div class="wrap">
  21.    
  22.         <div id="icon-themes" class="icon32"></div>
  23.         <h2>Boundaries For Breaking Options</h2>
  24.        
  25.         <?php settings_errors(); ?>
  26.        
  27.         <form method="post" action="options.php">
  28.             <?php settings_fields( 'b4b_theme_display_options' ); ?>
  29.             <?php do_settings_sections( 'b4b_theme_display_options') ?>
  30.             <?php submit_button(); ?>
  31.         </form>
  32.        
  33.     </div>
  34. <?php
  35. }
  36.  
  37. /*----------------------------
  38.     register settings
  39. ----------------------------*/
  40. function b4b_init_theme_options(){
  41.     if( false == get_option( 'b4b_theme_display_options' ) ) {
  42.         add_option( 'b4b_theme_display_options' );
  43.     }
  44.  
  45.     //add_settings_section
  46.     add_settings_section(
  47.         'b4b_general_options',
  48.         'General Options',
  49.         'b4b_section_callback',
  50.         'b4b_theme_display_options'
  51.     );
  52.     add_settings_section(
  53.         'b4b_header_options',
  54.         'Header Options',
  55.         'b4b_section_callback',
  56.         'b4b_theme_display_options'
  57.     );
  58.     add_settings_section(
  59.         'b4b_footer_options',
  60.         'Footer Options',
  61.         'b4b_section_callback',
  62.         'b4b_theme_display_options'
  63.     );
  64.  
  65.     //add_settings_field
  66.     add_settings_field(
  67.         'favicon_image',
  68.         'Change favicon',
  69.         'b4b_image_upload_callback',
  70.         'b4b_theme_display_options',
  71.         'b4b_general_options',
  72.         array(
  73.             'Upload & choose a favicon image.'
  74.         )
  75.     );
  76.  
  77.     add_settings_field(
  78.         'number_of_posts',
  79.         'Number of posts on homepage',
  80.         'b4b_textarea_callback',
  81.         'b4b_theme_display_options',
  82.         'b4b_general_options',
  83.         array(
  84.             'number_of_posts',
  85.             'Choose the number of posts displayed on the homepage.'
  86.         )
  87.     );
  88.  
  89.     add_settings_field(
  90.         'share_post_enable',
  91.         'Enable sharing buttons in posts',
  92.         'b4b_checkbox_callback',
  93.         'b4b_theme_display_options',
  94.         'b4b_general_options',
  95.         array(
  96.             'share_post_enable',
  97.             'Check the box to enable social sharing buttons in posts.'
  98.         )
  99.     );
  100.  
  101.     add_settings_field(
  102.         'author_bio_enable',
  103.         'Enable author bio in posts',
  104.         'b4b_checkbox_callback',
  105.         'b4b_theme_display_options',
  106.         'b4b_general_options',
  107.         array(
  108.             'author_bio_enable',
  109.             'Check the box to enable an author bio in posts.'
  110.         )
  111.     );
  112.  
  113.     add_settings_field(
  114.         'header_type',
  115.         'Text or Image header',
  116.         'b4b_select_callback',
  117.         'b4b_theme_display_options',
  118.         'b4b_header_options',
  119.         array(
  120.             'image','text',
  121.             'header_type','Choose the type of header you want.'
  122.         )
  123.     );
  124.  
  125.     add_settings_field(
  126.         'header_image',
  127.         'Header image',
  128.         'b4b_image_upload_callback',
  129.         'b4b_theme_display_options',
  130.         'b4b_header_options',
  131.         array(
  132.             'Upload & choose a header image.'
  133.         )
  134.     );
  135.  
  136.     add_settings_field(
  137.         'header_title',
  138.         'Header title text',
  139.         'b4b_textarea_callback',
  140.         'b4b_theme_display_options',
  141.         'b4b_header_options',
  142.         array(
  143.             'header_title',
  144.             'Type the text you want for the header title.'
  145.         )
  146.     );
  147.  
  148.     add_settings_field(
  149.         'header_slogan',
  150.         'Header slogan text',
  151.         'b4b_textarea_callback',
  152.         'b4b_theme_display_options',
  153.         'b4b_header_options',
  154.         array(
  155.             'header_slogan',
  156.             'Type the text you want for the header slogan.'
  157.         )
  158.     );
  159.  
  160.     add_settings_field(
  161.         'social_icons_enable',
  162.         'Enable social icons',
  163.         'b4b_checkbox_callback',
  164.         'b4b_theme_display_options',
  165.         'b4b_footer_options',
  166.         array(
  167.             'social_icons_enable',
  168.             'Enable/Disable social icons at the end of your posts.'
  169.         )
  170.     );
  171.  
  172.     add_settings_field(
  173.         'footer_text',
  174.         'Text in footer',
  175.         'b4b_textarea_callback',
  176.         'b4b_theme_display_options',
  177.         'b4b_footer_options',
  178.         array(
  179.             'footer_text',
  180.             'Type the text you want in the footer.'
  181.         )
  182.     );
  183.  
  184.     add_settings_field(
  185.         'facebook_url',
  186.         'Facebook url',
  187.         'b4b_textarea_callback',
  188.         'b4b_theme_display_options',
  189.         'b4b_footer_options',
  190.         array(
  191.             'facebook_url',
  192.             'Type in your facebook url.'
  193.         )
  194.     );
  195.  
  196.     add_settings_field(
  197.         'twitter_url',
  198.         'Twitter url',
  199.         'b4b_textarea_callback',
  200.         'b4b_theme_display_options',
  201.         'b4b_footer_options',
  202.         array(
  203.             'twitter_url',
  204.             'Type in your twitter url.'
  205.         )
  206.     );
  207.  
  208.     //register_setting
  209.     register_setting(
  210.         'b4b_theme_display_options',
  211.         'b4b_theme_display_options'
  212.     );
  213. }
  214. add_action('admin_init', 'b4b_init_theme_options');
  215.  
  216. /*----------------------------
  217.     section & field callbacks
  218. ----------------------------*/
  219. function b4b_section_callback(){
  220.  
  221. }
  222.  
  223. function b4b_image_upload_callback(){
  224.  
  225. }
  226.  
  227. function b4b_textarea_callback($args){
  228.     $options = get_option('b4b_theme_display_options');
  229.     $html = '<input type="text" id="' . $args[0] . '" name="b4b_theme_display_options[' . $args[0] . ']" value="' . $options[$args[0]] . '" />';
  230.    
  231.     echo $html;
  232. }
  233.  
  234. function b4b_checkbox_callback($args){
  235.     $options = get_option('b4b_theme_display_options');
  236.     $html = '<input type="checkbox" id="' . $args[0] . '" name="b4b_theme_display_options[' . $args[0] . ']" value="1" ' . checked(1, $options[$args[0]], false) . '/>';
  237.     $html .= '<label for="' . $args[0] . '"> ' . $args[1] . '</label>';
  238.    
  239.     echo $html;
  240. }
  241.  
  242. function b4b_select_callback($args){
  243.     $options = get_option('b4b_theme_display_options');
  244.     $html = '<select id="' . $args[Count($args)-2] . '" name="b4b_theme_display_options[' . $args[Count($args)-2] . ']">';
  245.     foreach($args as $arg){
  246.         if ($args[Count($args)-1] != $arg && $args[Count($args)-2] != $arg){
  247.             $html .= '<option value="' . $arg . '"' . selected($options[$args[Count($args)-2]], $arg, false) . '>' . $arg . '</option>';
  248.         }
  249.     }
  250.     $html .= '</select>';
  251.     $html .= '<label for="' . $args[Count($args)-2] . '">' . $args[Count($args)-1] . '</label>';
  252.    
  253.     echo $html;
  254. }
  255. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement