Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (8 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-includes/theme.php

    r41995 r42343  
    3131    global $wp_theme_directories;
    3232
    33     $defaults = array( 'errors' => false, 'allowed' => null, 'blog_id' => 0 );
    34     $args = wp_parse_args( $args, $defaults );
     33    $defaults = array(
     34        'errors'  => false,
     35        'allowed' => null,
     36        'blog_id' => 0,
     37    );
     38    $args     = wp_parse_args( $args, $defaults );
    3539
    3640    $theme_directories = search_theme_directories();
     
    4246        if ( isset( $theme_directories[ $current_theme ] ) ) {
    4347            $root_of_current_theme = get_raw_theme_root( $current_theme );
    44             if ( ! in_array( $root_of_current_theme, $wp_theme_directories ) )
     48            if ( ! in_array( $root_of_current_theme, $wp_theme_directories ) ) {
    4549                $root_of_current_theme = WP_CONTENT_DIR . $root_of_current_theme;
     50            }
    4651            $theme_directories[ $current_theme ]['theme_root'] = $root_of_current_theme;
    4752        }
    4853    }
    4954
    50     if ( empty( $theme_directories ) )
     55    if ( empty( $theme_directories ) ) {
    5156        return array();
     57    }
    5258
    5359    if ( is_multisite() && null !== $args['allowed'] ) {
    5460        $allowed = $args['allowed'];
    55         if ( 'network' === $allowed )
     61        if ( 'network' === $allowed ) {
    5662            $theme_directories = array_intersect_key( $theme_directories, WP_Theme::get_allowed_on_network() );
    57         elseif ( 'site' === $allowed )
     63        } elseif ( 'site' === $allowed ) {
    5864            $theme_directories = array_intersect_key( $theme_directories, WP_Theme::get_allowed_on_site( $args['blog_id'] ) );
    59         elseif ( $allowed )
     65        } elseif ( $allowed ) {
    6066            $theme_directories = array_intersect_key( $theme_directories, WP_Theme::get_allowed( $args['blog_id'] ) );
    61         else
     67        } else {
    6268            $theme_directories = array_diff_key( $theme_directories, WP_Theme::get_allowed( $args['blog_id'] ) );
    63     }
    64 
    65     $themes = array();
     69        }
     70    }
     71
     72    $themes         = array();
    6673    static $_themes = array();
    6774
    6875    foreach ( $theme_directories as $theme => $theme_root ) {
    69         if ( isset( $_themes[ $theme_root['theme_root'] . '/' . $theme ] ) )
     76        if ( isset( $_themes[ $theme_root['theme_root'] . '/' . $theme ] ) ) {
    7077            $themes[ $theme ] = $_themes[ $theme_root['theme_root'] . '/' . $theme ];
    71         else
     78        } else {
    7279            $themes[ $theme ] = $_themes[ $theme_root['theme_root'] . '/' . $theme ] = new WP_Theme( $theme, $theme_root['theme_root'] );
     80        }
    7381    }
    7482
    7583    if ( null !== $args['errors'] ) {
    7684        foreach ( $themes as $theme => $wp_theme ) {
    77             if ( $wp_theme->errors() != $args['errors'] )
     85            if ( $wp_theme->errors() != $args['errors'] ) {
    7886                unset( $themes[ $theme ] );
     87            }
    7988        }
    8089    }
     
    92101 * @param string $stylesheet Directory name for the theme. Optional. Defaults to current theme.
    93102 * @param string $theme_root Absolute path of the theme root to look in. Optional. If not specified, get_raw_theme_root()
    94  *                           is used to calculate the theme root for the $stylesheet provided (or current theme).
     103 *                           is used to calculate the theme root for the $stylesheet provided (or current theme).
    95104 * @return WP_Theme Theme object. Be sure to check the object's exists() method if you need to confirm the theme's existence.
    96105 */
     
    98107    global $wp_theme_directories;
    99108
    100     if ( empty( $stylesheet ) )
     109    if ( empty( $stylesheet ) ) {
    101110        $stylesheet = get_stylesheet();
     111    }
    102112
    103113    if ( empty( $theme_root ) ) {
    104114        $theme_root = get_raw_theme_root( $stylesheet );
    105         if ( false === $theme_root )
     115        if ( false === $theme_root ) {
    106116            $theme_root = WP_CONTENT_DIR . '/themes';
    107         elseif ( ! in_array( $theme_root, (array) $wp_theme_directories ) )
     117        } elseif ( ! in_array( $theme_root, (array) $wp_theme_directories ) ) {
    108118            $theme_root = WP_CONTENT_DIR . $theme_root;
     119        }
    109120    }
    110121
     
    119130 */
    120131function wp_clean_themes_cache( $clear_update_cache = true ) {
    121     if ( $clear_update_cache )
     132    if ( $clear_update_cache ) {
    122133        delete_site_transient( 'update_themes' );
     134    }
    123135    search_theme_directories( true );
    124     foreach ( wp_get_themes( array( 'errors' => null ) ) as $theme )
     136    foreach ( wp_get_themes( array( 'errors' => null ) ) as $theme ) {
    125137        $theme->cache_delete();
     138    }
    126139}
    127140
     
    132145 *
    133146 * @return bool true if a child theme is in use, false otherwise.
    134  **/
     147 */
    135148function is_child_theme() {
    136149    return ( TEMPLATEPATH !== STYLESHEETPATH );
     
    169182 */
    170183function get_stylesheet_directory() {
    171     $stylesheet = get_stylesheet();
    172     $theme_root = get_theme_root( $stylesheet );
     184    $stylesheet     = get_stylesheet();
     185    $theme_root     = get_theme_root( $stylesheet );
    173186    $stylesheet_dir = "$theme_root/$stylesheet";
    174187
     
    193206 */
    194207function get_stylesheet_directory_uri() {
    195     $stylesheet = str_replace( '%2F', '/', rawurlencode( get_stylesheet() ) );
    196     $theme_root_uri = get_theme_root_uri( $stylesheet );
     208    $stylesheet         = str_replace( '%2F', '/', rawurlencode( get_stylesheet() ) );
     209    $theme_root_uri     = get_theme_root_uri( $stylesheet );
    197210    $stylesheet_dir_uri = "$theme_root_uri/$stylesheet";
    198211
     
    221234function get_stylesheet_uri() {
    222235    $stylesheet_dir_uri = get_stylesheet_directory_uri();
    223     $stylesheet_uri = $stylesheet_dir_uri . '/style.css';
     236    $stylesheet_uri     = $stylesheet_dir_uri . '/style.css';
    224237    /**
    225238     * Filters the URI of the current theme stylesheet.
     
    257270    global $wp_locale;
    258271    $stylesheet_dir_uri = get_stylesheet_directory_uri();
    259     $dir = get_stylesheet_directory();
    260     $locale = get_locale();
    261     if ( file_exists("$dir/$locale.css") )
     272    $dir                = get_stylesheet_directory();
     273    $locale             = get_locale();
     274    if ( file_exists( "$dir/$locale.css" ) ) {
    262275        $stylesheet_uri = "$stylesheet_dir_uri/$locale.css";
    263     elseif ( !empty($wp_locale->text_direction) && file_exists("$dir/{$wp_locale->text_direction}.css") )
     276    } elseif ( ! empty( $wp_locale->text_direction ) && file_exists( "$dir/{$wp_locale->text_direction}.css" ) ) {
    264277        $stylesheet_uri = "$stylesheet_dir_uri/{$wp_locale->text_direction}.css";
    265     else
     278    } else {
    266279        $stylesheet_uri = '';
     280    }
    267281    /**
    268282     * Filters the localized stylesheet URI.
     
    302316 */
    303317function get_template_directory() {
    304     $template = get_template();
    305     $theme_root = get_theme_root( $template );
     318    $template     = get_template();
     319    $theme_root   = get_theme_root( $template );
    306320    $template_dir = "$theme_root/$template";
    307321
     
    326340 */
    327341function get_template_directory_uri() {
    328     $template = str_replace( '%2F', '/', rawurlencode( get_template() ) );
    329     $theme_root_uri = get_theme_root_uri( $template );
     342    $template         = str_replace( '%2F', '/', rawurlencode( get_template() ) );
     343    $theme_root_uri   = get_theme_root_uri( $template );
    330344    $template_dir_uri = "$theme_root_uri/$template";
    331345
     
    354368    global $wp_theme_directories;
    355369
    356     if ( count($wp_theme_directories) <= 1 )
     370    if ( count( $wp_theme_directories ) <= 1 ) {
    357371        return '/themes';
     372    }
    358373
    359374    $theme_roots = get_site_transient( 'theme_roots' );
     
    414429    static $found_themes = null;
    415430
    416     if ( empty( $wp_theme_directories ) )
     431    if ( empty( $wp_theme_directories ) ) {
    417432        return false;
    418 
    419     if ( ! $force && isset( $found_themes ) )
     433    }
     434
     435    if ( ! $force && isset( $found_themes ) ) {
    420436        return $found_themes;
     437    }
    421438
    422439    $found_themes = array();
     
    429446    // to use in get_theme_root().
    430447    foreach ( $wp_theme_directories as $theme_root ) {
    431         if ( 0 === strpos( $theme_root, WP_CONTENT_DIR ) )
     448        if ( 0 === strpos( $theme_root, WP_CONTENT_DIR ) ) {
    432449            $relative_theme_roots[ str_replace( WP_CONTENT_DIR, '', $theme_root ) ] = $theme_root;
    433         else
     450        } else {
    434451            $relative_theme_roots[ $theme_root ] = $theme_root;
     452        }
    435453    }
    436454
     
    448466            foreach ( $cached_roots as $theme_dir => $theme_root ) {
    449467                // A cached theme root is no longer around, so skip it.
    450                 if ( ! isset( $relative_theme_roots[ $theme_root ] ) )
     468                if ( ! isset( $relative_theme_roots[ $theme_root ] ) ) {
    451469                    continue;
     470                }
    452471                $found_themes[ $theme_dir ] = array(
    453472                    'theme_file' => $theme_dir . '/style.css',
     
    457476            return $found_themes;
    458477        }
    459         if ( ! is_int( $cache_expiration ) )
     478        if ( ! is_int( $cache_expiration ) ) {
    460479            $cache_expiration = 1800; // half hour
     480        }
    461481    } else {
    462482        $cache_expiration = 1800; // half hour
     
    473493        }
    474494        foreach ( $dirs as $dir ) {
    475             if ( ! is_dir( $theme_root . '/' . $dir ) || $dir[0] == '.' || $dir == 'CVS' )
     495            if ( ! is_dir( $theme_root . '/' . $dir ) || $dir[0] == '.' || $dir == 'CVS' ) {
    476496                continue;
     497            }
    477498            if ( file_exists( $theme_root . '/' . $dir . '/style.css' ) ) {
    478499                // wp-content/themes/a-single-theme
     
    492513                }
    493514                foreach ( $sub_dirs as $sub_dir ) {
    494                     if ( ! is_dir( $theme_root . '/' . $dir . '/' . $sub_dir ) || $dir[0] == '.' || $dir == 'CVS' )
     515                    if ( ! is_dir( $theme_root . '/' . $dir . '/' . $sub_dir ) || $dir[0] == '.' || $dir == 'CVS' ) {
    495516                        continue;
    496                     if ( ! file_exists( $theme_root . '/' . $dir . '/' . $sub_dir . '/style.css' ) )
     517                    }
     518                    if ( ! file_exists( $theme_root . '/' . $dir . '/' . $sub_dir . '/style.css' ) ) {
    497519                        continue;
     520                    }
    498521                    $found_themes[ $dir . '/' . $sub_dir ] = array(
    499522                        'theme_file' => $dir . '/' . $sub_dir . '/style.css',
    500523                        'theme_root' => $theme_root,
    501524                    );
    502                     $found_theme = true;
     525                    $found_theme                           = true;
    503526                }
    504527                // Never mind the above, it's just a theme missing a style.css.
    505528                // Return it; WP_Theme will catch the error.
    506                 if ( ! $found_theme )
     529                if ( ! $found_theme ) {
    507530                    $found_themes[ $dir ] = array(
    508531                        'theme_file' => $dir . '/style.css',
    509532                        'theme_root' => $theme_root,
    510533                    );
     534                }
    511535            }
    512536        }
     
    515539    asort( $found_themes );
    516540
    517     $theme_roots = array();
     541    $theme_roots          = array();
    518542    $relative_theme_roots = array_flip( $relative_theme_roots );
    519543
     
    522546    }
    523547
    524     if ( $theme_roots != get_site_transient( 'theme_roots' ) )
     548    if ( $theme_roots != get_site_transient( 'theme_roots' ) ) {
    525549        set_site_transient( 'theme_roots', $theme_roots, $cache_expiration );
     550    }
    526551
    527552    return $found_themes;
     
    546571        // Always prepend WP_CONTENT_DIR unless the root currently registered as a theme directory.
    547572        // This gives relative theme roots the benefit of the doubt when things go haywire.
    548         if ( ! in_array( $theme_root, (array) $wp_theme_directories ) )
     573        if ( ! in_array( $theme_root, (array) $wp_theme_directories ) ) {
    549574            $theme_root = WP_CONTENT_DIR . $theme_root;
     575        }
    550576    } else {
    551577        $theme_root = WP_CONTENT_DIR . '/themes';
     
    572598 *
    573599 * @param string $stylesheet_or_template Optional. The stylesheet or template name of the theme.
    574  *                                       Default is to leverage the main theme root.
     600 *                                       Default is to leverage the main theme root.
    575601 * @param string $theme_root             Optional. The theme root for which calculations will be based, preventing
    576  *                                       the need for a get_raw_theme_root() call.
     602 *                                       the need for a get_raw_theme_root() call.
    577603 * @return string Themes URI.
    578604 */
     
    580606    global $wp_theme_directories;
    581607
    582     if ( $stylesheet_or_template && ! $theme_root )
     608    if ( $stylesheet_or_template && ! $theme_root ) {
    583609        $theme_root = get_raw_theme_root( $stylesheet_or_template );
     610    }
    584611
    585612    if ( $stylesheet_or_template && $theme_root ) {
    586613        if ( in_array( $theme_root, (array) $wp_theme_directories ) ) {
    587614            // Absolute path. Make an educated guess. YMMV -- but note the filter below.
    588             if ( 0 === strpos( $theme_root, WP_CONTENT_DIR ) )
     615            if ( 0 === strpos( $theme_root, WP_CONTENT_DIR ) ) {
    589616                $theme_root_uri = content_url( str_replace( WP_CONTENT_DIR, '', $theme_root ) );
    590             elseif ( 0 === strpos( $theme_root, ABSPATH ) )
     617            } elseif ( 0 === strpos( $theme_root, ABSPATH ) ) {
    591618                $theme_root_uri = site_url( str_replace( ABSPATH, '', $theme_root ) );
    592             elseif ( 0 === strpos( $theme_root, WP_PLUGIN_DIR ) || 0 === strpos( $theme_root, WPMU_PLUGIN_DIR ) )
     619            } elseif ( 0 === strpos( $theme_root, WP_PLUGIN_DIR ) || 0 === strpos( $theme_root, WPMU_PLUGIN_DIR ) ) {
    593620                $theme_root_uri = plugins_url( basename( $theme_root ), $theme_root );
    594             else
     621            } else {
    595622                $theme_root_uri = $theme_root;
     623            }
    596624        } else {
    597625            $theme_root_uri = content_url( $theme_root );
     
    636664    // If requesting the root for the current theme, consult options to avoid calling get_theme_roots()
    637665    if ( ! $skip_cache ) {
    638         if ( get_option('stylesheet') == $stylesheet_or_template )
    639             $theme_root = get_option('stylesheet_root');
    640         elseif ( get_option('template') == $stylesheet_or_template )
    641             $theme_root = get_option('template_root');
    642     }
    643 
    644     if ( empty($theme_root) ) {
     666        if ( get_option( 'stylesheet' ) == $stylesheet_or_template ) {
     667            $theme_root = get_option( 'stylesheet_root' );
     668        } elseif ( get_option( 'template' ) == $stylesheet_or_template ) {
     669            $theme_root = get_option( 'template_root' );
     670        }
     671    }
     672
     673    if ( empty( $theme_root ) ) {
    645674        $theme_roots = get_theme_roots();
    646         if ( !empty($theme_roots[$stylesheet_or_template]) )
    647             $theme_root = $theme_roots[$stylesheet_or_template];
     675        if ( ! empty( $theme_roots[ $stylesheet_or_template ] ) ) {
     676            $theme_root = $theme_roots[ $stylesheet_or_template ];
     677        }
    648678    }
    649679
     
    658688function locale_stylesheet() {
    659689    $stylesheet = get_locale_stylesheet_uri();
    660     if ( empty($stylesheet) )
     690    if ( empty( $stylesheet ) ) {
    661691        return;
     692    }
    662693    echo '<link rel="stylesheet" href="' . $stylesheet . '" type="text/css" media="screen" />';
    663694}
     
    691722
    692723    if ( is_array( $_sidebars_widgets ) ) {
    693         set_theme_mod( 'sidebars_widgets', array( 'time' => time(), 'data' => $_sidebars_widgets ) );
     724        set_theme_mod(
     725            'sidebars_widgets', array(
     726                'time' => time(),
     727                'data' => $_sidebars_widgets,
     728            )
     729        );
    694730    }
    695731
     
    716752    }
    717753
    718     $new_name  = $new_theme->get('Name');
     754    $new_name = $new_theme->get( 'Name' );
    719755
    720756    update_option( 'current_theme', $new_name );
     
    776812     * @param bool $validate Whether to validate the current theme. Default true.
    777813     */
    778     if ( wp_installing() || ! apply_filters( 'validate_current_theme', true ) )
     814    if ( wp_installing() || ! apply_filters( 'validate_current_theme', true ) ) {
    779815        return true;
     816    }
    780817
    781818    if ( ! file_exists( get_template_directory() . '/index.php' ) ) {
     
    823860function get_theme_mods() {
    824861    $theme_slug = get_option( 'stylesheet' );
    825     $mods = get_option( "theme_mods_$theme_slug" );
     862    $mods       = get_option( "theme_mods_$theme_slug" );
    826863    if ( false === $mods ) {
    827864        $theme_name = get_option( 'current_theme' );
    828         if ( false === $theme_name )
    829             $theme_name = wp_get_theme()->get('Name');
     865        if ( false === $theme_name ) {
     866            $theme_name = wp_get_theme()->get( 'Name' );
     867        }
    830868        $mods = get_option( "mods_$theme_name" ); // Deprecated location.
    831869        if ( is_admin() && false !== $mods ) {
     
    854892    $mods = get_theme_mods();
    855893
    856     if ( isset( $mods[$name] ) ) {
     894    if ( isset( $mods[ $name ] ) ) {
    857895        /**
    858896         * Filters the theme modification, or 'theme_mod', value.
     
    867905         * @param string $current_mod The value of the current theme modification.
    868906         */
    869         return apply_filters( "theme_mod_{$name}", $mods[$name] );
    870     }
    871 
    872     if ( is_string( $default ) )
     907        return apply_filters( "theme_mod_{$name}", $mods[ $name ] );
     908    }
     909
     910    if ( is_string( $default ) ) {
    873911        $default = sprintf( $default, get_template_directory_uri(), get_stylesheet_directory_uri() );
     912    }
    874913
    875914    /** This filter is documented in wp-includes/theme.php */
     
    886925 */
    887926function set_theme_mod( $name, $value ) {
    888     $mods = get_theme_mods();
     927    $mods      = get_theme_mods();
    889928    $old_value = isset( $mods[ $name ] ) ? $mods[ $name ] : false;
    890929
     
    920959    $mods = get_theme_mods();
    921960
    922     if ( ! isset( $mods[ $name ] ) )
     961    if ( ! isset( $mods[ $name ] ) ) {
    923962        return;
     963    }
    924964
    925965    unset( $mods[ $name ] );
     
    943983    // Old style.
    944984    $theme_name = get_option( 'current_theme' );
    945     if ( false === $theme_name )
    946         $theme_name = wp_get_theme()->get('Name');
     985    if ( false === $theme_name ) {
     986        $theme_name = wp_get_theme()->get( 'Name' );
     987    }
    947988    delete_option( 'mods_' . $theme_name );
    948989}
     
    956997 */
    957998function get_header_textcolor() {
    958     return get_theme_mod('header_textcolor', get_theme_support( 'custom-header', 'default-text-color' ) );
     999    return get_theme_mod( 'header_textcolor', get_theme_support( 'custom-header', 'default-text-color' ) );
    9591000}
    9601001
     
    9761017 */
    9771018function display_header_text() {
    978     if ( ! current_theme_supports( 'custom-header', 'header-text' ) )
     1019    if ( ! current_theme_supports( 'custom-header', 'header-text' ) ) {
    9791020        return false;
     1021    }
    9801022
    9811023    $text_color = get_theme_mod( 'header_textcolor', get_theme_support( 'custom-header', 'default-text-color' ) );
     
    10061048    $url = get_theme_mod( 'header_image', get_theme_support( 'custom-header', 'default-image' ) );
    10071049
    1008     if ( 'remove-header' == $url )
     1050    if ( 'remove-header' == $url ) {
    10091051        return false;
    1010 
    1011     if ( is_random_header_image() )
     1052    }
     1053
     1054    if ( is_random_header_image() ) {
    10121055        $url = get_random_header_image();
     1056    }
    10131057
    10141058    return esc_url_raw( set_url_scheme( $url ) );
     
    10251069 */
    10261070function get_header_image_tag( $attr = array() ) {
    1027     $header = get_custom_header();
     1071    $header      = get_custom_header();
    10281072    $header->url = get_header_image();
    10291073
     
    10321076    }
    10331077
    1034     $width = absint( $header->width );
     1078    $width  = absint( $header->width );
    10351079    $height = absint( $header->height );
    10361080
     
    10381082        $attr,
    10391083        array(
    1040             'src' => $header->url,
    1041             'width' => $width,
     1084            'src'    => $header->url,
     1085            'width'  => $width,
    10421086            'height' => $height,
    1043             'alt' => get_bloginfo( 'name' ),
     1087            'alt'    => get_bloginfo( 'name' ),
    10441088        )
    10451089    );
     
    10521096        if ( is_array( $image_meta ) ) {
    10531097            $srcset = wp_calculate_image_srcset( $size_array, $header->url, $image_meta, $header->attachment_id );
    1054             $sizes = ! empty( $attr['sizes'] ) ? $attr['sizes'] : wp_calculate_image_sizes( $size_array, $header->url, $image_meta, $header->attachment_id );
     1098            $sizes  = ! empty( $attr['sizes'] ) ? $attr['sizes'] : wp_calculate_image_sizes( $size_array, $header->url, $image_meta, $header->attachment_id );
    10551099
    10561100            if ( $srcset && $sizes ) {
    10571101                $attr['srcset'] = $srcset;
    1058                 $attr['sizes'] = $sizes;
     1102                $attr['sizes']  = $sizes;
    10591103            }
    10601104        }
     
    11111155        global $_wp_default_headers;
    11121156        $header_image_mod = get_theme_mod( 'header_image', '' );
    1113         $headers = array();
    1114 
    1115         if ( 'random-uploaded-image' == $header_image_mod )
     1157        $headers          = array();
     1158
     1159        if ( 'random-uploaded-image' == $header_image_mod ) {
    11161160            $headers = get_uploaded_header_images();
    1117         elseif ( ! empty( $_wp_default_headers ) ) {
     1161        } elseif ( ! empty( $_wp_default_headers ) ) {
    11181162            if ( 'random-default-image' == $header_image_mod ) {
    11191163                $headers = $_wp_default_headers;
    11201164            } else {
    1121                 if ( current_theme_supports( 'custom-header', 'random-default' ) )
     1165                if ( current_theme_supports( 'custom-header', 'random-default' ) ) {
    11221166                    $headers = $_wp_default_headers;
    1123             }
    1124         }
    1125 
    1126         if ( empty( $headers ) )
     1167                }
     1168            }
     1169        }
     1170
     1171        if ( empty( $headers ) ) {
    11271172            return new stdClass;
     1173        }
    11281174
    11291175        $_wp_random_header = (object) $headers[ array_rand( $headers ) ];
    11301176
    1131         $_wp_random_header->url = sprintf( $_wp_random_header->url, get_template_directory_uri(), get_stylesheet_directory_uri() );
    1132         $_wp_random_header->thumbnail_url =  sprintf( $_wp_random_header->thumbnail_url, get_template_directory_uri(), get_stylesheet_directory_uri() );
     1177        $_wp_random_header->url           = sprintf( $_wp_random_header->url, get_template_directory_uri(), get_stylesheet_directory_uri() );
     1178        $_wp_random_header->thumbnail_url = sprintf( $_wp_random_header->thumbnail_url, get_template_directory_uri(), get_stylesheet_directory_uri() );
    11331179    }
    11341180    return $_wp_random_header;
     
    11441190function get_random_header_image() {
    11451191    $random_image = _get_random_header_data();
    1146     if ( empty( $random_image->url ) )
     1192    if ( empty( $random_image->url ) ) {
    11471193        return '';
     1194    }
    11481195    return $random_image->url;
    11491196}
     
    11651212
    11661213    if ( 'any' == $type ) {
    1167         if ( 'random-default-image' == $header_image_mod || 'random-uploaded-image' == $header_image_mod || ( '' != get_random_header_image() && empty( $header_image_mod ) ) )
     1214        if ( 'random-default-image' == $header_image_mod || 'random-uploaded-image' == $header_image_mod || ( '' != get_random_header_image() && empty( $header_image_mod ) ) ) {
    11681215            return true;
     1216        }
    11691217    } else {
    1170         if ( "random-$type-image" == $header_image_mod )
     1218        if ( "random-$type-image" == $header_image_mod ) {
    11711219            return true;
    1172         elseif ( 'default' == $type && empty( $header_image_mod ) && '' != get_random_header_image() )
     1220        } elseif ( 'default' == $type && empty( $header_image_mod ) && '' != get_random_header_image() ) {
    11731221            return true;
     1222        }
    11741223    }
    11751224
     
    12001249
    12011250    // @todo caching
    1202     $headers = get_posts( array( 'post_type' => 'attachment', 'meta_key' => '_wp_attachment_is_custom_header', 'meta_value' => get_option('stylesheet'), 'orderby' => 'none', 'nopaging' => true ) );
    1203 
    1204     if ( empty( $headers ) )
     1251    $headers = get_posts(
     1252        array(
     1253            'post_type'  => 'attachment',
     1254            'meta_key'   => '_wp_attachment_is_custom_header',
     1255            'meta_value' => get_option( 'stylesheet' ),
     1256            'orderby'    => 'none',
     1257            'nopaging'   => true,
     1258        )
     1259    );
     1260
     1261    if ( empty( $headers ) ) {
    12051262        return array();
     1263    }
    12061264
    12071265    foreach ( (array) $headers as $header ) {
    1208         $url = esc_url_raw( wp_get_attachment_url( $header->ID ) );
    1209         $header_data = wp_get_attachment_metadata( $header->ID );
     1266        $url          = esc_url_raw( wp_get_attachment_url( $header->ID ) );
     1267        $header_data  = wp_get_attachment_metadata( $header->ID );
    12101268        $header_index = $header->ID;
    12111269
    1212         $header_images[$header_index] = array();
    1213         $header_images[$header_index]['attachment_id'] = $header->ID;
    1214         $header_images[$header_index]['url'] =  $url;
    1215         $header_images[$header_index]['thumbnail_url'] = $url;
    1216         $header_images[$header_index]['alt_text'] = get_post_meta( $header->ID, '_wp_attachment_image_alt', true );
    1217         $header_images[$header_index]['attachment_parent'] = isset( $header_data['attachment_parent'] ) ? $header_data['attachment_parent'] : '';
    1218 
    1219         if ( isset( $header_data['width'] ) )
    1220             $header_images[$header_index]['width'] = $header_data['width'];
    1221         if ( isset( $header_data['height'] ) )
    1222             $header_images[$header_index]['height'] = $header_data['height'];
     1270        $header_images[ $header_index ]                      = array();
     1271        $header_images[ $header_index ]['attachment_id']     = $header->ID;
     1272        $header_images[ $header_index ]['url']               = $url;
     1273        $header_images[ $header_index ]['thumbnail_url']     = $url;
     1274        $header_images[ $header_index ]['alt_text']          = get_post_meta( $header->ID, '_wp_attachment_image_alt', true );
     1275        $header_images[ $header_index ]['attachment_parent'] = isset( $header_data['attachment_parent'] ) ? $header_data['attachment_parent'] : '';
     1276
     1277        if ( isset( $header_data['width'] ) ) {
     1278            $header_images[ $header_index ]['width'] = $header_data['width'];
     1279        }
     1280        if ( isset( $header_data['height'] ) ) {
     1281            $header_images[ $header_index ]['height'] = $header_data['height'];
     1282        }
    12231283    }
    12241284
     
    12441304        if ( ! $data && current_theme_supports( 'custom-header', 'default-image' ) ) {
    12451305            $directory_args = array( get_template_directory_uri(), get_stylesheet_directory_uri() );
    1246             $data = array();
    1247             $data['url'] = $data['thumbnail_url'] = vsprintf( get_theme_support( 'custom-header', 'default-image' ), $directory_args );
     1306            $data           = array();
     1307            $data['url']    = $data['thumbnail_url'] = vsprintf( get_theme_support( 'custom-header', 'default-image' ), $directory_args );
    12481308            if ( ! empty( $_wp_default_headers ) ) {
    12491309                foreach ( (array) $_wp_default_headers as $default_header ) {
    12501310                    $url = vsprintf( $default_header['url'], $directory_args );
    12511311                    if ( $data['url'] == $url ) {
    1252                         $data = $default_header;
    1253                         $data['url'] = $url;
     1312                        $data                  = $default_header;
     1313                        $data['url']           = $url;
    12541314                        $data['thumbnail_url'] = vsprintf( $data['thumbnail_url'], $directory_args );
    12551315                        break;
     
    13351395 */
    13361396function get_header_video_url() {
    1337     $id = absint( get_theme_mod( 'header_video' ) );
     1397    $id  = absint( get_theme_mod( 'header_video' ) );
    13381398    $url = esc_url( get_theme_mod( 'external_header_video' ) );
    13391399
     
    13941454            'pause'      => __( 'Pause' ),
    13951455            'play'       => __( 'Play' ),
    1396             'pauseSpeak' => __( 'Video is paused.'),
    1397             'playSpeak'  => __( 'Video is playing.'),
     1456            'pauseSpeak' => __( 'Video is paused.' ),
     1457            'playSpeak'  => __( 'Video is playing.' ),
    13981458        ),
    13991459    );
     
    15041564 */
    15051565function get_background_image() {
    1506     return get_theme_mod('background_image', get_theme_support( 'custom-background', 'default-image' ) );
     1566    return get_theme_mod( 'background_image', get_theme_support( 'custom-background', 'default-image' ) );
    15071567}
    15081568
     
    15241584 */
    15251585function get_background_color() {
    1526     return get_theme_mod('background_color', get_theme_support( 'custom-background', 'default-color' ) );
     1586    return get_theme_mod( 'background_color', get_theme_support( 'custom-background', 'default-color' ) );
    15271587}
    15281588
     
    16221682function wp_custom_css_cb() {
    16231683    $styles = wp_get_custom_css();
    1624     if ( $styles || is_customize_preview() ) : ?>
     1684    if ( $styles || is_customize_preview() ) :
     1685    ?>
    16251686        <style type="text/css" id="wp-custom-css">
    16261687            <?php echo strip_tags( $styles ); // Note that esc_html() cannot be used because `div &gt; span` is not interpreted properly. ?>
    16271688        </style>
    1628     <?php endif;
     1689    <?php
     1690    endif;
    16291691}
    16301692
     
    16651727        if ( ! $post && -1 !== $post_id ) {
    16661728            $query = new WP_Query( $custom_css_query_vars );
    1667             $post = $query->post;
     1729            $post  = $query->post;
    16681730            /*
    16691731             * Cache the lookup. See wp_update_custom_css_post().
     
    16741736    } else {
    16751737        $query = new WP_Query( $custom_css_query_vars );
    1676         $post = $query->post;
     1738        $post  = $query->post;
    16771739    }
    16781740
     
    17301792 */
    17311793function wp_update_custom_css_post( $css, $args = array() ) {
    1732     $args = wp_parse_args( $args, array(
    1733         'preprocessed' => '',
    1734         'stylesheet' => get_stylesheet(),
    1735     ) );
     1794    $args = wp_parse_args(
     1795        $args, array(
     1796            'preprocessed' => '',
     1797            'stylesheet'   => get_stylesheet(),
     1798        )
     1799    );
    17361800
    17371801    $data = array(
    1738         'css' => $css,
     1802        'css'          => $css,
    17391803        'preprocessed' => $args['preprocessed'],
    17401804    );
     
    17761840
    17771841    $post_data = array(
    1778         'post_title' => $args['stylesheet'],
    1779         'post_name' => sanitize_title( $args['stylesheet'] ),
    1780         'post_type' => 'custom_css',
    1781         'post_status' => 'publish',
    1782         'post_content' => $data['css'],
     1842        'post_title'            => $args['stylesheet'],
     1843        'post_name'             => sanitize_title( $args['stylesheet'] ),
     1844        'post_type'             => 'custom_css',
     1845        'post_status'           => 'publish',
     1846        'post_content'          => $data['css'],
    17831847        'post_content_filtered' => $data['preprocessed'],
    17841848    );
     
    17881852    if ( $post ) {
    17891853        $post_data['ID'] = $post->ID;
    1790         $r = wp_update_post( wp_slash( $post_data ), true );
     1854        $r               = wp_update_post( wp_slash( $post_data ), true );
    17911855    } else {
    17921856        $r = wp_insert_post( wp_slash( $post_data ), true );
     
    18301894 *
    18311895 * @param array|string $stylesheet Optional. Stylesheet name or array thereof, relative to theme root.
    1832  *                                 Defaults to 'editor-style.css'
     1896 *                                 Defaults to 'editor-style.css'
    18331897 */
    18341898function add_editor_style( $stylesheet = 'editor-style.css' ) {
    18351899    add_theme_support( 'editor-style' );
    18361900
    1837     if ( ! is_admin() )
     1901    if ( ! is_admin() ) {
    18381902        return;
     1903    }
    18391904
    18401905    global $editor_styles;
     
    18421907    $stylesheet    = (array) $stylesheet;
    18431908    if ( is_rtl() ) {
    1844         $rtl_stylesheet = str_replace('.css', '-rtl.css', $stylesheet[0]);
    1845         $stylesheet[] = $rtl_stylesheet;
     1909        $rtl_stylesheet = str_replace( '.css', '-rtl.css', $stylesheet[0] );
     1910        $stylesheet[]   = $rtl_stylesheet;
    18461911    }
    18471912
     
    18591924 */
    18601925function remove_editor_styles() {
    1861     if ( ! current_theme_supports( 'editor-style' ) )
     1926    if ( ! current_theme_supports( 'editor-style' ) ) {
    18621927        return false;
     1928    }
    18631929    _remove_theme_support( 'editor-style' );
    1864     if ( is_admin() )
     1930    if ( is_admin() ) {
    18651931        $GLOBALS['editor_styles'] = array();
     1932    }
    18661933    return true;
    18671934}
     
    18831950
    18841951        $editor_styles = array_unique( array_filter( $editor_styles ) );
    1885         $style_uri = get_stylesheet_directory_uri();
    1886         $style_dir = get_stylesheet_directory();
     1952        $style_uri     = get_stylesheet_directory_uri();
     1953        $style_dir     = get_stylesheet_directory();
    18871954
    18881955        // Support externally referenced styles (like, say, fonts).
     
    19392006
    19402007    $core_content = array(
    1941         'widgets' => array(
    1942             'text_business_info' => array( 'text', array(
    1943                 'title' => _x( 'Find Us', 'Theme starter content' ),
    1944                 'text' => join( '', array(
    1945                     '<strong>' . _x( 'Address', 'Theme starter content' ) . "</strong>\n",
    1946                     _x( '123 Main Street', 'Theme starter content' ) . "\n" . _x( 'New York, NY 10001', 'Theme starter content' ) . "\n\n",
    1947                     '<strong>' . _x( 'Hours', 'Theme starter content' ) . "</strong>\n",
    1948                     _x( 'Monday&mdash;Friday: 9:00AM&ndash;5:00PM', 'Theme starter content' ) . "\n" . _x( 'Saturday &amp; Sunday: 11:00AM&ndash;3:00PM', 'Theme starter content' )
    1949                 ) ),
    1950                 'filter' => true,
    1951                 'visual' => true,
    1952             ) ),
    1953             'text_about' => array( 'text', array(
    1954                 'title' => _x( 'About This Site', 'Theme starter content' ),
    1955                 'text' => _x( 'This may be a good place to introduce yourself and your site or include some credits.', 'Theme starter content' ),
    1956                 'filter' => true,
    1957                 'visual' => true,
    1958             ) ),
    1959             'archives' => array( 'archives', array(
    1960                 'title' => _x( 'Archives', 'Theme starter content' ),
    1961             ) ),
    1962             'calendar' => array( 'calendar', array(
    1963                 'title' => _x( 'Calendar', 'Theme starter content' ),
    1964             ) ),
    1965             'categories' => array( 'categories', array(
    1966                 'title' => _x( 'Categories', 'Theme starter content' ),
    1967             ) ),
    1968             'meta' => array( 'meta', array(
    1969                 'title' => _x( 'Meta', 'Theme starter content' ),
    1970             ) ),
    1971             'recent-comments' => array( 'recent-comments', array(
    1972                 'title' => _x( 'Recent Comments', 'Theme starter content' ),
    1973             ) ),
    1974             'recent-posts' => array( 'recent-posts', array(
    1975                 'title' => _x( 'Recent Posts', 'Theme starter content' ),
    1976             ) ),
    1977             'search' => array( 'search', array(
    1978                 'title' => _x( 'Search', 'Theme starter content' ),
    1979             ) ),
     2008        'widgets'   => array(
     2009            'text_business_info' => array(
     2010                'text',
     2011                array(
     2012                    'title'  => _x( 'Find Us', 'Theme starter content' ),
     2013                    'text'   => join(
     2014                        '', array(
     2015                            '<strong>' . _x( 'Address', 'Theme starter content' ) . "</strong>\n",
     2016                            _x( '123 Main Street', 'Theme starter content' ) . "\n" . _x( 'New York, NY 10001', 'Theme starter content' ) . "\n\n",
     2017                            '<strong>' . _x( 'Hours', 'Theme starter content' ) . "</strong>\n",
     2018                            _x( 'Monday&mdash;Friday: 9:00AM&ndash;5:00PM', 'Theme starter content' ) . "\n" . _x( 'Saturday &amp; Sunday: 11:00AM&ndash;3:00PM', 'Theme starter content' ),
     2019                        )
     2020                    ),
     2021                    'filter' => true,
     2022                    'visual' => true,
     2023                ),
     2024            ),
     2025            'text_about'         => array(
     2026                'text',
     2027                array(
     2028                    'title'  => _x( 'About This Site', 'Theme starter content' ),
     2029                    'text'   => _x( 'This may be a good place to introduce yourself and your site or include some credits.', 'Theme starter content' ),
     2030                    'filter' => true,
     2031                    'visual' => true,
     2032                ),
     2033            ),
     2034            'archives'           => array(
     2035                'archives',
     2036                array(
     2037                    'title' => _x( 'Archives', 'Theme starter content' ),
     2038                ),
     2039            ),
     2040            'calendar'           => array(
     2041                'calendar',
     2042                array(
     2043                    'title' => _x( 'Calendar', 'Theme starter content' ),
     2044                ),
     2045            ),
     2046            'categories'         => array(
     2047                'categories',
     2048                array(
     2049                    'title' => _x( 'Categories', 'Theme starter content' ),
     2050                ),
     2051            ),
     2052            'meta'               => array(
     2053                'meta',
     2054                array(
     2055                    'title' => _x( 'Meta', 'Theme starter content' ),
     2056                ),
     2057            ),
     2058            'recent-comments'    => array(
     2059                'recent-comments',
     2060                array(
     2061                    'title' => _x( 'Recent Comments', 'Theme starter content' ),
     2062                ),
     2063            ),
     2064            'recent-posts'       => array(
     2065                'recent-posts',
     2066                array(
     2067                    'title' => _x( 'Recent Posts', 'Theme starter content' ),
     2068                ),
     2069            ),
     2070            'search'             => array(
     2071                'search',
     2072                array(
     2073                    'title' => _x( 'Search', 'Theme starter content' ),
     2074                ),
     2075            ),
    19802076        ),
    19812077        'nav_menus' => array(
    1982             'link_home' => array(
    1983                 'type' => 'custom',
     2078            'link_home'       => array(
     2079                'type'  => 'custom',
    19842080                'title' => _x( 'Home', 'Theme starter content' ),
    1985                 'url' => home_url( '/' ),
     2081                'url'   => home_url( '/' ),
    19862082            ),
    1987             'page_home' => array( // Deprecated in favor of link_home.
    1988                 'type' => 'post_type',
    1989                 'object' => 'page',
     2083            'page_home'       => array( // Deprecated in favor of link_home.
     2084                'type'      => 'post_type',
     2085                'object'    => 'page',
    19902086                'object_id' => '{{home}}',
    19912087            ),
    1992             'page_about' => array(
    1993                 'type' => 'post_type',
    1994                 'object' => 'page',
     2088            'page_about'      => array(
     2089                'type'      => 'post_type',
     2090                'object'    => 'page',
    19952091                'object_id' => '{{about}}',
    19962092            ),
    1997             'page_blog' => array(
    1998                 'type' => 'post_type',
    1999                 'object' => 'page',
     2093            'page_blog'       => array(
     2094                'type'      => 'post_type',
     2095                'object'    => 'page',
    20002096                'object_id' => '{{blog}}',
    20012097            ),
    2002             'page_news' => array(
    2003                 'type' => 'post_type',
    2004                 'object' => 'page',
     2098            'page_news'       => array(
     2099                'type'      => 'post_type',
     2100                'object'    => 'page',
    20052101                'object_id' => '{{news}}',
    20062102            ),
    2007             'page_contact' => array(
    2008                 'type' => 'post_type',
    2009                 'object' => 'page',
     2103            'page_contact'    => array(
     2104                'type'      => 'post_type',
     2105                'object'    => 'page',
    20102106                'object_id' => '{{contact}}',
    20112107            ),
    20122108
    2013             'link_email' => array(
     2109            'link_email'      => array(
    20142110                'title' => _x( 'Email', 'Theme starter content' ),
    2015                 'url' => 'mailto:wordpress@example.com',
     2111                'url'   => 'mailto:wordpress@example.com',
    20162112            ),
    2017             'link_facebook' => array(
     2113            'link_facebook'   => array(
    20182114                'title' => _x( 'Facebook', 'Theme starter content' ),
    2019                 'url' => 'https://www.facebook.com/wordpress',
     2115                'url'   => 'https://www.facebook.com/wordpress',
    20202116            ),
    20212117            'link_foursquare' => array(
    20222118                'title' => _x( 'Foursquare', 'Theme starter content' ),
    2023                 'url' => 'https://foursquare.com/',
     2119                'url'   => 'https://foursquare.com/',
    20242120            ),
    2025             'link_github' => array(
     2121            'link_github'     => array(
    20262122                'title' => _x( 'GitHub', 'Theme starter content' ),
    2027                 'url' => 'https://github.com/wordpress/',
     2123                'url'   => 'https://github.com/wordpress/',
    20282124            ),
    2029             'link_instagram' => array(
     2125            'link_instagram'  => array(
    20302126                'title' => _x( 'Instagram', 'Theme starter content' ),
    2031                 'url' => 'https://www.instagram.com/explore/tags/wordcamp/',
     2127                'url'   => 'https://www.instagram.com/explore/tags/wordcamp/',
    20322128            ),
    2033             'link_linkedin' => array(
     2129            'link_linkedin'   => array(
    20342130                'title' => _x( 'LinkedIn', 'Theme starter content' ),
    2035                 'url' => 'https://www.linkedin.com/company/1089783',
     2131                'url'   => 'https://www.linkedin.com/company/1089783',
    20362132            ),
    2037             'link_pinterest' => array(
     2133            'link_pinterest'  => array(
    20382134                'title' => _x( 'Pinterest', 'Theme starter content' ),
    2039                 'url' => 'https://www.pinterest.com/',
     2135                'url'   => 'https://www.pinterest.com/',
    20402136            ),
    2041             'link_twitter' => array(
     2137            'link_twitter'    => array(
    20422138                'title' => _x( 'Twitter', 'Theme starter content' ),
    2043                 'url' => 'https://twitter.com/wordpress',
     2139                'url'   => 'https://twitter.com/wordpress',
    20442140            ),
    2045             'link_yelp' => array(
     2141            'link_yelp'       => array(
    20462142                'title' => _x( 'Yelp', 'Theme starter content' ),
    2047                 'url' => 'https://www.yelp.com',
     2143                'url'   => 'https://www.yelp.com',
    20482144            ),
    2049             'link_youtube' => array(
     2145            'link_youtube'    => array(
    20502146                'title' => _x( 'YouTube', 'Theme starter content' ),
    2051                 'url' => 'https://www.youtube.com/channel/UCdof4Ju7amm1chz1gi1T2ZA',
     2147                'url'   => 'https://www.youtube.com/channel/UCdof4Ju7amm1chz1gi1T2ZA',
    20522148            ),
    20532149        ),
    2054         'posts' => array(
    2055             'home' => array(
    2056                 'post_type' => 'page',
    2057                 'post_title' => _x( 'Home', 'Theme starter content' ),
     2150        'posts'     => array(
     2151            'home'             => array(
     2152                'post_type'    => 'page',
     2153                'post_title'   => _x( 'Home', 'Theme starter content' ),
    20582154                'post_content' => _x( 'Welcome to your site! This is your homepage, which is what most visitors will see when they come to your site for the first time.', 'Theme starter content' ),
    20592155            ),
    2060             'about' => array(
    2061                 'post_type' => 'page',
    2062                 'post_title' => _x( 'About', 'Theme starter content' ),
     2156            'about'            => array(
     2157                'post_type'    => 'page',
     2158                'post_title'   => _x( 'About', 'Theme starter content' ),
    20632159                'post_content' => _x( 'You might be an artist who would like to introduce yourself and your work here or maybe you&rsquo;re a business with a mission to describe.', 'Theme starter content' ),
    20642160            ),
    2065             'contact' => array(
    2066                 'post_type' => 'page',
    2067                 'post_title' => _x( 'Contact', 'Theme starter content' ),
     2161            'contact'          => array(
     2162                'post_type'    => 'page',
     2163                'post_title'   => _x( 'Contact', 'Theme starter content' ),
    20682164                'post_content' => _x( 'This is a page with some basic contact information, such as an address and phone number. You might also try a plugin to add a contact form.', 'Theme starter content' ),
    20692165            ),
    2070             'blog' => array(
    2071                 'post_type' => 'page',
     2166            'blog'             => array(
     2167                'post_type'  => 'page',
    20722168                'post_title' => _x( 'Blog', 'Theme starter content' ),
    20732169            ),
    2074             'news' => array(
    2075                 'post_type' => 'page',
     2170            'news'             => array(
     2171                'post_type'  => 'page',
    20762172                'post_title' => _x( 'News', 'Theme starter content' ),
    20772173            ),
    20782174
    20792175            'homepage-section' => array(
    2080                 'post_type' => 'page',
    2081                 'post_title' => _x( 'A homepage section', 'Theme starter content' ),
     2176                'post_type'    => 'page',
     2177                'post_title'   => _x( 'A homepage section', 'Theme starter content' ),
    20822178                'post_content' => _x( 'This is an example of a homepage section. Homepage sections can be any page other than the homepage itself, including the page that shows your latest blog posts.', 'Theme starter content' ),
    20832179            ),
     
    20882184
    20892185    foreach ( $config as $type => $args ) {
    2090         switch( $type ) {
     2186        switch ( $type ) {
    20912187            // Use options and theme_mods as-is.
    2092             case 'options' :
    2093             case 'theme_mods' :
     2188            case 'options':
     2189            case 'theme_mods':
    20942190                $content[ $type ] = $config[ $type ];
    20952191                break;
    20962192
    20972193            // Widgets are grouped into sidebars.
    2098             case 'widgets' :
     2194            case 'widgets':
    20992195                foreach ( $config[ $type ] as $sidebar_id => $widgets ) {
    21002196                    foreach ( $widgets as $id => $widget ) {
     
    21182214
    21192215            // And nav menu items are grouped into nav menus.
    2120             case 'nav_menus' :
     2216            case 'nav_menus':
    21212217                foreach ( $config[ $type ] as $nav_menu_location => $nav_menu ) {
    21222218
     
    21452241
    21462242            // Attachments are posts but have special treatment.
    2147             case 'attachments' :
     2243            case 'attachments':
    21482244                foreach ( $config[ $type ] as $id => $item ) {
    21492245                    if ( ! empty( $item['file'] ) ) {
     
    21542250
    21552251            // All that's left now are posts (besides attachments). Not a default case for the sake of clarity and future work.
    2156             case 'posts' :
     2252            case 'posts':
    21572253                foreach ( $config[ $type ] as $id => $item ) {
    21582254                    if ( is_array( $item ) ) {
     
    22222318    global $_wp_theme_features;
    22232319
    2224     if ( func_num_args() == 1 )
     2320    if ( func_num_args() == 1 ) {
    22252321        $args = true;
    2226     else
     2322    } else {
    22272323        $args = array_slice( func_get_args(), 1 );
     2324    }
    22282325
    22292326    switch ( $feature ) {
     
    22442341            break;
    22452342
    2246         case 'post-formats' :
     2343        case 'post-formats':
    22472344            if ( is_array( $args[0] ) ) {
    22482345                $post_formats = get_post_format_slugs();
     
    22532350            break;
    22542351
    2255         case 'html5' :
     2352        case 'html5':
    22562353            // You can't just pass 'html5', you need to pass an array of types.
    22572354            if ( empty( $args[0] ) ) {
     
    22642361
    22652362            // Calling 'html5' again merges, rather than overwrites.
    2266             if ( isset( $_wp_theme_features['html5'] ) )
     2363            if ( isset( $_wp_theme_features['html5'] ) ) {
    22672364                $args[0] = array_merge( $_wp_theme_features['html5'][0], $args[0] );
     2365            }
    22682366            break;
    22692367
     
    22792377                'header-text' => '',
    22802378            );
    2281             $args[0] = wp_parse_args( array_intersect_key( $args[0], $defaults ), $defaults );
     2379            $args[0]  = wp_parse_args( array_intersect_key( $args[0], $defaults ), $defaults );
    22822380
    22832381            // Allow full flexibility if no size is specified.
     
    22882386            break;
    22892387
    2290         case 'custom-header-uploads' :
     2388        case 'custom-header-uploads':
    22912389            return add_theme_support( 'custom-header', array( 'uploads' => true ) );
    22922390
    2293         case 'custom-header' :
    2294             if ( ! is_array( $args ) )
     2391        case 'custom-header':
     2392            if ( ! is_array( $args ) ) {
    22952393                $args = array( 0 => array() );
     2394            }
    22962395
    22972396            $defaults = array(
    2298                 'default-image' => '',
    2299                 'random-default' => false,
    2300                 'width' => 0,
    2301                 'height' => 0,
    2302                 'flex-height' => false,
    2303                 'flex-width' => false,
    2304                 'default-text-color' => '',
    2305                 'header-text' => true,
    2306                 'uploads' => true,
    2307                 'wp-head-callback' => '',
    2308                 'admin-head-callback' => '',
     2397                'default-image'          => '',
     2398                'random-default'         => false,
     2399                'width'                  => 0,
     2400                'height'                 => 0,
     2401                'flex-height'            => false,
     2402                'flex-width'             => false,
     2403                'default-text-color'     => '',
     2404                'header-text'            => true,
     2405                'uploads'                => true,
     2406                'wp-head-callback'       => '',
     2407                'admin-head-callback'    => '',
    23092408                'admin-preview-callback' => '',
    2310                 'video' => false,
    2311                 'video-active-callback' => 'is_front_page',
     2409                'video'                  => false,
     2410                'video-active-callback'  => 'is_front_page',
    23122411            );
    23132412
     
    23172416            // Merge in data from previous add_theme_support() calls.
    23182417            // The first value registered wins. (A child theme is set up first.)
    2319             if ( isset( $_wp_theme_features['custom-header'] ) )
     2418            if ( isset( $_wp_theme_features['custom-header'] ) ) {
    23202419                $args[0] = wp_parse_args( $_wp_theme_features['custom-header'][0], $args[0] );
     2420            }
    23212421
    23222422            // Load in the defaults at the end, as we need to insure first one wins.
    23232423            // This will cause all constants to be defined, as each arg will then be set to the default.
    2324             if ( $jit )
     2424            if ( $jit ) {
    23252425                $args[0] = wp_parse_args( $args[0], $defaults );
     2426            }
    23262427
    23272428            // If a constant was defined, use that value. Otherwise, define the constant to ensure
     
    23312432            // Constants are lame. Don't reference them. This is just for backward compatibility.
    23322433
    2333             if ( defined( 'NO_HEADER_TEXT' ) )
     2434            if ( defined( 'NO_HEADER_TEXT' ) ) {
    23342435                $args[0]['header-text'] = ! NO_HEADER_TEXT;
    2335             elseif ( isset( $args[0]['header-text'] ) )
     2436            } elseif ( isset( $args[0]['header-text'] ) ) {
    23362437                define( 'NO_HEADER_TEXT', empty( $args[0]['header-text'] ) );
    2337 
    2338             if ( defined( 'HEADER_IMAGE_WIDTH' ) )
     2438            }
     2439
     2440            if ( defined( 'HEADER_IMAGE_WIDTH' ) ) {
    23392441                $args[0]['width'] = (int) HEADER_IMAGE_WIDTH;
    2340             elseif ( isset( $args[0]['width'] ) )
     2442            } elseif ( isset( $args[0]['width'] ) ) {
    23412443                define( 'HEADER_IMAGE_WIDTH', (int) $args[0]['width'] );
    2342 
    2343             if ( defined( 'HEADER_IMAGE_HEIGHT' ) )
     2444            }
     2445
     2446            if ( defined( 'HEADER_IMAGE_HEIGHT' ) ) {
    23442447                $args[0]['height'] = (int) HEADER_IMAGE_HEIGHT;
    2345             elseif ( isset( $args[0]['height'] ) )
     2448            } elseif ( isset( $args[0]['height'] ) ) {
    23462449                define( 'HEADER_IMAGE_HEIGHT', (int) $args[0]['height'] );
    2347 
    2348             if ( defined( 'HEADER_TEXTCOLOR' ) )
     2450            }
     2451
     2452            if ( defined( 'HEADER_TEXTCOLOR' ) ) {
    23492453                $args[0]['default-text-color'] = HEADER_TEXTCOLOR;
    2350             elseif ( isset( $args[0]['default-text-color'] ) )
     2454            } elseif ( isset( $args[0]['default-text-color'] ) ) {
    23512455                define( 'HEADER_TEXTCOLOR', $args[0]['default-text-color'] );
    2352 
    2353             if ( defined( 'HEADER_IMAGE' ) )
     2456            }
     2457
     2458            if ( defined( 'HEADER_IMAGE' ) ) {
    23542459                $args[0]['default-image'] = HEADER_IMAGE;
    2355             elseif ( isset( $args[0]['default-image'] ) )
     2460            } elseif ( isset( $args[0]['default-image'] ) ) {
    23562461                define( 'HEADER_IMAGE', $args[0]['default-image'] );
    2357 
    2358             if ( $jit && ! empty( $args[0]['default-image'] ) )
     2462            }
     2463
     2464            if ( $jit && ! empty( $args[0]['default-image'] ) ) {
    23592465                $args[0]['random-default'] = false;
     2466            }
    23602467
    23612468            // If headers are supported, and we still don't have a defined width or height,
    23622469            // we have implicit flex sizes.
    23632470            if ( $jit ) {
    2364                 if ( empty( $args[0]['width'] ) && empty( $args[0]['flex-width'] ) )
     2471                if ( empty( $args[0]['width'] ) && empty( $args[0]['flex-width'] ) ) {
    23652472                    $args[0]['flex-width'] = true;
    2366                 if ( empty( $args[0]['height'] ) && empty( $args[0]['flex-height'] ) )
     2473                }
     2474                if ( empty( $args[0]['height'] ) && empty( $args[0]['flex-height'] ) ) {
    23672475                    $args[0]['flex-height'] = true;
     2476                }
    23682477            }
    23692478
    23702479            break;
    23712480
    2372         case 'custom-background' :
    2373             if ( ! is_array( $args ) )
     2481        case 'custom-background':
     2482            if ( ! is_array( $args ) ) {
    23742483                $args = array( 0 => array() );
     2484            }
    23752485
    23762486            $defaults = array(
     
    23922502
    23932503            // Merge in data from previous add_theme_support() calls. The first value registered wins.
    2394             if ( isset( $_wp_theme_features['custom-background'] ) )
     2504            if ( isset( $_wp_theme_features['custom-background'] ) ) {
    23952505                $args[0] = wp_parse_args( $_wp_theme_features['custom-background'][0], $args[0] );
    2396 
    2397             if ( $jit )
     2506            }
     2507
     2508            if ( $jit ) {
    23982509                $args[0] = wp_parse_args( $args[0], $defaults );
    2399 
    2400             if ( defined( 'BACKGROUND_COLOR' ) )
     2510            }
     2511
     2512            if ( defined( 'BACKGROUND_COLOR' ) ) {
    24012513                $args[0]['default-color'] = BACKGROUND_COLOR;
    2402             elseif ( isset( $args[0]['default-color'] ) || $jit )
     2514            } elseif ( isset( $args[0]['default-color'] ) || $jit ) {
    24032515                define( 'BACKGROUND_COLOR', $args[0]['default-color'] );
    2404 
    2405             if ( defined( 'BACKGROUND_IMAGE' ) )
     2516            }
     2517
     2518            if ( defined( 'BACKGROUND_IMAGE' ) ) {
    24062519                $args[0]['default-image'] = BACKGROUND_IMAGE;
    2407             elseif ( isset( $args[0]['default-image'] ) || $jit )
     2520            } elseif ( isset( $args[0]['default-image'] ) || $jit ) {
    24082521                define( 'BACKGROUND_IMAGE', $args[0]['default-image'] );
     2522            }
    24092523
    24102524            break;
    24112525
    24122526        // Ensure that 'title-tag' is accessible in the admin.
    2413         case 'title-tag' :
     2527        case 'title-tag':
    24142528            // Can be called in functions.php but must happen before wp_loaded, i.e. not in header.php.
    24152529            if ( did_action( 'wp_loaded' ) ) {
    24162530                /* translators: 1: Theme support 2: hook name */
    2417                 _doing_it_wrong( "add_theme_support( 'title-tag' )", sprintf( __( 'Theme support for %1$s should be registered before the %2$s hook.' ),
    2418                     '<code>title-tag</code>', '<code>wp_loaded</code>' ), '4.1.0' );
     2531                _doing_it_wrong(
     2532                    "add_theme_support( 'title-tag' )", sprintf(
     2533                        __( 'Theme support for %1$s should be registered before the %2$s hook.' ),
     2534                        '<code>title-tag</code>', '<code>wp_loaded</code>'
     2535                    ), '4.1.0'
     2536                );
    24192537
    24202538                return false;
     
    24422560
    24432561        $args = get_theme_support( 'custom-header' );
    2444         if ( $args[0]['wp-head-callback'] )
     2562        if ( $args[0]['wp-head-callback'] ) {
    24452563            add_action( 'wp_head', $args[0]['wp-head-callback'] );
     2564        }
    24462565
    24472566        if ( is_admin() ) {
     
    25012620function get_theme_support( $feature ) {
    25022621    global $_wp_theme_features;
    2503     if ( ! isset( $_wp_theme_features[ $feature ] ) )
     2622    if ( ! isset( $_wp_theme_features[ $feature ] ) ) {
    25042623        return false;
    2505 
    2506     if ( func_num_args() <= 1 )
     2624    }
     2625
     2626    if ( func_num_args() <= 1 ) {
    25072627        return $_wp_theme_features[ $feature ];
     2628    }
    25082629
    25092630    $args = array_slice( func_get_args(), 1 );
    25102631    switch ( $feature ) {
    2511         case 'custom-logo' :
    2512         case 'custom-header' :
    2513         case 'custom-background' :
    2514             if ( isset( $_wp_theme_features[ $feature ][0][ $args[0] ] ) )
     2632        case 'custom-logo':
     2633        case 'custom-header':
     2634        case 'custom-background':
     2635            if ( isset( $_wp_theme_features[ $feature ][0][ $args[0] ] ) ) {
    25152636                return $_wp_theme_features[ $feature ][0][ $args[0] ];
     2637            }
    25162638            return false;
    25172639
    2518         default :
     2640        default:
    25192641            return $_wp_theme_features[ $feature ];
    25202642    }
     
    25342656function remove_theme_support( $feature ) {
    25352657    // Blacklist: for internal registrations not used directly by themes.
    2536     if ( in_array( $feature, array( 'editor-style', 'widgets', 'menus' ) ) )
     2658    if ( in_array( $feature, array( 'editor-style', 'widgets', 'menus' ) ) ) {
    25372659        return false;
     2660    }
    25382661
    25392662    return _remove_theme_support( $feature );
     
    25562679
    25572680    switch ( $feature ) {
    2558         case 'custom-header-uploads' :
    2559             if ( ! isset( $_wp_theme_features['custom-header'] ) )
     2681        case 'custom-header-uploads':
     2682            if ( ! isset( $_wp_theme_features['custom-header'] ) ) {
    25602683                return false;
     2684            }
    25612685            add_theme_support( 'custom-header', array( 'uploads' => false ) );
    25622686            return; // Do not continue - custom-header-uploads no longer exists.
    25632687    }
    25642688
    2565     if ( ! isset( $_wp_theme_features[ $feature ] ) )
     2689    if ( ! isset( $_wp_theme_features[ $feature ] ) ) {
    25662690        return false;
     2691    }
    25672692
    25682693    switch ( $feature ) {
    2569         case 'custom-header' :
    2570             if ( ! did_action( 'wp_loaded' ) )
     2694        case 'custom-header':
     2695            if ( ! did_action( 'wp_loaded' ) ) {
    25712696                break;
     2697            }
    25722698            $support = get_theme_support( 'custom-header' );
    25732699            if ( isset( $support[0]['wp-head-callback'] ) ) {
     
    25802706            break;
    25812707
    2582         case 'custom-background' :
    2583             if ( ! did_action( 'wp_loaded' ) )
     2708        case 'custom-background':
     2709            if ( ! did_action( 'wp_loaded' ) ) {
    25842710                break;
     2711            }
    25852712            $support = get_theme_support( 'custom-background' );
    25862713            remove_action( 'wp_head', $support[0]['wp-head-callback'] );
     
    26072734    global $_wp_theme_features;
    26082735
    2609     if ( 'custom-header-uploads' == $feature )
     2736    if ( 'custom-header-uploads' == $feature ) {
    26102737        return current_theme_supports( 'custom-header', 'uploads' );
    2611 
    2612     if ( !isset( $_wp_theme_features[$feature] ) )
     2738    }
     2739
     2740    if ( ! isset( $_wp_theme_features[ $feature ] ) ) {
    26132741        return false;
     2742    }
    26142743
    26152744    // If no args passed then no extra checks need be performed
    2616     if ( func_num_args() <= 1 )
     2745    if ( func_num_args() <= 1 ) {
    26172746        return true;
     2747    }
    26182748
    26192749    $args = array_slice( func_get_args(), 1 );
     
    26242754            // an array of types to add_theme_support(). If no array was passed, then
    26252755            // any type is accepted
    2626             if ( true === $_wp_theme_features[$feature] )  // Registered for all types
     2756            if ( true === $_wp_theme_features[ $feature ] ) {  // Registered for all types
    26272757                return true;
     2758            }
    26282759            $content_type = $args[0];
    2629             return in_array( $content_type, $_wp_theme_features[$feature][0] );
     2760            return in_array( $content_type, $_wp_theme_features[ $feature ][0] );
    26302761
    26312762        case 'html5':
     
    26372768
    26382769            $type = $args[0];
    2639             return in_array( $type, $_wp_theme_features[$feature][0] );
     2770            return in_array( $type, $_wp_theme_features[ $feature ][0] );
    26402771
    26412772        case 'custom-logo':
     
    26602791     * @param string $feature The theme feature.
    26612792     */
    2662     return apply_filters( "current_theme_supports-{$feature}", true, $args, $_wp_theme_features[$feature] );
     2793    return apply_filters( "current_theme_supports-{$feature}", true, $args, $_wp_theme_features[ $feature ] );
    26632794}
    26642795
     
    26742805function require_if_theme_supports( $feature, $include ) {
    26752806    if ( current_theme_supports( $feature ) ) {
    2676         require ( $include );
     2807        require( $include );
    26772808        return true;
    26782809    }
     
    27732904
    27742905    $is_customize_admin_page = ( is_admin() && 'customize.php' == basename( $_SERVER['PHP_SELF'] ) );
    2775     $should_include = (
     2906    $should_include          = (
    27762907        $is_customize_admin_page
    27772908        ||
     
    27902921     * the values should contain any characters needing slashes anyway.
    27912922     */
    2792     $keys = array( 'changeset_uuid', 'customize_changeset_uuid', 'customize_theme', 'theme', 'customize_messenger_channel', 'customize_autosaved' );
     2923    $keys       = array( 'changeset_uuid', 'customize_changeset_uuid', 'customize_theme', 'theme', 'customize_messenger_channel', 'customize_autosaved' );
    27932924    $input_vars = array_merge(
    27942925        wp_array_slice_assoc( $_GET, $keys ),
     
    27962927    );
    27972928
    2798     $theme = null;
    2799     $changeset_uuid = false; // Value false indicates UUID should be determined after_setup_theme to either re-use existing saved changeset or else generate a new UUID if none exists.
     2929    $theme             = null;
     2930    $changeset_uuid    = false; // Value false indicates UUID should be determined after_setup_theme to either re-use existing saved changeset or else generate a new UUID if none exists.
    28002931    $messenger_channel = null;
    2801     $autosaved = null;
    2802     $branching = false; // Set initially fo false since defaults to true for back-compat; can be overridden via the customize_changeset_branching filter.
     2932    $autosaved         = null;
     2933    $branching         = false; // Set initially fo false since defaults to true for back-compat; can be overridden via the customize_changeset_branching filter.
    28032934
    28042935    if ( $is_customize_admin_page && isset( $input_vars['changeset_uuid'] ) ) {
     
    28372968        'customize_save' === wp_unslash( $_REQUEST['action'] )
    28382969    );
    2839     $settings_previewed = ! $is_customize_save_action;
     2970    $settings_previewed       = ! $is_customize_save_action;
    28402971
    28412972    require_once ABSPATH . WPINC . '/class-wp-customize-manager.php';
     
    28723003    if ( empty( $wp_customize ) ) {
    28733004        require_once ABSPATH . WPINC . '/class-wp-customize-manager.php';
    2874         $wp_customize = new WP_Customize_Manager( array(
    2875             'changeset_uuid' => $changeset_post->post_name,
    2876             'settings_previewed' => false,
    2877         ) );
     3005        $wp_customize = new WP_Customize_Manager(
     3006            array(
     3007                'changeset_uuid'     => $changeset_post->post_name,
     3008                'settings_previewed' => false,
     3009            )
     3010        );
    28783011    }
    28793012
     
    28993032        do_action( 'customize_register', $wp_customize );
    29003033    }
    2901     $wp_customize->_publish_changeset_values( $changeset_post->ID ) ;
     3034    $wp_customize->_publish_changeset_values( $changeset_post->ID );
    29023035
    29033036    /*
     
    29473080    $admin_origin = parse_url( admin_url() );
    29483081    $home_origin  = parse_url( home_url() );
    2949     $cross_domain = ( strtolower( $admin_origin[ 'host' ] ) != strtolower( $home_origin[ 'host' ] ) );
     3082    $cross_domain = ( strtolower( $admin_origin['host'] ) != strtolower( $home_origin['host'] ) );
    29503083
    29513084    $browser = array(
     
    29673100
    29683101    $wp_scripts = wp_scripts();
    2969     $data = $wp_scripts->get_data( 'customize-loader', 'data' );
    2970     if ( $data )
     3102    $data       = $wp_scripts->get_data( 'customize-loader', 'data' );
     3103    if ( $data ) {
    29713104        $script = "$data\n$script";
     3105    }
    29723106
    29733107    $wp_scripts->add_data( 'customize-loader', 'data', $script );
     
    29803114 *
    29813115 * @param string $stylesheet Optional. Theme to customize. Defaults to current theme.
    2982  *                           The theme's stylesheet will be urlencoded if necessary.
     3116 *                           The theme's stylesheet will be urlencoded if necessary.
    29833117 * @return string
    29843118 */
    29853119function wp_customize_url( $stylesheet = null ) {
    29863120    $url = admin_url( 'customize.php' );
    2987     if ( $stylesheet )
     3121    if ( $stylesheet ) {
    29883122        $url .= '?theme=' . urlencode( $stylesheet );
     3123    }
    29893124    return esc_url( $url );
    29903125}
     
    30093144    $admin_origin = parse_url( admin_url() );
    30103145    $home_origin  = parse_url( home_url() );
    3011     $cross_domain = ( strtolower( $admin_origin[ 'host' ] ) != strtolower( $home_origin[ 'host' ] ) );
     3146    $cross_domain = ( strtolower( $admin_origin['host'] ) != strtolower( $home_origin['host'] ) );
    30123147
    30133148    ?>
Note: See TracChangeset for help on using the changeset viewer.