WordPress.org

Make WordPress Core


Ignore:
Timestamp:
04/28/2011 08:52:37 AM (9 years ago)
Author:
nacin
Message:

Twenty Eleven:

  • Use add_option(), rather than get_option() with defaults, to prevent notoption queries.
  • Add twentyeleven_theme_options_validate filter, that way one doesn't need to add a filter to sanitize_option_\$option to allow more options in.
  • Some inline doc modifications and additions.

see #17198.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-content/themes/twentyeleven/inc/theme-options/theme-options.php

    r17733 r17734  
    3838 * formatted, and safe.
    3939 *
     40 * We also use this function to add our theme option if it doesn't already exist.
     41 *
    4042 * @since Twenty Eleven 1.0
    4143 */
    4244function twentyeleven_theme_options_init() {
    43     register_setting( 'twentyeleven_options', 'twentyeleven_theme_options', 'twentyeleven_theme_options_validate' );
     45
     46    // If we have no options in the database, let's add them now.
     47    if ( false === twentyeleven_get_theme_options() )
     48        add_option( 'twentyeleven_theme_options', twentyeleven_get_default_theme_options() );
     49
     50    register_setting(
     51        'twentyeleven_options',       // Options group, see settings_fields() call in theme_options_render_page()
     52        'twentyeleven_theme_options', // Database option, see twentyeleven_get_theme_options()
     53        'twentyeleven_theme_options_validate' // The sanitization callback, see twentyeleven_theme_options_validate()
     54    );
    4455}
    4556add_action( 'admin_init', 'twentyeleven_theme_options_init' );
     
    120131    $default_theme_options = array(
    121132        'color_scheme' => 'light',
    122         'link_color' => '#1b8be0',
     133        'link_color'   => '#1b8be0',
    123134        'theme_layout' => 'content-sidebar',
    124135    );
     
    133144 */
    134145function twentyeleven_get_theme_options() {
    135     $defaults = twentyeleven_get_default_theme_options();
    136     $options = get_option( 'twentyeleven_theme_options', $defaults );
    137 
    138     return $options;
     146    return get_option( 'twentyeleven_theme_options' );
    139147}
    140148
     
    229237 * @todo set up Reset Options action
    230238 *
    231  * @since Twenty Ten 1.0
     239 * @since Twenty Eleven 1.0
    232240 */
    233241function twentyeleven_theme_options_validate( $input ) {
    234     $output = twentyeleven_get_default_theme_options();
     242    $output = $defaults = twentyeleven_get_default_theme_options();
    235243
    236244    // Color scheme must be in our array of color scheme options
     
    246254        $output['theme_layout'] = $input['theme_layout'];
    247255
    248     return $output;
    249 }
    250 
    251 /**
    252  * Register our color schemes and add them to the queue
     256    return apply_filters( 'twentyeleven_theme_options_validate', $output, $input, $defaults );
     257}
     258
     259/**
     260 * Enqueue the styles for the current color scheme.
     261 *
     262 * @since Twenty Eleven 1.0
    253263 */
    254264function twentyeleven_color_styles() {
     
    292302
    293303/**
    294  *  Adds Twenty Ten layout classes to the array of body classes
     304 * Adds Twenty Eleven layout classes to the array of body classes.
    295305 *
    296306 * @since Twenty Eleven 1.0
Note: See TracChangeset for help on using the changeset viewer.