Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (7 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

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

    r36797 r42343  
    6060    );
    6161
    62     add_settings_field( 'link_color', __( 'Link Color',     'twentyeleven' ), 'twentyeleven_settings_field_link_color', 'theme_options', 'general' );
    63     add_settings_field( 'layout',     __( 'Default Layout', 'twentyeleven' ), 'twentyeleven_settings_field_layout',    'theme_options', 'general' );
     62    add_settings_field( 'link_color', __( 'Link Color', 'twentyeleven' ), 'twentyeleven_settings_field_link_color', 'theme_options', 'general' );
     63    add_settings_field( 'layout', __( 'Default Layout', 'twentyeleven' ), 'twentyeleven_settings_field_layout', 'theme_options', 'general' );
    6464}
    6565add_action( 'admin_init', 'twentyeleven_theme_options_init' );
     
    100100    );
    101101
    102     if ( ! $theme_page )
     102    if ( ! $theme_page ) {
    103103        return;
     104    }
    104105
    105106    add_action( "load-$theme_page", 'twentyeleven_theme_options_help' );
     
    125126    if ( method_exists( $screen, 'add_help_tab' ) ) {
    126127        // WordPress 3.3.0
    127         $screen->add_help_tab( array(
    128             'title' => __( 'Overview', 'twentyeleven' ),
    129             'id' => 'theme-options-help',
    130             'content' => $help,
     128        $screen->add_help_tab(
     129            array(
     130                'title'   => __( 'Overview', 'twentyeleven' ),
     131                'id'      => 'theme-options-help',
     132                'content' => $help,
    131133            )
    132134        );
     
    147149    $color_scheme_options = array(
    148150        'light' => array(
    149             'value' => 'light',
    150             'label' => __( 'Light', 'twentyeleven' ),
    151             'thumbnail' => get_template_directory_uri() . '/inc/images/light.png',
     151            'value'              => 'light',
     152            'label'              => __( 'Light', 'twentyeleven' ),
     153            'thumbnail'          => get_template_directory_uri() . '/inc/images/light.png',
    152154            'default_link_color' => '#1b8be0',
    153155        ),
    154         'dark' => array(
    155             'value' => 'dark',
    156             'label' => __( 'Dark', 'twentyeleven' ),
    157             'thumbnail' => get_template_directory_uri() . '/inc/images/dark.png',
     156        'dark'  => array(
     157            'value'              => 'dark',
     158            'label'              => __( 'Dark', 'twentyeleven' ),
     159            'thumbnail'          => get_template_directory_uri() . '/inc/images/dark.png',
    158160            'default_link_color' => '#e4741f',
    159161        ),
     
    178180    $layout_options = array(
    179181        'content-sidebar' => array(
    180             'value' => 'content-sidebar',
    181             'label' => __( 'Content on left', 'twentyeleven' ),
     182            'value'     => 'content-sidebar',
     183            'label'     => __( 'Content on left', 'twentyeleven' ),
    182184            'thumbnail' => get_template_directory_uri() . '/inc/images/content-sidebar.png',
    183185        ),
    184186        'sidebar-content' => array(
    185             'value' => 'sidebar-content',
    186             'label' => __( 'Content on right', 'twentyeleven' ),
     187            'value'     => 'sidebar-content',
     188            'label'     => __( 'Content on right', 'twentyeleven' ),
    187189            'thumbnail' => get_template_directory_uri() . '/inc/images/sidebar-content.png',
    188190        ),
    189         'content' => array(
    190             'value' => 'content',
    191             'label' => __( 'One-column, no sidebar', 'twentyeleven' ),
     191        'content'         => array(
     192            'value'     => 'content',
     193            'label'     => __( 'One-column, no sidebar', 'twentyeleven' ),
    192194            'thumbnail' => get_template_directory_uri() . '/inc/images/content.png',
    193195        ),
     
    218220    );
    219221
    220     if ( is_rtl() )
     222    if ( is_rtl() ) {
    221223        $default_theme_options['theme_layout'] = 'sidebar-content';
     224    }
    222225
    223226    /**
     
    239242 *                             Default null (or the active color scheme).
    240243 * @return string The default link color.
    241 */
     244 */
    242245function twentyeleven_get_default_link_color( $color_scheme = null ) {
    243246    if ( null === $color_scheme ) {
    244         $options = twentyeleven_get_theme_options();
     247        $options      = twentyeleven_get_theme_options();
    245248        $color_scheme = $options['color_scheme'];
    246249    }
    247250
    248251    $color_schemes = twentyeleven_color_schemes();
    249     if ( ! isset( $color_schemes[ $color_scheme ] ) )
     252    if ( ! isset( $color_schemes[ $color_scheme ] ) ) {
    250253        return false;
     254    }
    251255
    252256    return $color_schemes[ $color_scheme ]['default_link_color'];
     
    365369
    366370    // Color scheme must be in our array of color scheme options
    367     if ( isset( $input['color_scheme'] ) && array_key_exists( $input['color_scheme'], twentyeleven_color_schemes() ) )
     371    if ( isset( $input['color_scheme'] ) && array_key_exists( $input['color_scheme'], twentyeleven_color_schemes() ) ) {
    368372        $output['color_scheme'] = $input['color_scheme'];
     373    }
    369374
    370375    // Our defaults for the link color may have changed, based on the color scheme.
     
    372377
    373378    // Link color must be 3 or 6 hexadecimal characters
    374     if ( isset( $input['link_color'] ) && preg_match( '/^#?([a-f0-9]{3}){1,2}$/i', $input['link_color'] ) )
     379    if ( isset( $input['link_color'] ) && preg_match( '/^#?([a-f0-9]{3}){1,2}$/i', $input['link_color'] ) ) {
    375380        $output['link_color'] = '#' . strtolower( ltrim( $input['link_color'], '#' ) );
     381    }
    376382
    377383    // Theme layout must be in our array of theme layout options
    378     if ( isset( $input['theme_layout'] ) && array_key_exists( $input['theme_layout'], twentyeleven_layouts() ) )
     384    if ( isset( $input['theme_layout'] ) && array_key_exists( $input['theme_layout'], twentyeleven_layouts() ) ) {
    379385        $output['theme_layout'] = $input['theme_layout'];
     386    }
    380387
    381388    /**
     
    397404 */
    398405function twentyeleven_enqueue_color_scheme() {
    399     $options = twentyeleven_get_theme_options();
     406    $options      = twentyeleven_get_theme_options();
    400407    $color_scheme = $options['color_scheme'];
    401408
    402     if ( 'dark' == $color_scheme )
     409    if ( 'dark' == $color_scheme ) {
    403410        wp_enqueue_style( 'dark', get_template_directory_uri() . '/colors/dark.css', array(), null );
     411    }
    404412
    405413    /**
     
    422430 */
    423431function twentyeleven_print_link_color_style() {
    424     $options = twentyeleven_get_theme_options();
     432    $options    = twentyeleven_get_theme_options();
    425433    $link_color = $options['link_color'];
    426434
     
    428436
    429437    // Don't do anything if the current link color is the default.
    430     if ( $default_options['link_color'] == $link_color )
     438    if ( $default_options['link_color'] == $link_color ) {
    431439        return;
     440    }
    432441?>
    433442    <style>
     
    470479 */
    471480function twentyeleven_layout_classes( $existing_classes ) {
    472     $options = twentyeleven_get_theme_options();
     481    $options        = twentyeleven_get_theme_options();
    473482    $current_layout = $options['theme_layout'];
    474483
    475     if ( in_array( $current_layout, array( 'content-sidebar', 'sidebar-content' ) ) )
     484    if ( in_array( $current_layout, array( 'content-sidebar', 'sidebar-content' ) ) ) {
    476485        $classes = array( 'two-column' );
    477     else
     486    } else {
    478487        $classes = array( 'one-column' );
    479 
    480     if ( 'content-sidebar' == $current_layout )
     488    }
     489
     490    if ( 'content-sidebar' == $current_layout ) {
    481491        $classes[] = 'right-sidebar';
    482     elseif ( 'sidebar-content' == $current_layout )
     492    } elseif ( 'sidebar-content' == $current_layout ) {
    483493        $classes[] = 'left-sidebar';
    484     else
     494    } else {
    485495        $classes[] = $current_layout;
     496    }
    486497
    487498    /**
     
    507518 */
    508519function twentyeleven_customize_register( $wp_customize ) {
    509     $wp_customize->get_setting( 'blogname' )->transport = 'postMessage';
    510     $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage';
     520    $wp_customize->get_setting( 'blogname' )->transport         = 'postMessage';
     521    $wp_customize->get_setting( 'blogdescription' )->transport  = 'postMessage';
    511522    $wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage';
    512523
    513524    if ( isset( $wp_customize->selective_refresh ) ) {
    514         $wp_customize->selective_refresh->add_partial( 'blogname', array(
    515             'selector' => '#site-title a',
    516             'container_inclusive' => false,
    517             'render_callback' => 'twentyeleven_customize_partial_blogname',
    518         ) );
    519         $wp_customize->selective_refresh->add_partial( 'blogdescription', array(
    520             'selector' => '#site-description',
    521             'container_inclusive' => false,
    522             'render_callback' => 'twentyeleven_customize_partial_blogdescription',
    523         ) );
     525        $wp_customize->selective_refresh->add_partial(
     526            'blogname', array(
     527                'selector'            => '#site-title a',
     528                'container_inclusive' => false,
     529                'render_callback'     => 'twentyeleven_customize_partial_blogname',
     530            )
     531        );
     532        $wp_customize->selective_refresh->add_partial(
     533            'blogdescription', array(
     534                'selector'            => '#site-description',
     535                'container_inclusive' => false,
     536                'render_callback'     => 'twentyeleven_customize_partial_blogdescription',
     537            )
     538        );
    524539    }
    525540
     
    527542    $defaults = twentyeleven_get_default_theme_options();
    528543
    529     $wp_customize->add_setting( 'twentyeleven_theme_options[color_scheme]', array(
    530         'default'    => $defaults['color_scheme'],
    531         'type'       => 'option',
    532         'capability' => 'edit_theme_options',
    533     ) );
     544    $wp_customize->add_setting(
     545        'twentyeleven_theme_options[color_scheme]', array(
     546            'default'    => $defaults['color_scheme'],
     547            'type'       => 'option',
     548            'capability' => 'edit_theme_options',
     549        )
     550    );
    534551
    535552    $schemes = twentyeleven_color_schemes();
     
    539556    }
    540557
    541     $wp_customize->add_control( 'twentyeleven_color_scheme', array(
    542         'label'    => __( 'Color Scheme', 'twentyeleven' ),
    543         'section'  => 'colors',
    544         'settings' => 'twentyeleven_theme_options[color_scheme]',
    545         'type'     => 'radio',
    546         'choices'  => $choices,
    547         'priority' => 5,
    548     ) );
     558    $wp_customize->add_control(
     559        'twentyeleven_color_scheme', array(
     560            'label'    => __( 'Color Scheme', 'twentyeleven' ),
     561            'section'  => 'colors',
     562            'settings' => 'twentyeleven_theme_options[color_scheme]',
     563            'type'     => 'radio',
     564            'choices'  => $choices,
     565            'priority' => 5,
     566        )
     567    );
    549568
    550569    // Link Color (added to Color Scheme section in Customizer)
    551     $wp_customize->add_setting( 'twentyeleven_theme_options[link_color]', array(
    552         'default'           => twentyeleven_get_default_link_color( $options['color_scheme'] ),
    553         'type'              => 'option',
    554         'sanitize_callback' => 'sanitize_hex_color',
    555         'capability'        => 'edit_theme_options',
    556     ) );
    557 
    558     $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'link_color', array(
    559         'label'    => __( 'Link Color', 'twentyeleven' ),
    560         'section'  => 'colors',
    561         'settings' => 'twentyeleven_theme_options[link_color]',
    562     ) ) );
     570    $wp_customize->add_setting(
     571        'twentyeleven_theme_options[link_color]', array(
     572            'default'           => twentyeleven_get_default_link_color( $options['color_scheme'] ),
     573            'type'              => 'option',
     574            'sanitize_callback' => 'sanitize_hex_color',
     575            'capability'        => 'edit_theme_options',
     576        )
     577    );
     578
     579    $wp_customize->add_control(
     580        new WP_Customize_Color_Control(
     581            $wp_customize, 'link_color', array(
     582                'label'    => __( 'Link Color', 'twentyeleven' ),
     583                'section'  => 'colors',
     584                'settings' => 'twentyeleven_theme_options[link_color]',
     585            )
     586        )
     587    );
    563588
    564589    // Default Layout
    565     $wp_customize->add_section( 'twentyeleven_layout', array(
    566         'title'    => __( 'Layout', 'twentyeleven' ),
    567         'priority' => 50,
    568     ) );
    569 
    570     $wp_customize->add_setting( 'twentyeleven_theme_options[theme_layout]', array(
    571         'type'              => 'option',
    572         'default'           => $defaults['theme_layout'],
    573         'sanitize_callback' => 'sanitize_key',
    574     ) );
     590    $wp_customize->add_section(
     591        'twentyeleven_layout', array(
     592            'title'    => __( 'Layout', 'twentyeleven' ),
     593            'priority' => 50,
     594        )
     595    );
     596
     597    $wp_customize->add_setting(
     598        'twentyeleven_theme_options[theme_layout]', array(
     599            'type'              => 'option',
     600            'default'           => $defaults['theme_layout'],
     601            'sanitize_callback' => 'sanitize_key',
     602        )
     603    );
    575604
    576605    $layouts = twentyeleven_layouts();
     
    580609    }
    581610
    582     $wp_customize->add_control( 'twentyeleven_theme_options[theme_layout]', array(
    583         'section'    => 'twentyeleven_layout',
    584         'type'       => 'radio',
    585         'choices'    => $choices,
    586     ) );
     611    $wp_customize->add_control(
     612        'twentyeleven_theme_options[theme_layout]', array(
     613            'section' => 'twentyeleven_layout',
     614            'type'    => 'radio',
     615            'choices' => $choices,
     616        )
     617    );
    587618}
    588619add_action( 'customize_register', 'twentyeleven_customize_register' );
Note: See TracChangeset for help on using the changeset viewer.