Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //b4b Theme Options Panel
- //textarea args = 'id', 'desc'
- //checkbox args = 'id','desc'
- //select args = 'opt1', 'opt2', 'opt3', 'opt...', 'id', 'desc'
- function b4b_create_menu_page(){
- add_theme_page(
- 'Boundaries For Breaking Options',
- 'B4B Options',
- 'administrator',
- 'b4b_theme_options',
- 'b4b_theme_display'
- );
- }
- add_action('admin_menu', 'b4b_create_menu_page');
- function b4b_theme_display(){
- ?>
- <div class="wrap">
- <div id="icon-themes" class="icon32"></div>
- <h2>Boundaries For Breaking Options</h2>
- <?php settings_errors(); ?>
- <form method="post" action="options.php">
- <?php settings_fields( 'b4b_theme_display_options' ); ?>
- <?php do_settings_sections( 'b4b_theme_display_options') ?>
- <?php submit_button(); ?>
- </form>
- </div>
- <?php
- }
- /*----------------------------
- register settings
- ----------------------------*/
- function b4b_init_theme_options(){
- if( false == get_option( 'b4b_theme_display_options' ) ) {
- add_option( 'b4b_theme_display_options' );
- }
- //add_settings_section
- add_settings_section(
- 'b4b_general_options',
- 'General Options',
- 'b4b_section_callback',
- 'b4b_theme_display_options'
- );
- add_settings_section(
- 'b4b_header_options',
- 'Header Options',
- 'b4b_section_callback',
- 'b4b_theme_display_options'
- );
- add_settings_section(
- 'b4b_footer_options',
- 'Footer Options',
- 'b4b_section_callback',
- 'b4b_theme_display_options'
- );
- //add_settings_field
- add_settings_field(
- 'favicon_image',
- 'Change favicon',
- 'b4b_image_upload_callback',
- 'b4b_theme_display_options',
- 'b4b_general_options',
- array(
- 'Upload & choose a favicon image.'
- )
- );
- add_settings_field(
- 'number_of_posts',
- 'Number of posts on homepage',
- 'b4b_textarea_callback',
- 'b4b_theme_display_options',
- 'b4b_general_options',
- array(
- 'number_of_posts',
- 'Choose the number of posts displayed on the homepage.'
- )
- );
- add_settings_field(
- 'share_post_enable',
- 'Enable sharing buttons in posts',
- 'b4b_checkbox_callback',
- 'b4b_theme_display_options',
- 'b4b_general_options',
- array(
- 'share_post_enable',
- 'Check the box to enable social sharing buttons in posts.'
- )
- );
- add_settings_field(
- 'author_bio_enable',
- 'Enable author bio in posts',
- 'b4b_checkbox_callback',
- 'b4b_theme_display_options',
- 'b4b_general_options',
- array(
- 'author_bio_enable',
- 'Check the box to enable an author bio in posts.'
- )
- );
- add_settings_field(
- 'header_type',
- 'Text or Image header',
- 'b4b_select_callback',
- 'b4b_theme_display_options',
- 'b4b_header_options',
- array(
- 'image','text',
- 'header_type','Choose the type of header you want.'
- )
- );
- add_settings_field(
- 'header_image',
- 'Header image',
- 'b4b_image_upload_callback',
- 'b4b_theme_display_options',
- 'b4b_header_options',
- array(
- 'Upload & choose a header image.'
- )
- );
- add_settings_field(
- 'header_title',
- 'Header title text',
- 'b4b_textarea_callback',
- 'b4b_theme_display_options',
- 'b4b_header_options',
- array(
- 'header_title',
- 'Type the text you want for the header title.'
- )
- );
- add_settings_field(
- 'header_slogan',
- 'Header slogan text',
- 'b4b_textarea_callback',
- 'b4b_theme_display_options',
- 'b4b_header_options',
- array(
- 'header_slogan',
- 'Type the text you want for the header slogan.'
- )
- );
- add_settings_field(
- 'social_icons_enable',
- 'Enable social icons',
- 'b4b_checkbox_callback',
- 'b4b_theme_display_options',
- 'b4b_footer_options',
- array(
- 'social_icons_enable',
- 'Enable/Disable social icons at the end of your posts.'
- )
- );
- add_settings_field(
- 'footer_text',
- 'Text in footer',
- 'b4b_textarea_callback',
- 'b4b_theme_display_options',
- 'b4b_footer_options',
- array(
- 'footer_text',
- 'Type the text you want in the footer.'
- )
- );
- add_settings_field(
- 'facebook_url',
- 'Facebook url',
- 'b4b_textarea_callback',
- 'b4b_theme_display_options',
- 'b4b_footer_options',
- array(
- 'facebook_url',
- 'Type in your facebook url.'
- )
- );
- add_settings_field(
- 'twitter_url',
- 'Twitter url',
- 'b4b_textarea_callback',
- 'b4b_theme_display_options',
- 'b4b_footer_options',
- array(
- 'twitter_url',
- 'Type in your twitter url.'
- )
- );
- //register_setting
- register_setting(
- 'b4b_theme_display_options',
- 'b4b_theme_display_options'
- );
- }
- add_action('admin_init', 'b4b_init_theme_options');
- /*----------------------------
- section & field callbacks
- ----------------------------*/
- function b4b_section_callback(){
- }
- function b4b_image_upload_callback(){
- }
- function b4b_textarea_callback($args){
- $options = get_option('b4b_theme_display_options');
- $html = '<input type="text" id="' . $args[0] . '" name="b4b_theme_display_options[' . $args[0] . ']" value="' . $options[$args[0]] . '" />';
- echo $html;
- }
- function b4b_checkbox_callback($args){
- $options = get_option('b4b_theme_display_options');
- $html = '<input type="checkbox" id="' . $args[0] . '" name="b4b_theme_display_options[' . $args[0] . ']" value="1" ' . checked(1, $options[$args[0]], false) . '/>';
- $html .= '<label for="' . $args[0] . '"> ' . $args[1] . '</label>';
- echo $html;
- }
- function b4b_select_callback($args){
- $options = get_option('b4b_theme_display_options');
- $html = '<select id="' . $args[Count($args)-2] . '" name="b4b_theme_display_options[' . $args[Count($args)-2] . ']">';
- foreach($args as $arg){
- if ($args[Count($args)-1] != $arg && $args[Count($args)-2] != $arg){
- $html .= '<option value="' . $arg . '"' . selected($options[$args[Count($args)-2]], $arg, false) . '>' . $arg . '</option>';
- }
- }
- $html .= '</select>';
- $html .= '<label for="' . $args[Count($args)-2] . '">' . $args[Count($args)-1] . '</label>';
- echo $html;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement