checkboxes = array(); $this->settings = array(); $this->grab_settings(); $this->sections['general'] = __( 'General Settings', 'bs3mobilefirst' ); $this->sections['about'] = __( 'About', 'bs3mobilefirst' ); add_action( 'admin_menu', array( &$this, 'add_pages' ) ); add_action( 'admin_init', array( &$this, 'register_settings' ) ); if ( ! get_option( 'mytheme_options' ) ) $this->initialize_settings(); } /** * Add options page * * @since 1.0 */ public function add_pages() { $admin_page = add_theme_page( __( 'Theme Options', 'bs3mobilefirst' ), __( 'Theme Options', 'bs3mobilefirst' ), 'edit_theme_options', 'mytheme-options', array( &$this, 'display_page' ) ); add_action( 'admin_print_scripts-' . $admin_page, array( &$this, 'scripts' ) ); add_action( 'admin_print_styles-' . $admin_page, array( &$this, 'styles' ) ); } /** * Create settings field * * @since 1.0 */ public function create_setting( $args = array() ) { $defaults = array( 'id' => 'default_field', 'title' => __( 'Default Field', 'bs3mobilefirst' ), 'desc' => __( 'This is a default description.', 'bs3mobilefirst' ), 'std' => '', 'type' => 'text', 'section' => 'general', 'choices' => array(), 'class' => '' ); extract( wp_parse_args( $args, $defaults ) ); $field_args = array( 'type' => $type, 'id' => $id, 'desc' => $desc, 'std' => $std, 'choices' => $choices, 'label_for' => $id, 'class' => $class ); if ( $type == 'checkbox' ) $this->checkboxes[] = $id; add_settings_field( $id, $title, array( $this, 'display_setting' ), 'mytheme-options', $section, $field_args ); } /** * Display options page * * @since 1.0 */ public function display_page() { echo '

' . __( 'Theme Options', 'bs3mobilefirst' ) . '

'; if ( isset( $_GET['settings-updated'] ) && $_GET['settings-updated'] == true ) echo '

' . __( 'Theme options updated.', 'bs3mobilefirst' ) . '

'; echo '
'; settings_fields( 'mytheme_options' ); echo '
    '; foreach ( $this->sections as $section_slug => $section ) echo '
  • ' . $section . '
  • '; echo '
'; do_settings_sections( $_GET['page'] ); echo '

'; echo '
'; } /** * Description for section * * @since 1.0 */ public function display_section() { // code } /** * Description for About section * * @since 1.0 */ public function display_about_section() { // This displays on the "About" tab. Echo regular HTML here, like so: echo '

BS3 Mobile First Theme

'; echo '

This is a blog style theme for WordPress 3.6 designed with the newest Twitter Bootstrap 3.0. Much of the style is replicated from Bootstrap 3.0\'s website.

'; echo '

Contact

'; echo '

If you have any feature requests or want to report a bug please email me at danecando@gmail.com. Follow Me on Twitter for new themes and other updates @danecando '; } /** * HTML output for text field * * @since 1.0 */ public function display_setting( $args = array() ) { extract( $args ); $options = get_option( 'mytheme_options' ); if ( ! isset( $options[$id] ) && $type != 'checkbox' ) $options[$id] = $std; elseif ( ! isset( $options[$id] ) ) $options[$id] = 0; $field_class = ''; if ( $class != '' ) $field_class = ' ' . $class; switch ( $type ) { case 'heading': echo '

' . $desc . '

'; break; case 'checkbox': echo ' '; break; case 'select': echo ''; if ( $desc != '' ) echo '
' . $desc . ''; break; case 'radio': $i = 0; foreach ( $choices as $value => $label ) { echo ' '; if ( $i < count( $options ) - 1 ) echo '
'; $i++; } if ( $desc != '' ) echo '
' . $desc . ''; break; case 'textarea': echo ''; if ( $desc != '' ) echo '
' . $desc . ''; break; case 'password': echo ''; if ( $desc != '' ) echo '
' . $desc . ''; break; case 'text': default: echo ''; if ( $desc != '' ) echo '
' . $desc . ''; break; } } /** * Settings and defaults * * @since 1.0 */ public function grab_settings() { /* General Settings ===========================================*/ $this->settings['theme_color'] = array( 'section' => 'general', 'title' => __( 'Theme Color', 'bs3mobilefirst' ), 'desc' => __( 'Choose a color for your blog!', 'bs3mobilefirst' ), 'type' => 'select', 'std' => '', 'choices' => array( 'purple' => 'Purple (default)', 'red' => 'Red', 'green' => 'Green', 'yellow' => 'Yellow' ) ); $this->settings['header_logo'] = array( 'section' => 'general', 'title' => __( 'Header Logo', 'bs3mobilefirst' ), 'desc' => __( 'Logo Dimensions: 150px x 30px - Enter the URL to your logo for the theme header.', 'bs3mobilefirst' ), 'type' => 'text', 'std' => '' ); $this->settings['favicon'] = array( 'section' => 'general', 'title' => __( 'Favicon', 'bs3mobilefirst' ), 'desc' => __( 'Enter the URL to your custom favicon. It should be 16x16 pixels in size.', 'bs3mobilefirst' ), 'type' => 'text', 'std' => '' ); $this->settings['custom_css'] = array( 'title' => __( 'Custom Styles', 'bs3mobilefirst' ), 'desc' => __( 'Enter any custom CSS here to apply it to your theme.', 'bs3mobilefirst' ), 'std' => '', 'type' => 'textarea', 'section' => 'general', 'class' => 'code' ); $this->settings['custom_scripts'] = array( 'title' => __( 'Custom Scripts', 'bs3mobilefirst' ), 'desc' => __( 'Enter any custom scripts and Google Analytics code here.', 'bs3mobilefirst' ), 'std' => '', 'type' => 'textarea', 'section' => 'general', 'class' => 'code' ); /* Reset ===========================================*/ $this->settings['reset_theme'] = array( 'section' => 'general', 'title' => __( 'Reset theme', 'bs3mobilefirst' ), 'type' => 'checkbox', 'std' => 0, 'class' => 'warning', // Custom class for CSS 'desc' => __( 'Check this box and click "Save Changes" below to reset theme options to their defaults.', 'bs3mobilefirst' ) ); } /** * Initialize settings to their default values * * @since 1.0 */ public function initialize_settings() { $default_settings = array(); foreach ( $this->settings as $id => $setting ) { if ( $setting['type'] != 'heading' ) $default_settings[$id] = $setting['std']; } update_option( 'mytheme_options', $default_settings ); } /** * Register settings * * @since 1.0 */ public function register_settings() { register_setting( 'mytheme_options', 'mytheme_options', array ( &$this, 'validate_settings' ) ); foreach ( $this->sections as $slug => $title ) { if ( $slug == 'about' ) add_settings_section( $slug, $title, array( &$this, 'display_about_section' ), 'mytheme-options' ); else add_settings_section( $slug, $title, array( &$this, 'display_section' ), 'mytheme-options' ); } $this->grab_settings(); foreach ( $this->settings as $id => $setting ) { $setting['id'] = $id; $this->create_setting( $setting ); } } /** * jQuery Tabs * * @since 1.0 */ public function scripts() { wp_print_scripts( 'jquery-ui-tabs' ); } /** * Styling for the theme options page * * @since 1.0 */ public function styles() { wp_register_style( 'mytheme-admin', get_template_directory_uri() . '/css/mytheme-options.css' ); wp_enqueue_style( 'mytheme-admin' ); } /** * Validate settings * * @since 1.0 */ public function validate_settings( $input ) { if ( ! isset( $input['reset_theme'] ) ) { $options = get_option( 'mytheme_options' ); foreach ( $this->checkboxes as $id ) { if ( isset( $options[$id] ) && ! isset( $input[$id] ) ) unset( $options[$id] ); } return $input; } return false; } } $bs3mf_theme_options = new BS3MF_Theme_Options(); function bs3mf_option( $option ) { $options = get_option( 'mytheme_options' ); if ( isset( $options[$option] ) ) return $options[$option]; else return false; } ?>