Ticket #21404: 21404.3.diff
File 21404.3.diff, 7.1 KB (added by , 13 years ago) |
---|
-
wp-content/themes/twentytwelve/inc/theme-options.php
37 37 if ( 'twentytwelve' != get_stylesheet() ) 38 38 $this->option_key = get_stylesheet() . '_theme_options'; 39 39 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' ) ); 43 42 } 44 43 45 44 /** … … 57 56 */ 58 57 public function options_init() { 59 58 // Load our options for use in any method. 60 $this->options = $this->get_theme_options();59 $this->options = twentytwelve_get_theme_options(); 61 60 62 61 // Register our option group. 63 62 register_setting( … … 104 103 } 105 104 106 105 /** 107 * Returns the default options.108 *109 * @access public110 *111 * @return array112 */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 public125 *126 * @return array127 */128 public function get_theme_options() {129 return get_option( $this->option_key, $this->get_default_theme_options() );130 }131 132 /**133 106 * Renders the enable fonts checkbox setting field. 134 107 * 135 108 * @access public … … 183 156 * @return array The validated data. 184 157 */ 185 158 public function validate( $input ) { 186 $output = $defaults = $this->get_default_theme_options();159 $output = $defaults = (array) twentytwelve_default_theme_options(); 187 160 188 161 // The enable fonts checkbox should boolean true or false 189 162 if ( ! isset( $input['enable_fonts'] ) ) … … 192 165 193 166 return apply_filters( 'twentytwelve_options_validate', $output, $input, $defaults ); 194 167 } 195 196 /**197 * Implement Twenty Twelve theme options into Theme Customizer.198 *199 * @since Twenty Twelve 1.0200 * @access public201 * @param WP_Customize_Manager $wp_customize Theme Customizer object.202 *203 * @return void204 */205 public function customize_register( $wp_customize ) {206 // Enable Web Fonts207 $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 }227 168 } 228 No newline at end of file -
wp-content/themes/twentytwelve/functions.php
43 43 * @since Twenty Twelve 1.0 44 44 */ 45 45 function twentytwelve_setup() { 46 global $twentytwelve_options;47 46 48 47 /** 49 48 * Make Twenty Twelve available for translation. … … 52 51 * to change 'twentytwelve' to the name of your theme in all the template files. 53 52 */ 54 53 load_theme_textdomain( 'twentytwelve', get_template_directory() . '/languages' ); 55 54 56 55 // 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 60 61 // You can define support for an editor stylesheet here; Twenty Twelve doesn't have a default one. 61 62 // Then, create a CSS file called editor-style.css and place it in your theme directory. 62 63 add_editor_style(); … … 92 93 * @since Twenty Twelve 1.0 93 94 */ 94 95 function twentytwelve_scripts_styles() { 95 global $twentytwelve_options;96 96 97 97 /** 98 98 * Add JavaScript to pages with the comment form to support … … 111 111 * Load special font CSS file. 112 112 * Depends on Theme Options setting. 113 113 */ 114 $options = $twentytwelve_options->get_theme_options();114 $options = twentytwelve_get_theme_options(); 115 115 if ( $options['enable_fonts'] ) 116 116 wp_enqueue_style( 'twentytwelve-fonts', 'http://fonts.googleapis.com/css?family=Open+Sans:400italic,700italic,400,700' ); 117 117 … … 161 161 add_filter( 'wp_title', 'twentytwelve_wp_title', 10, 2 ); 162 162 163 163 /** 164 * Add Customizer page to the admin menu. 165 * 166 * @since Twenty Twelve 1.0 167 * 168 * @return void 169 */ 170 function 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 } 180 add_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 */ 190 function 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 } 209 add_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 */ 218 function 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 */ 229 function 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 /** 164 238 * Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link. 165 239 * 166 240 * @since Twenty Twelve 1.0