Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (9 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/twentyfifteen/inc/customizer.php

    r36797 r42343  
    2222
    2323    if ( isset( $wp_customize->selective_refresh ) ) {
    24         $wp_customize->selective_refresh->add_partial( 'blogname', array(
    25             'selector' => '.site-title a',
    26             'container_inclusive' => false,
    27             'render_callback' => 'twentyfifteen_customize_partial_blogname',
    28         ) );
    29         $wp_customize->selective_refresh->add_partial( 'blogdescription', array(
    30             'selector' => '.site-description',
    31             'container_inclusive' => false,
    32             'render_callback' => 'twentyfifteen_customize_partial_blogdescription',
    33         ) );
     24        $wp_customize->selective_refresh->add_partial(
     25            'blogname', array(
     26                'selector'            => '.site-title a',
     27                'container_inclusive' => false,
     28                'render_callback'     => 'twentyfifteen_customize_partial_blogname',
     29            )
     30        );
     31        $wp_customize->selective_refresh->add_partial(
     32            'blogdescription', array(
     33                'selector'            => '.site-description',
     34                'container_inclusive' => false,
     35                'render_callback'     => 'twentyfifteen_customize_partial_blogdescription',
     36            )
     37        );
    3438    }
    3539
    3640    // Add color scheme setting and control.
    37     $wp_customize->add_setting( 'color_scheme', array(
    38         'default'           => 'default',
    39         'sanitize_callback' => 'twentyfifteen_sanitize_color_scheme',
    40         'transport'         => 'postMessage',
    41     ) );
    42 
    43     $wp_customize->add_control( 'color_scheme', array(
    44         'label'    => __( 'Base Color Scheme', 'twentyfifteen' ),
    45         'section'  => 'colors',
    46         'type'     => 'select',
    47         'choices'  => twentyfifteen_get_color_scheme_choices(),
    48         'priority' => 1,
    49     ) );
     41    $wp_customize->add_setting(
     42        'color_scheme', array(
     43            'default'           => 'default',
     44            'sanitize_callback' => 'twentyfifteen_sanitize_color_scheme',
     45            'transport'         => 'postMessage',
     46        )
     47    );
     48
     49    $wp_customize->add_control(
     50        'color_scheme', array(
     51            'label'    => __( 'Base Color Scheme', 'twentyfifteen' ),
     52            'section'  => 'colors',
     53            'type'     => 'select',
     54            'choices'  => twentyfifteen_get_color_scheme_choices(),
     55            'priority' => 1,
     56        )
     57    );
    5058
    5159    // Add custom header and sidebar text color setting and control.
    52     $wp_customize->add_setting( 'sidebar_textcolor', array(
    53         'default'           => $color_scheme[4],
    54         'sanitize_callback' => 'sanitize_hex_color',
    55         'transport'         => 'postMessage',
    56     ) );
    57 
    58     $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'sidebar_textcolor', array(
    59         'label'       => __( 'Header and Sidebar Text Color', 'twentyfifteen' ),
    60         'description' => __( 'Applied to the header on small screens and the sidebar on wide screens.', 'twentyfifteen' ),
    61         'section'     => 'colors',
    62     ) ) );
     60    $wp_customize->add_setting(
     61        'sidebar_textcolor', array(
     62            'default'           => $color_scheme[4],
     63            'sanitize_callback' => 'sanitize_hex_color',
     64            'transport'         => 'postMessage',
     65        )
     66    );
     67
     68    $wp_customize->add_control(
     69        new WP_Customize_Color_Control(
     70            $wp_customize, 'sidebar_textcolor', array(
     71                'label'       => __( 'Header and Sidebar Text Color', 'twentyfifteen' ),
     72                'description' => __( 'Applied to the header on small screens and the sidebar on wide screens.', 'twentyfifteen' ),
     73                'section'     => 'colors',
     74            )
     75        )
     76    );
    6377
    6478    // Remove the core header textcolor control, as it shares the sidebar text color.
     
    6680
    6781    // Add custom header and sidebar background color setting and control.
    68     $wp_customize->add_setting( 'header_background_color', array(
    69         'default'           => $color_scheme[1],
    70         'sanitize_callback' => 'sanitize_hex_color',
    71         'transport'         => 'postMessage',
    72     ) );
    73 
    74     $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'header_background_color', array(
    75         'label'       => __( 'Header and Sidebar Background Color', 'twentyfifteen' ),
    76         'description' => __( 'Applied to the header on small screens and the sidebar on wide screens.', 'twentyfifteen' ),
    77         'section'     => 'colors',
    78     ) ) );
     82    $wp_customize->add_setting(
     83        'header_background_color', array(
     84            'default'           => $color_scheme[1],
     85            'sanitize_callback' => 'sanitize_hex_color',
     86            'transport'         => 'postMessage',
     87        )
     88    );
     89
     90    $wp_customize->add_control(
     91        new WP_Customize_Color_Control(
     92            $wp_customize, 'header_background_color', array(
     93                'label'       => __( 'Header and Sidebar Background Color', 'twentyfifteen' ),
     94                'description' => __( 'Applied to the header on small screens and the sidebar on wide screens.', 'twentyfifteen' ),
     95                'section'     => 'colors',
     96            )
     97        )
     98    );
    7999
    80100    // Add an additional description to the header image section.
     
    146166     * }
    147167     */
    148     return apply_filters( 'twentyfifteen_color_schemes', array(
    149         'default' => array(
    150             'label'  => __( 'Default', 'twentyfifteen' ),
    151             'colors' => array(
    152                 '#f1f1f1',
    153                 '#ffffff',
    154                 '#ffffff',
    155                 '#333333',
    156                 '#333333',
    157                 '#f7f7f7',
     168    return apply_filters(
     169        'twentyfifteen_color_schemes', array(
     170            'default' => array(
     171                'label'  => __( 'Default', 'twentyfifteen' ),
     172                'colors' => array(
     173                    '#f1f1f1',
     174                    '#ffffff',
     175                    '#ffffff',
     176                    '#333333',
     177                    '#333333',
     178                    '#f7f7f7',
     179                ),
    158180            ),
    159         ),
    160         'dark'    => array(
    161             'label'  => __( 'Dark', 'twentyfifteen' ),
    162             'colors' => array(
    163                 '#111111',
    164                 '#202020',
    165                 '#202020',
    166                 '#bebebe',
    167                 '#bebebe',
    168                 '#1b1b1b',
     181            'dark'    => array(
     182                'label'  => __( 'Dark', 'twentyfifteen' ),
     183                'colors' => array(
     184                    '#111111',
     185                    '#202020',
     186                    '#202020',
     187                    '#bebebe',
     188                    '#bebebe',
     189                    '#1b1b1b',
     190                ),
    169191            ),
    170         ),
    171         'yellow'  => array(
    172             'label'  => __( 'Yellow', 'twentyfifteen' ),
    173             'colors' => array(
    174                 '#f4ca16',
    175                 '#ffdf00',
    176                 '#ffffff',
    177                 '#111111',
    178                 '#111111',
    179                 '#f1f1f1',
     192            'yellow'  => array(
     193                'label'  => __( 'Yellow', 'twentyfifteen' ),
     194                'colors' => array(
     195                    '#f4ca16',
     196                    '#ffdf00',
     197                    '#ffffff',
     198                    '#111111',
     199                    '#111111',
     200                    '#f1f1f1',
     201                ),
    180202            ),
    181         ),
    182         'pink'    => array(
    183             'label'  => __( 'Pink', 'twentyfifteen' ),
    184             'colors' => array(
    185                 '#ffe5d1',
    186                 '#e53b51',
    187                 '#ffffff',
    188                 '#352712',
    189                 '#ffffff',
    190                 '#f1f1f1',
     203            'pink'    => array(
     204                'label'  => __( 'Pink', 'twentyfifteen' ),
     205                'colors' => array(
     206                    '#ffe5d1',
     207                    '#e53b51',
     208                    '#ffffff',
     209                    '#352712',
     210                    '#ffffff',
     211                    '#f1f1f1',
     212                ),
    191213            ),
    192         ),
    193         'purple'  => array(
    194             'label'  => __( 'Purple', 'twentyfifteen' ),
    195             'colors' => array(
    196                 '#674970',
    197                 '#2e2256',
    198                 '#ffffff',
    199                 '#2e2256',
    200                 '#ffffff',
    201                 '#f1f1f1',
     214            'purple'  => array(
     215                'label'  => __( 'Purple', 'twentyfifteen' ),
     216                'colors' => array(
     217                    '#674970',
     218                    '#2e2256',
     219                    '#ffffff',
     220                    '#2e2256',
     221                    '#ffffff',
     222                    '#f1f1f1',
     223                ),
    202224            ),
    203         ),
    204         'blue'   => array(
    205             'label'  => __( 'Blue', 'twentyfifteen' ),
    206             'colors' => array(
    207                 '#e9f2f9',
    208                 '#55c3dc',
    209                 '#ffffff',
    210                 '#22313f',
    211                 '#ffffff',
    212                 '#f1f1f1',
     225            'blue'    => array(
     226                'label'  => __( 'Blue', 'twentyfifteen' ),
     227                'colors' => array(
     228                    '#e9f2f9',
     229                    '#55c3dc',
     230                    '#ffffff',
     231                    '#22313f',
     232                    '#ffffff',
     233                    '#f1f1f1',
     234                ),
    213235            ),
    214         ),
    215     ) );
     236        )
     237    );
    216238}
    217239
    218240if ( ! function_exists( 'twentyfifteen_get_color_scheme' ) ) :
    219 /**
    220  * Get the current Twenty Fifteen color scheme.
    221  *
    222  * @since Twenty Fifteen 1.0
    223  *
    224  * @return array An associative array of either the current or default color scheme hex values.
    225  */
    226 function twentyfifteen_get_color_scheme() {
    227     $color_scheme_option = get_theme_mod( 'color_scheme', 'default' );
    228     $color_schemes       = twentyfifteen_get_color_schemes();
    229 
    230     if ( array_key_exists( $color_scheme_option, $color_schemes ) ) {
    231         return $color_schemes[ $color_scheme_option ]['colors'];
    232     }
    233 
    234     return $color_schemes['default']['colors'];
    235 }
     241    /**
     242    * Get the current Twenty Fifteen color scheme.
     243    *
     244    * @since Twenty Fifteen 1.0
     245    *
     246    * @return array An associative array of either the current or default color scheme hex values.
     247    */
     248    function twentyfifteen_get_color_scheme() {
     249        $color_scheme_option = get_theme_mod( 'color_scheme', 'default' );
     250        $color_schemes       = twentyfifteen_get_color_schemes();
     251
     252        if ( array_key_exists( $color_scheme_option, $color_schemes ) ) {
     253            return $color_schemes[ $color_scheme_option ]['colors'];
     254        }
     255
     256        return $color_schemes['default']['colors'];
     257    }
    236258endif; // twentyfifteen_get_color_scheme
    237259
    238260if ( ! function_exists( 'twentyfifteen_get_color_scheme_choices' ) ) :
    239 /**
    240  * Returns an array of color scheme choices registered for Twenty Fifteen.
    241  *
    242  * @since Twenty Fifteen 1.0
    243  *
    244  * @return array Array of color schemes.
    245  */
    246 function twentyfifteen_get_color_scheme_choices() {
    247     $color_schemes                = twentyfifteen_get_color_schemes();
    248     $color_scheme_control_options = array();
    249 
    250     foreach ( $color_schemes as $color_scheme => $value ) {
    251         $color_scheme_control_options[ $color_scheme ] = $value['label'];
    252     }
    253 
    254     return $color_scheme_control_options;
    255 }
     261    /**
     262    * Returns an array of color scheme choices registered for Twenty Fifteen.
     263    *
     264    * @since Twenty Fifteen 1.0
     265    *
     266    * @return array Array of color schemes.
     267    */
     268    function twentyfifteen_get_color_scheme_choices() {
     269        $color_schemes                = twentyfifteen_get_color_schemes();
     270        $color_scheme_control_options = array();
     271
     272        foreach ( $color_schemes as $color_scheme => $value ) {
     273            $color_scheme_control_options[ $color_scheme ] = $value['label'];
     274        }
     275
     276        return $color_scheme_control_options;
     277    }
    256278endif; // twentyfifteen_get_color_scheme_choices
    257279
    258280if ( ! function_exists( 'twentyfifteen_sanitize_color_scheme' ) ) :
    259 /**
    260  * Sanitization callback for color schemes.
    261  *
    262  * @since Twenty Fifteen 1.0
    263  *
    264  * @param string $value Color scheme name value.
    265  * @return string Color scheme name.
    266  */
    267 function twentyfifteen_sanitize_color_scheme( $value ) {
    268     $color_schemes = twentyfifteen_get_color_scheme_choices();
    269 
    270     if ( ! array_key_exists( $value, $color_schemes ) ) {
    271         $value = 'default';
    272     }
    273 
    274     return $value;
    275 }
     281    /**
     282    * Sanitization callback for color schemes.
     283    *
     284    * @since Twenty Fifteen 1.0
     285    *
     286    * @param string $value Color scheme name value.
     287    * @return string Color scheme name.
     288    */
     289    function twentyfifteen_sanitize_color_scheme( $value ) {
     290        $color_schemes = twentyfifteen_get_color_scheme_choices();
     291
     292        if ( ! array_key_exists( $value, $color_schemes ) ) {
     293            $value = 'default';
     294        }
     295
     296        return $value;
     297    }
    276298endif; // twentyfifteen_sanitize_color_scheme
    277299
     
    296318    $color_textcolor_rgb         = twentyfifteen_hex2rgb( $color_scheme[3] );
    297319    $color_sidebar_textcolor_rgb = twentyfifteen_hex2rgb( $color_scheme[4] );
    298     $colors = array(
     320    $colors                      = array(
    299321        'background_color'            => $color_scheme[0],
    300322        'header_background_color'     => $color_scheme[1],
     
    349371 */
    350372function twentyfifteen_get_color_scheme_css( $colors ) {
    351     $colors = wp_parse_args( $colors, array(
    352         'background_color'            => '',
    353         'header_background_color'     => '',
    354         'box_background_color'        => '',
    355         'textcolor'                   => '',
    356         'secondary_textcolor'         => '',
    357         'border_color'                => '',
    358         'border_focus_color'          => '',
    359         'sidebar_textcolor'           => '',
    360         'sidebar_border_color'        => '',
    361         'sidebar_border_focus_color'  => '',
    362         'secondary_sidebar_textcolor' => '',
    363         'meta_box_background_color'   => '',
    364     ) );
     373    $colors = wp_parse_args(
     374        $colors, array(
     375            'background_color'            => '',
     376            'header_background_color'     => '',
     377            'box_background_color'        => '',
     378            'textcolor'                   => '',
     379            'secondary_textcolor'         => '',
     380            'border_color'                => '',
     381            'border_focus_color'          => '',
     382            'sidebar_textcolor'           => '',
     383            'sidebar_border_color'        => '',
     384            'sidebar_border_focus_color'  => '',
     385            'secondary_sidebar_textcolor' => '',
     386            'meta_box_background_color'   => '',
     387        )
     388    );
    365389
    366390    $css = <<<CSS
Note: See TracChangeset for help on using the changeset viewer.