Advertisement
kaed

theme-options.php - end of 7/11/13

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