Advertisement
kaed

theme-options.php - 7/11/13

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