settings_page = add_theme_page( esc_html( __( 'Canyon Options', 'canyon' ) ), /** Settings page name. */ esc_html( __( 'Canyon Options', 'canyon' ) ), /** Menu item name. */ $this->settings_page_capability(), /** Required capability */ 'canyon-options', /** Screen name */ array( &$this, 'settings_page' ) /** Callback function */ ); /* Check if the settings page is being shown before running any functions for it. */ if ( !empty( $canyon->settings_page ) ) { /** Add contextual help to the theme settings page. */ add_action( 'load-'. $canyon->settings_page, array( &$this, 'settings_page_contextual_help' ) ); /* Load the JavaScript and stylesheets needed for the theme settings screen. */ add_action( 'admin_enqueue_scripts', array( &$this, 'settings_page_enqueue_scripts' ) ); /** Configure settings Sections and Fileds. */ $this->settings_sections(); /** Configure default settings. */ $this->settings_default(); } } /** Returns the required capability for viewing and saving theme settings. */ function settings_page_capability() { return 'edit_theme_options'; } /** Displays the theme settings page. */ function settings_page() { require( trailingslashit( CANYON_ADMIN_DIR ) . 'page.php' ); } /** Text for the contextual help for the theme settings page in the admin. */ function settings_page_contextual_help() { /** Set the $help variable to an empty string. */ $help = ''; /** Get the parent theme data. */ $theme = canyon_get_theme_data(); /** If the theme has provided a documentation or support URI, add them to the help text. */ if ( !empty( $theme['AuthorURI'] ) || !empty( $theme['URI'] ) ) { /** Open an unordered list for the help text. */ $help = ''; } /** Additional Help */ $sidebar = '

' . __( 'For more information:', 'canyon' ) . '

'; $sidebar .= '

' . __( 'Documentation on Theme Options', 'canyon' ) . '

'; $sidebar .= '

' . __( 'Support Forums', 'canyon' ) . '

'; $screen = get_current_screen(); if ( method_exists( $screen, 'add_help_tab' ) ) { /** WordPress 3.3 */ $screen->add_help_tab( array( 'title' => __( 'Overview', 'canyon' ), 'id' => 'theme-settings-help', 'content' => $help, ) ); $screen->set_help_sidebar( $sidebar ); } else { /** WordPress 3.2 */ add_contextual_help( $screen, $help . $sidebar ); } } /** Loads admin JavaScript and Stylesheet files for displaying the theme settings page in the WordPress admin. */ function settings_page_enqueue_scripts() { /** Load Admin Stylesheet */ wp_enqueue_style( 'canyon-admin-css-style' ); wp_enqueue_style( 'canyon-admin-css-ui-smoothness' ); /** Load Admin Scripts */ wp_enqueue_script( 'canyon-admin-js-canyon' ); wp_enqueue_script( 'canyon-admin-js-jquery-cookie' ); } /** Configure settings Sections and Fileds */ function settings_sections() { /** Blog Section */ add_settings_section( 'canyon_section_blog', 'Blog Options', array( &$this, 'canyon_section_blog_fn' ), 'canyon_section_blog_page' ); add_settings_field( 'canyon_field_post_style', __( 'Post Style', 'canyon' ), array( &$this, 'canyon_field_post_style_fn' ), 'canyon_section_blog_page', 'canyon_section_blog' ); add_settings_field( 'canyon_field_post_nav_style', __( 'Post Navigation Style', 'canyon' ), array( &$this, 'canyon_field_post_nav_style_fn' ), 'canyon_section_blog_page', 'canyon_section_blog' ); /** General Section */ add_settings_section( 'canyon_section_general', 'General Options', array( &$this, 'canyon_section_general_fn' ), 'canyon_section_general_page' ); add_settings_field( 'canyon_field_analytic', __( 'Use Analytic', 'canyon' ), array( &$this, 'canyon_field_analytic_fn' ), 'canyon_section_general_page', 'canyon_section_general' ); add_settings_field( 'canyon_field_analytic_code', __( 'Enter Analytic Code', 'canyon' ), array( &$this, 'canyon_field_analytic_code_fn' ), 'canyon_section_general_page', 'canyon_section_general' ); add_settings_field( 'canyon_field_copyright', __( 'Enter Copyright Text', 'canyon' ), array( &$this, 'canyon_field_copyright_fn' ), 'canyon_section_general_page', 'canyon_section_general' ); add_settings_field('canyon_field_reset', __( 'Reset Theme Options', 'canyon' ), array( &$this, 'canyon_field_reset_fn' ), 'canyon_section_general_page', 'canyon_section_general' ); } /** Configure default settings. */ function settings_default() { global $canyon; $canyon_reset = false; $canyon_options = canyon_get_settings(); /** Canyon Reset Logic */ if ( !is_array( $canyon_options ) ) { $canyon_reset = true; } elseif ( $canyon_options['canyon_reset'] == 1 ) { $canyon_reset = true; } /** Let Reset Canyon */ if( $canyon_reset == true ) { $default = array( 'canyon_post_style' => 'content', 'canyon_post_nav_style' => 'numeric', 'canyon_analytic' => 0, 'canyon_analytic_code' => 'Analytic Code', 'canyon_copyright' => '© Copyright '. date( 'Y' ) .' - '. get_bloginfo( 'name' ) .'', 'canyon_reset' => 0, ); update_option( 'canyon_options' , $default ); } } /** Canyon Pre-defined Range */ /* Boolean Yes | No */ function canyon_pd_boolean() { return array( 1 => __( 'yes', 'canyon' ), 0 => __( 'no', 'canyon' ) ); } /* Post Style Range */ function canyon_pd_post_style() { return array( 'content' => __( 'Content', 'canyon' ), 'excerpt' => __( 'Excerpt (Magazine Style)', 'canyon' ) ); } /* Post Navigation Style Range */ function canyon_pd_post_nav_style() { return array( 'numeric' => __( 'Numeric', 'canyon' ), 'older-newer' => __( 'Older / Newer', 'canyon' ) ); } /** Canyon Options Validation */ function canyon_options_validate( $input ) { /* Validation: canyon_post_style */ $canyon_pd_post_style = $this->canyon_pd_post_style(); if ( ! array_key_exists( $input['canyon_post_style'], $canyon_pd_post_style ) ) { $input['canyon_post_style'] = 'excerpt'; } /* Validation: canyon_post_nav_style */ $canyon_pd_post_nav_style = $this->canyon_pd_post_nav_style(); if ( ! array_key_exists( $input['canyon_post_nav_style'], $canyon_pd_post_nav_style ) ) { $input['canyon_post_nav_style'] = 'numeric'; } /* Validation: canyon_analytic */ $canyon_pd_boolean = $this->canyon_pd_boolean(); if ( ! array_key_exists( $input['canyon_analytic'], $canyon_pd_boolean ) ) { $input['canyon_analytic'] = 0; } /* Validation: canyon_analytic_code */ if( !empty( $input['canyon_analytic_code'] ) ) { $input['canyon_analytic_code'] = htmlspecialchars ( $input['canyon_analytic_code'] ); } /* Validation: canyon_copyright */ if( !empty( $input['canyon_copyright'] ) ) { $input['canyon_copyright'] = esc_html ( $input['canyon_copyright'] ); } /* Validation: canyon_reset */ $canyon_pd_boolean = $this->canyon_pd_boolean(); //if ( ! array_key_exists( canyon_undefined_index_fix ( $input['canyon_reset'] ), $canyon_pd_boolean ) ) { if ( ! array_key_exists( $input['canyon_reset'], $canyon_pd_boolean ) ) { $input['canyon_reset'] = 0; } add_settings_error( 'canyon_options', 'canyon_options', __( 'Settings Saved.', 'canyon' ), 'updated' ); return $input; } /** Blog Section Callback */ function canyon_section_blog_fn() { _e( 'Canyon Blog Options', 'canyon' ); } /* Post Style Callback */ function canyon_field_post_style_fn() { $canyon_options = get_option('canyon_options'); $items = $this->canyon_pd_post_style(); foreach( $items as $key => $val ) { ?>
canyon_pd_post_nav_style(); foreach( $items as $key => $val ) { ?>
canyon_pd_boolean(); echo ''; echo '
'. __( 'Enter the Analytic code.', 'canyon' ) .'
'; } /* Copyright Text Callback */ function canyon_field_copyright_fn() { $canyon_options = get_option('canyon_options'); echo ''; echo '
'. __( 'Enter Copyright Text.', 'canyon' ) .'
'; echo '
Example: &copy; Copyright '.date('Y').' - <a href="'. home_url( '/' ) .'">'. get_bloginfo('name') .'</a>
'; } /* Theme Reset Callback */ function canyon_field_reset_fn() { $canyon_options = get_option('canyon_options'); $items = $this->canyon_pd_boolean(); echo ''; } } /** Initiate Admin */ new CanyonAdmin(); ?>