Advertisement
kaed

theme-options.php - 7/22/13

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