add_menu( array( 'parent' => false, 'id' => 'asteroid_admin_bar', 'title' => ('Asteroid Options'), 'href' => admin_url( 'themes.php?page=asteroid-options') )); $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'theme_editor_admin_bar', 'title' => ('Editor'), 'href' => admin_url( 'theme-editor.php') )); $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'plugins_admin_bar', 'title' => ('Plugins'), 'href' => admin_url( 'plugins.php') )); } } add_action( 'admin_bar_menu', 'asteroid_admin_bar_menu', 88 ); class Asteroid_Theme_Options { private $sections; private $checkboxes; private $settings; public function __construct() { $this->checkboxes = array(); $this->settings = array(); $this->get_option(); $this->sections['general'] = __( 'General', 'asteroid' ); $this->sections['appearance'] = __( 'Appearance', 'asteroid' ); $this->sections['post-page'] = __( 'Posts & Pages', 'asteroid' ); $this->sections['widget-areas'] = __( 'Widget Areas', 'asteroid' ); $this->sections['custom-css'] = __( 'Custom CSS', 'asteroid' ); $this->sections['misc'] = __( 'Misc', 'asteroid' ); $this->sections['reset'] = __( 'Reset', 'asteroid' ); add_action( 'admin_menu', array( &$this, 'ast_add_pages' ) ); add_action( 'admin_init', array( &$this, 'register_settings' ) ); if ( ! get_option( 'asteroid_options' ) ) $this->initialize_settings(); } /* Add page(s) to the admin menu */ public function ast_add_pages() { $admin_menu = add_theme_page( __('Asteroid Options', 'asteroid'), __('Asteroid Options', 'asteroid'), 'edit_theme_options', 'asteroid-options', array( &$this, 'display_page' ) ); add_action( 'admin_print_scripts-' . $admin_menu, array( &$this, 'scripts' ) ); add_action( 'admin_print_styles-' . $admin_menu, array( &$this, 'styles' ) ); } /* Create settings field */ public function create_setting( $args = array() ) { $defaults = array( 'id' => 'default_field', 'title' => 'Default Field', 'desc' => 'This is a default description.', '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' ), 'asteroid-options', $section, $field_args ); } /*------------------------------------- HTML to display the options page --------------------------------------*/ public function display_page() { echo '

' . __( 'Asteroid Options', 'asteroid' ) . '

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

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

'; echo '
'; settings_fields( 'asteroid_options' ); echo '
    '; foreach ( $this->sections as $section_slug => $section ) echo '
  • ' . $section . '
  • '; echo '
'; do_settings_sections( $_GET['page'] ); echo '
'; echo ' '; echo '
'; } /*------------------------------------- HTML Output --------------------------------------*/ public function display_setting( $args = array() ) { extract( $args ); $options = get_option( 'asteroid_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 'textarea-css': echo ''; if ( $desc != '' ) echo '
' . $desc . ''; break; case 'password': echo ''; if ( $desc != '' ) echo '
' . $desc . ''; break; case 'text': default: echo ''; if ( $desc != '' ) echo '
' . $desc . ''; break; case 'text-int': default: echo ''; if ( $desc != '' ) echo ' ' . $desc . ''; break; case 'upload': default: echo ' '; if ( $desc != '' ) echo '
' . $desc . ''; break; case 'color': default: echo ''; if ( $desc != '' ) echo ' ' . $desc . ''; break; } } /*------------------------------------- Define settings and their defaults --------------------------------------*/ public function get_option() { /* General Settings ===========================================*/ $this->settings['ast_menu_search'] = array( 'section' => 'general', 'title' => __( 'Search Box on Menu', 'asteroid' ), 'desc' => __( 'Display a Search box on the Main Menu.', 'asteroid' ), 'type' => 'checkbox', 'std' => 1 // Set to 1 to be checked by default, 0 to be unchecked by default. ); $this->settings['ast_post_display_type'] = array( 'section' => 'general', 'title' => __( 'Display on Blog View', 'asteroid' ), 'desc' => __( 'Show excerpts or full posts on non-singular pages.', 'asteroid' ), 'type' => 'radio', 'std' => '1', 'choices' => array( '1' => __( 'Excerpt', 'asteroid' ), '2' => __( 'Full Post', 'asteroid' ) ) ); $this->settings['ast_head_codes'] = array( 'title' => __( 'Custom <Head> Codes', 'asteroid' ), 'desc' => __( 'Insert <Head> codes here.    e.g. Google Analytics, Metas, Fonts, Scripts and what not.', 'asteroid' ), 'std' => '', 'type' => 'textarea', 'section' => 'general' ); $this->settings['ast_hook_footer_links'] = array( 'title' => __( 'Footer Links', 'asteroid' ), 'desc' => __( 'Insert your footer links here.    Accepts html codes.', 'asteroid' ), 'std' => '', 'type' => 'textarea', 'section' => 'general' ); /* Appearance ===========================================*/ $this->settings['ast_header_logo'] = array( 'section' => 'appearance', 'title' => __( 'Header Logo', 'asteroid' ), 'desc' => __( 'The URL of your logo. This replaces the Title & Tagline.', 'asteroid' ), 'type' => 'upload', 'std' => '' ); $this->settings['ast_favicon'] = array( 'section' => 'appearance', 'title' => __( 'Favicon', 'asteroid' ), 'desc' => __( 'The URL of your favicon. It should be 16x16 pixels.', 'asteroid' ), 'type' => 'upload', 'std' => '' ); $this->settings['ast_header_height'] = array( 'title' => __( 'Height of Header', 'asteroid' ), 'desc' => 'px. ' . __( 'Set the height of the Header.', 'asteroid' ), 'std' => '120', 'type' => 'text-int', 'section' => 'appearance' ); $this->settings['ast_content_width'] = array( 'title' => __( 'Width of Content', 'asteroid' ), 'desc' => 'px. ' . __( 'Set the width of the Content or Post Area.', 'asteroid' ), 'std' => '640', 'type' => 'text-int', 'section' => 'appearance' ); $this->settings['ast_sidebar_width'] = array( 'title' => __( 'Width of Sidebar', 'asteroid' ), 'desc' => 'px. ' . __( 'Set the width of the Sidebar.', 'asteroid' ), 'std' => '320', 'type' => 'text-int', 'section' => 'appearance' ); $this->settings['ast_header_bgcolor'] = array( 'title' => __( 'Color of Header', 'asteroid' ), 'desc' => __( 'Choose a background color for the #header container.', 'asteroid' ), 'std' => 'FFFFFF', 'type' => 'color', 'section' => 'appearance' ); $this->settings['ast_content_bgcolor'] = array( 'title' => __( 'Color of Content', 'asteroid' ), 'desc' => __( 'Choose a background color for the #content container.', 'asteroid' ), 'std' => 'FFFFFF', 'type' => 'color', 'section' => 'appearance' ); $this->settings['ast_sidebar_bgcolor'] = array( 'title' => __( 'Color of Sidebar', 'asteroid' ), 'desc' => __( 'Choose a background color for the #sidebar container.', 'asteroid' ), 'std' => 'FFFFFF', 'type' => 'color', 'section' => 'appearance' ); /* Posts & Pages ===========================================*/ $this->settings['ast_excerpt_thumbnails'] = array( 'section' => 'post-page', 'title' => __( 'Excerpt Thumbnails', 'asteroid' ), 'desc' => __( 'Show Thumbnails on excerpts. Featured image will be used.', 'asteroid' ), 'type' => 'checkbox', 'std' => 1 ); $this->settings['ast_blog_date'] = array( 'section' => 'post-page', 'title' => __( 'Blog View Publish Date', 'asteroid' ), 'desc' => __( 'Show Publish Date on Blog, Archives, and Searches.', 'asteroid' ), 'type' => 'checkbox', 'std' => 1 ); $this->settings['ast_blog_author'] = array( 'section' => 'post-page', 'title' => __( 'Blog View Author', 'asteroid' ), 'desc' => __( 'Show Post Author on Blog, Archives, and Searches.', 'asteroid' ), 'type' => 'checkbox', 'std' => 0 ); $this->settings['ast_blog_comment_links'] = array( 'section' => 'post-page', 'title' => __( 'Blog View Comments', 'asteroid' ), 'desc' => __( 'Show comment count and comment link below excerpts.', 'asteroid' ), 'type' => 'checkbox', 'std' => 0 ); $this->settings['ast_single_date'] = array( 'section' => 'post-page', 'title' => __( 'Single View Publish Date', 'asteroid' ), 'desc' => __( 'Display the publish date on Posts and Pages.', 'asteroid' ), 'type' => 'select', 'std' => 1, 'choices' => array( 0 => __('Hidden', 'asteroid'), 1 => __('On Posts', 'asteroid'), 2 => __('On Pages', 'asteroid'), 3 => __('Both Posts & Pages', 'asteroid') ) ); $this->settings['ast_single_author'] = array( 'section' => 'post-page', 'title' => __( 'Single View Author', 'asteroid' ), 'desc' => __( 'Display the author on Posts and Pages.', 'asteroid' ), 'type' => 'select', 'std' => 1, 'choices' => array( 0 => __('Hidden', 'asteroid'), 1 => __('On Posts', 'asteroid'), 2 => __('On Pages', 'asteroid'), 3 => __('Both Posts & Pages', 'asteroid') ) ); $this->settings['ast_date_modified'] = array( 'section' => 'post-page', 'title' => __( 'Show Date Modified', 'asteroid' ), 'desc' => __( 'Display date when the Post or Page was modified.', 'asteroid' ), 'type' => 'select', 'std' => 1, 'choices' => array( 0 => __('Hidden', 'asteroid'), 1 => __('On Posts', 'asteroid'), 2 => __('On Pages', 'asteroid'), 3 => __('Both Posts & Pages', 'asteroid') ) ); $this->settings['ast_post_comments'] = array( 'section' => 'post-page', 'title' => __( 'Post Comments', 'asteroid' ), 'desc' => __( 'Show the comments and comment form on Posts.', 'asteroid' ), 'type' => 'checkbox', 'std' => 1 ); $this->settings['ast_page_comments'] = array( 'section' => 'post-page', 'title' => __( 'Page Comments', 'asteroid' ), 'desc' => __( 'Show the comments and comment form on Pages.', 'asteroid' ), 'type' => 'checkbox', 'std' => 1 ); $this->settings['ast_post_author_info_box'] = array( 'section' => 'post-page', 'title' => __( 'Show Author Info Box', 'asteroid' ), 'desc' => __( 'Show "About the Author" box below each post.', 'asteroid' ), 'type' => 'checkbox', 'std' => 0 ); /* Custom Widgets ===========================================*/ $this->settings['ast_widget_body'] = array( 'section' => 'widget-areas', 'title' => __( 'Body', 'asteroid' ), 'desc' => __( 'Allow widgets on the Body', 'asteroid' ), 'type' => 'checkbox', 'std' => 0 ); $this->settings['ast_widget_header'] = array( 'section' => 'widget-areas', 'title' => __( 'Header', 'asteroid' ), 'desc' => __( 'Allow widgets on the Header', 'asteroid' ), 'type' => 'checkbox', 'std' => 0 ); $this->settings['ast_widget_below_menu'] = array( 'section' => 'widget-areas', 'title' => __( 'Below Menu', 'asteroid' ), 'desc' => __( 'Allow widgets below the main menu.', 'asteroid' ), 'type' => 'checkbox', 'std' => 0 ); $this->settings['ast_widget_before_content'] = array( 'section' => 'widget-areas', 'title' => __( 'Before Content', 'asteroid' ), 'desc' => __( 'Allow widgets on top of the content.', 'asteroid' ), 'type' => 'checkbox', 'std' => 0 ); $this->settings['ast_widget_below_excerpts'] = array( 'section' => 'widget-areas', 'title' => __( 'Below Excerpts', 'asteroid' ), 'desc' => __( 'Allow widgets below the excerpts.', 'asteroid' ), 'type' => 'checkbox', 'std' => 0 ); $this->settings['ast_widget_before_post'] = array( 'section' => 'widget-areas', 'title' => __( 'Before Post', 'asteroid' ), 'desc' => __( 'Allow widgets to show after the post-title.', 'asteroid' ), 'type' => 'checkbox', 'std' => 0 ); $this->settings['ast_widget_before_post_content'] = array( 'section' => 'widget-areas', 'title' => __( 'Before Post - Content', 'asteroid' ), 'desc' => __( 'Allow widgets to show before the post-content.', 'asteroid' ), 'type' => 'checkbox', 'std' => 0 ); $this->settings['ast_widget_after_post_content'] = array( 'section' => 'widget-areas', 'title' => __( 'After Post - Content', 'asteroid' ), 'desc' => __( 'Allow widgets to show after the post-content.', 'asteroid' ), 'type' => 'checkbox', 'std' => 0 ); $this->settings['ast_widget_after_post'] = array( 'section' => 'widget-areas', 'title' => __( 'After Post', 'asteroid' ), 'desc' => __( 'Allow widgets to show at the post-footer.', 'asteroid' ), 'type' => 'checkbox', 'std' => 0 ); /* Custom CSS ===========================================*/ $this->settings['ast_custom_css'] = array( 'title' => __( 'Custom CSS Codes', 'asteroid' ), 'desc' => __( 'Enter custom CSS here to apply to the theme. This should override any other stylings.', 'asteroid' ), 'std' => '', 'type' => 'textarea-css', 'section' => 'custom-css', 'class' => 'textarea-css' ); /* Miscellaneous ===========================================*/ $this->settings['ast_post_editor_style'] = array( 'section' => 'misc', 'title' => __( 'Disable Post Editor Style', 'asteroid' ), 'desc' => __( 'Disable theme styles on the visual editor. Disables resizing of editor width.', 'asteroid' ), 'type' => 'checkbox', 'std' => 0 ); $this->settings['ast_remove_wp_version'] = array( 'section' => 'misc', 'title' => __( 'Remove WordPress Version', 'asteroid' ), 'desc' => __( 'Prevent WP Version from being displayed in the <Head>', 'asteroid' ), 'type' => 'checkbox', 'std' => 0 ); $this->settings['ast_remove_theme_link'] = array( 'section' => 'misc', 'title' => __( 'Remove Theme URL', 'asteroid' ), 'desc' => __( 'Remove the Asteroid Theme URL on the footer.', 'asteroid' ), 'type' => 'checkbox', 'std' => 0 ); $this->settings['ast_bbpress_forum_full_width'] = array( 'section' => 'misc', 'title' => __( 'bbPress Forum Width', 'asteroid' ), 'desc' => __( 'Make bbPress forum full-width with no sidebar.', 'asteroid' ), 'type' => 'checkbox', 'std' => 0 ); $this->settings['ast_bbpress_topic_full_width'] = array( 'section' => 'misc', 'title' => __( 'bbPress Topic Width', 'asteroid' ), 'desc' => __( 'Make bbPress topics full-width with no sidebar.', 'asteroid' ), 'type' => 'checkbox', 'std' => 0 ); /* Reset ===========================================*/ $this->settings['ast_reset_theme'] = array( 'section' => 'reset', 'title' => __( 'Reset theme', 'asteroid' ), 'desc' => __( 'Check and click "Save" to reset theme options. This deletes customizations!', 'asteroid' ), 'type' => 'checkbox', 'std' => 0, 'class' => 'warning' // Custom class for CSS ); } /*------------------------------------- Description for pages --------------------------------------*/ public function display_section() { // No Description } public function display_about_section() { // No Description } /*------------------------------------- Initialize Settings to Defaults --------------------------------------*/ public function initialize_settings() { $default_settings = array(); foreach ( $this->settings as $id => $setting ) { if ( $setting['type'] != 'heading' ) $default_settings[$id] = $setting['std']; } update_option( 'asteroid_options', $default_settings ); } /*------------------------------------- Register Settings --------------------------------------*/ public function register_settings() { register_setting( 'asteroid_options', 'asteroid_options', array ( &$this, 'validate_settings' ) ); foreach ( $this->sections as $slug => $title ) { if ( $slug == 'about' ) add_settings_section( $slug, $title, array( &$this, 'display_about_section' ), 'asteroid-options' ); else add_settings_section( $slug, $title, array( &$this, 'display_section' ), 'asteroid-options' ); } $this->get_option(); foreach ( $this->settings as $id => $setting ) { $setting['id'] = $id; $this->create_setting( $setting ); } } /*------------------------------------- jQuery Tabs --------------------------------------*/ public function scripts() { wp_print_scripts( 'jquery-ui-tabs' ); wp_enqueue_script('my-upload'); wp_enqueue_script('media-upload'); wp_enqueue_script('thickbox'); wp_register_script('my-upload', get_template_directory_uri() . '/js/uploader.js', array('jquery','media-upload','thickbox')); } /*------------------------------------- Styling for the theme options page --------------------------------------*/ public function styles() { wp_register_style( 'mytheme-admin', get_template_directory_uri() . '/includes/theme-options.css' ); wp_enqueue_style( 'mytheme-admin' ); wp_enqueue_style('thickbox'); } /*------------------------------------- Validate Settings --------------------------------------*/ public function validate_settings( $input ) { if ( ! isset( $input['ast_reset_theme'] ) ) { $options = get_option( 'asteroid_options' ); foreach ( $this->checkboxes as $id ) { if ( isset( $options[$id] ) && ! isset( $input[$id] ) ) unset( $options[$id] ); } return $input; } return false; } } $asteroid_options = new Asteroid_Theme_Options(); function asteroid_option( $option ) { $options = get_option( 'asteroid_options' ); if ( isset( $options[$option] ) ) return $options[$option]; else return false; }