Make WordPress Core

Ticket #21404: 21404.3.diff

File 21404.3.diff, 7.1 KB (added by obenland, 13 years ago)

Keeps Theme Options page for versions prior to 3.4

  • wp-content/themes/twentytwelve/inc/theme-options.php

     
    3737                if ( 'twentytwelve' != get_stylesheet() )
    3838                        $this->option_key = get_stylesheet() . '_theme_options';
    3939
    40                 add_action( 'admin_init',         array( $this, 'options_init'       ) );
    41                 add_action( 'admin_menu',         array( $this, 'add_page'           ) );
    42                 add_action( 'customize_register', array( $this, 'customize_register' ) );
     40                add_action( 'admin_init', array( $this, 'options_init' ) );
     41                add_action( 'admin_menu', array( $this, 'add_page'     ) );
    4342        }
    4443
    4544        /**
     
    5756         */
    5857        public function options_init() {
    5958                // Load our options for use in any method.
    60                 $this->options = $this->get_theme_options();
     59                $this->options = twentytwelve_get_theme_options();
    6160
    6261                // Register our option group.
    6362                register_setting(
     
    104103        }
    105104
    106105        /**
    107          * Returns the default options.
    108          *
    109          * @access public
    110          *
    111          * @return array
    112          */
    113         public function get_default_theme_options() {
    114                 $default_theme_options = array(
    115                         'enable_fonts' => false,
    116                 );
    117 
    118                 return apply_filters( 'twentytwelve_default_theme_options', $default_theme_options );
    119         }
    120 
    121         /**
    122          * Returns the options array.
    123          *
    124          * @access public
    125          *
    126          * @return array
    127          */
    128         public function get_theme_options() {
    129                 return get_option( $this->option_key, $this->get_default_theme_options() );
    130         }
    131 
    132         /**
    133106         * Renders the enable fonts checkbox setting field.
    134107         *
    135108         * @access public
     
    183156         * @return array The validated data.
    184157         */
    185158        public function validate( $input ) {
    186                 $output = $defaults = $this->get_default_theme_options();
     159                $output = $defaults = (array) twentytwelve_default_theme_options();
    187160
    188161                // The enable fonts checkbox should boolean true or false
    189162                if ( ! isset( $input['enable_fonts'] ) )
     
    192165
    193166                return apply_filters( 'twentytwelve_options_validate', $output, $input, $defaults );
    194167        }
    195 
    196         /**
    197          * Implement Twenty Twelve theme options into Theme Customizer.
    198          *
    199          * @since Twenty Twelve 1.0
    200          * @access public
    201          * @param WP_Customize_Manager $wp_customize Theme Customizer object.
    202          *
    203          * @return void
    204          */
    205         public function customize_register( $wp_customize ) {
    206                 // Enable Web Fonts
    207                 $wp_customize->add_section( $this->option_key . '_enable_fonts', array(
    208                         'title'    => __( 'Fonts', 'twentytwelve' ),
    209                         'priority' => 35,
    210                 ) );
    211 
    212                 $defaults = $this->get_default_theme_options();
    213 
    214                 $wp_customize->add_setting( $this->option_key . '[enable_fonts]', array(
    215                         'default'    => $defaults['enable_fonts'],
    216                         'type'       => 'option',
    217                         'capability' => 'edit_theme_options',
    218                 ) );
    219 
    220                 $wp_customize->add_control( $this->option_key . '_enable_fonts', array(
    221                         'label'    => __( 'Enable Web Fonts', 'twentytwelve' ),
    222                         'section'  => $this->option_key . '_enable_fonts',
    223                         'settings' => $this->option_key . '[enable_fonts]',
    224                         'type'     => 'checkbox',
    225                 ) );
    226         }
    227168}
    228  No newline at end of file
  • wp-content/themes/twentytwelve/functions.php

     
    4343 * @since Twenty Twelve 1.0
    4444 */
    4545function twentytwelve_setup() {
    46         global $twentytwelve_options;
    4746
    4847        /**
    4948         * Make Twenty Twelve available for translation.
     
    5251         * to change 'twentytwelve' to the name of your theme in all the template files.
    5352         */
    5453        load_theme_textdomain( 'twentytwelve', get_template_directory() . '/languages' );
    55 
     54       
    5655        // Load up our theme options page and related code.
    57         require( get_template_directory() . '/inc/theme-options.php' );
    58         $twentytwelve_options = new Twenty_Twelve_Options();
    59 
     56        if ( version_compare( get_bloginfo( 'version' ), 3.4, '<' ) ) {
     57                require( get_template_directory() . '/inc/theme-options.php' );
     58                $twentytwelve_options = new Twenty_Twelve_Options();
     59        }
     60       
    6061        // You can define support for an editor stylesheet here; Twenty Twelve doesn't have a default one.
    6162        // Then, create a CSS file called editor-style.css and place it in your theme directory.
    6263        add_editor_style();
     
    9293 * @since Twenty Twelve 1.0
    9394 */
    9495function twentytwelve_scripts_styles() {
    95         global $twentytwelve_options;
    9696
    9797        /**
    9898         * Add JavaScript to pages with the comment form to support
     
    111111         * Load special font CSS file.
    112112         * Depends on Theme Options setting.
    113113         */
    114         $options = $twentytwelve_options->get_theme_options();
     114        $options = twentytwelve_get_theme_options();
    115115        if ( $options['enable_fonts'] )
    116116                wp_enqueue_style( 'twentytwelve-fonts', 'http://fonts.googleapis.com/css?family=Open+Sans:400italic,700italic,400,700' );
    117117
     
    161161add_filter( 'wp_title', 'twentytwelve_wp_title', 10, 2 );
    162162
    163163/**
     164 * Add Customizer page to the admin menu.
     165 *
     166 * @since Twenty Twelve 1.0
     167 *
     168 * @return void
     169 */
     170function twentytwelve_add_page() {
     171       
     172        if ( version_compare( get_bloginfo( 'version' ), 3.4, '>=' ) )
     173                add_theme_page(
     174                        __( 'Customize', 'twentytwelve' ), // Name of page
     175                        __( 'Customize', 'twentytwelve' ), // Label in menu
     176                        'edit_theme_options',              // Capability required
     177                        'customize.php'                    // Menu slug, used to uniquely identify the page
     178                );
     179}
     180add_action( 'admin_menu', 'twentytwelve_add_page' );
     181
     182/**
     183 * Implement Twenty Twelve theme options into Theme Customizer.
     184 *
     185 * @since Twenty Twelve 1.0
     186 * @param WP_Customize_Manager $wp_customize Theme Customizer object.
     187 *
     188 * @return void
     189 */
     190function twentytwelve_customize_register( $wp_customize ) {
     191        // Enable Web Fonts
     192        $wp_customize->add_section( 'twentytwelve_fonts', array(
     193                'title'    => __( 'Fonts', 'twentytwelve' ),
     194                'priority' => 35,
     195        ) );
     196
     197        $wp_customize->add_setting( get_stylesheet() . '_theme_options[enable_fonts]', array(
     198                'default'  => twentytwelve_default_theme_options()->enable_fonts,
     199                'type'     => 'option',
     200        ) );
     201
     202        $wp_customize->add_control( 'twentytwelve_enable_fonts', array(
     203                'label'    => __( 'Enable Open Sans Font', 'twentytwelve' ),
     204                'section'  => 'twentytwelve_fonts',
     205                'settings' => get_stylesheet() . '_theme_options[enable_fonts]',
     206                'type'     => 'checkbox',
     207        ) );
     208}
     209add_action( 'customize_register', 'twentytwelve_customize_register' );
     210
     211/**
     212 * Returns the options array.
     213 *
     214 * @since Twenty Twelve 1.0
     215 *
     216 * @return array
     217 */
     218function twentytwelve_get_theme_options() {
     219        return get_option( get_stylesheet() . '_theme_options', twentytwelve_default_theme_options() );
     220}
     221
     222/**
     223 * Returns the default options.
     224 *
     225 * @since Twenty Twelve 1.0
     226 *
     227 * @return object
     228 */
     229function twentytwelve_default_theme_options() {
     230        $default_theme_options = array(
     231                'enable_fonts' => true,
     232        );
     233
     234        return (object) apply_filters( 'twentytwelve_default_theme_options', $default_theme_options );
     235}
     236
     237/**
    164238 * Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link.
    165239 *
    166240 * @since Twenty Twelve 1.0