diff -r c7c34916027a -r 177826044cd9 wp/wp-includes/theme.php --- a/wp/wp-includes/theme.php Mon Oct 14 18:06:33 2019 +0200 +++ b/wp/wp-includes/theme.php Mon Oct 14 18:28:13 2019 +0200 @@ -17,21 +17,28 @@ * @global array $wp_theme_directories * @staticvar array $_themes * - * @param array $args The search arguments. Optional. - * - errors mixed True to return themes with errors, false to return themes without errors, null - * to return all themes. Defaults to false. - * - allowed mixed (Multisite) True to return only allowed themes for a site. False to return only - * disallowed themes for a site. 'site' to return only site-allowed themes. 'network' - * to return only network-allowed themes. Null to return all themes. Defaults to null. - * - blog_id int (Multisite) The blog ID used to calculate which themes are allowed. Defaults to 0, - * synonymous for the current blog. - * @return array Array of WP_Theme objects. + * @param array $args { + * Optional. The search arguments. + * + * @type mixed $errors True to return themes with errors, false to return themes without errors, null to return all themes. + * Defaults to false. + * @type mixed $allowed (Multisite) True to return only allowed themes for a site. False to return only disallowed themes for a site. + * 'site' to return only site-allowed themes. 'network' to return only network-allowed themes. + * Null to return all themes. Defaults to null. + * @type int $blog_id (Multisite) The blog ID used to calculate which themes are allowed. + * Defaults to 0, synonymous for the current blog. + * } + * @return WP_Theme[] Array of WP_Theme objects. */ function wp_get_themes( $args = array() ) { global $wp_theme_directories; - $defaults = array( 'errors' => false, 'allowed' => null, 'blog_id' => 0 ); - $args = wp_parse_args( $args, $defaults ); + $defaults = array( + 'errors' => false, + 'allowed' => null, + 'blog_id' => 0, + ); + $args = wp_parse_args( $args, $defaults ); $theme_directories = search_theme_directories(); @@ -41,41 +48,46 @@ $current_theme = get_stylesheet(); if ( isset( $theme_directories[ $current_theme ] ) ) { $root_of_current_theme = get_raw_theme_root( $current_theme ); - if ( ! in_array( $root_of_current_theme, $wp_theme_directories ) ) + if ( ! in_array( $root_of_current_theme, $wp_theme_directories ) ) { $root_of_current_theme = WP_CONTENT_DIR . $root_of_current_theme; + } $theme_directories[ $current_theme ]['theme_root'] = $root_of_current_theme; } } - if ( empty( $theme_directories ) ) + if ( empty( $theme_directories ) ) { return array(); + } if ( is_multisite() && null !== $args['allowed'] ) { $allowed = $args['allowed']; - if ( 'network' === $allowed ) + if ( 'network' === $allowed ) { $theme_directories = array_intersect_key( $theme_directories, WP_Theme::get_allowed_on_network() ); - elseif ( 'site' === $allowed ) + } elseif ( 'site' === $allowed ) { $theme_directories = array_intersect_key( $theme_directories, WP_Theme::get_allowed_on_site( $args['blog_id'] ) ); - elseif ( $allowed ) + } elseif ( $allowed ) { $theme_directories = array_intersect_key( $theme_directories, WP_Theme::get_allowed( $args['blog_id'] ) ); - else + } else { $theme_directories = array_diff_key( $theme_directories, WP_Theme::get_allowed( $args['blog_id'] ) ); + } } - $themes = array(); + $themes = array(); static $_themes = array(); foreach ( $theme_directories as $theme => $theme_root ) { - if ( isset( $_themes[ $theme_root['theme_root'] . '/' . $theme ] ) ) + if ( isset( $_themes[ $theme_root['theme_root'] . '/' . $theme ] ) ) { $themes[ $theme ] = $_themes[ $theme_root['theme_root'] . '/' . $theme ]; - else + } else { $themes[ $theme ] = $_themes[ $theme_root['theme_root'] . '/' . $theme ] = new WP_Theme( $theme, $theme_root['theme_root'] ); + } } if ( null !== $args['errors'] ) { foreach ( $themes as $theme => $wp_theme ) { - if ( $wp_theme->errors() != $args['errors'] ) + if ( $wp_theme->errors() != $args['errors'] ) { unset( $themes[ $theme ] ); + } } } @@ -91,21 +103,23 @@ * * @param string $stylesheet Directory name for the theme. Optional. Defaults to current theme. * @param string $theme_root Absolute path of the theme root to look in. Optional. If not specified, get_raw_theme_root() - * is used to calculate the theme root for the $stylesheet provided (or current theme). + * is used to calculate the theme root for the $stylesheet provided (or current theme). * @return WP_Theme Theme object. Be sure to check the object's exists() method if you need to confirm the theme's existence. */ function wp_get_theme( $stylesheet = null, $theme_root = null ) { global $wp_theme_directories; - if ( empty( $stylesheet ) ) + if ( empty( $stylesheet ) ) { $stylesheet = get_stylesheet(); + } if ( empty( $theme_root ) ) { $theme_root = get_raw_theme_root( $stylesheet ); - if ( false === $theme_root ) + if ( false === $theme_root ) { $theme_root = WP_CONTENT_DIR . '/themes'; - elseif ( ! in_array( $theme_root, (array) $wp_theme_directories ) ) + } elseif ( ! in_array( $theme_root, (array) $wp_theme_directories ) ) { $theme_root = WP_CONTENT_DIR . $theme_root; + } } return new WP_Theme( $stylesheet, $theme_root ); @@ -118,11 +132,13 @@ * @param bool $clear_update_cache Whether to clear the Theme updates cache */ function wp_clean_themes_cache( $clear_update_cache = true ) { - if ( $clear_update_cache ) + if ( $clear_update_cache ) { delete_site_transient( 'update_themes' ); + } search_theme_directories( true ); - foreach ( wp_get_themes( array( 'errors' => null ) ) as $theme ) + foreach ( wp_get_themes( array( 'errors' => null ) ) as $theme ) { $theme->cache_delete(); + } } /** @@ -131,7 +147,7 @@ * @since 3.0.0 * * @return bool true if a child theme is in use, false otherwise. - **/ + */ function is_child_theme() { return ( TEMPLATEPATH !== STYLESHEETPATH ); } @@ -168,8 +184,8 @@ * @return string Path to current theme directory. */ function get_stylesheet_directory() { - $stylesheet = get_stylesheet(); - $theme_root = get_theme_root( $stylesheet ); + $stylesheet = get_stylesheet(); + $theme_root = get_theme_root( $stylesheet ); $stylesheet_dir = "$theme_root/$stylesheet"; /** @@ -192,8 +208,8 @@ * @return string */ function get_stylesheet_directory_uri() { - $stylesheet = str_replace( '%2F', '/', rawurlencode( get_stylesheet() ) ); - $theme_root_uri = get_theme_root_uri( $stylesheet ); + $stylesheet = str_replace( '%2F', '/', rawurlencode( get_stylesheet() ) ); + $theme_root_uri = get_theme_root_uri( $stylesheet ); $stylesheet_dir_uri = "$theme_root_uri/$stylesheet"; /** @@ -220,7 +236,7 @@ */ function get_stylesheet_uri() { $stylesheet_dir_uri = get_stylesheet_directory_uri(); - $stylesheet_uri = $stylesheet_dir_uri . '/style.css'; + $stylesheet_uri = $stylesheet_dir_uri . '/style.css'; /** * Filters the URI of the current theme stylesheet. * @@ -256,14 +272,15 @@ function get_locale_stylesheet_uri() { global $wp_locale; $stylesheet_dir_uri = get_stylesheet_directory_uri(); - $dir = get_stylesheet_directory(); - $locale = get_locale(); - if ( file_exists("$dir/$locale.css") ) + $dir = get_stylesheet_directory(); + $locale = get_locale(); + if ( file_exists( "$dir/$locale.css" ) ) { $stylesheet_uri = "$stylesheet_dir_uri/$locale.css"; - elseif ( !empty($wp_locale->text_direction) && file_exists("$dir/{$wp_locale->text_direction}.css") ) + } elseif ( ! empty( $wp_locale->text_direction ) && file_exists( "$dir/{$wp_locale->text_direction}.css" ) ) { $stylesheet_uri = "$stylesheet_dir_uri/{$wp_locale->text_direction}.css"; - else + } else { $stylesheet_uri = ''; + } /** * Filters the localized stylesheet URI. * @@ -301,8 +318,8 @@ * @return string Template directory path. */ function get_template_directory() { - $template = get_template(); - $theme_root = get_theme_root( $template ); + $template = get_template(); + $theme_root = get_theme_root( $template ); $template_dir = "$theme_root/$template"; /** @@ -325,8 +342,8 @@ * @return string Template directory URI. */ function get_template_directory_uri() { - $template = str_replace( '%2F', '/', rawurlencode( get_template() ) ); - $theme_root_uri = get_theme_root_uri( $template ); + $template = str_replace( '%2F', '/', rawurlencode( get_template() ) ); + $theme_root_uri = get_theme_root_uri( $template ); $template_dir_uri = "$theme_root_uri/$template"; /** @@ -414,11 +431,13 @@ global $wp_theme_directories; static $found_themes = null; - if ( empty( $wp_theme_directories ) ) + if ( empty( $wp_theme_directories ) ) { return false; - - if ( ! $force && isset( $found_themes ) ) + } + + if ( ! $force && isset( $found_themes ) ) { return $found_themes; + } $found_themes = array(); @@ -429,10 +448,11 @@ // We always want to return absolute, but we need to cache relative // to use in get_theme_root(). foreach ( $wp_theme_directories as $theme_root ) { - if ( 0 === strpos( $theme_root, WP_CONTENT_DIR ) ) + if ( 0 === strpos( $theme_root, WP_CONTENT_DIR ) ) { $relative_theme_roots[ str_replace( WP_CONTENT_DIR, '', $theme_root ) ] = $theme_root; - else + } else { $relative_theme_roots[ $theme_root ] = $theme_root; + } } /** @@ -448,8 +468,9 @@ if ( is_array( $cached_roots ) ) { foreach ( $cached_roots as $theme_dir => $theme_root ) { // A cached theme root is no longer around, so skip it. - if ( ! isset( $relative_theme_roots[ $theme_root ] ) ) + if ( ! isset( $relative_theme_roots[ $theme_root ] ) ) { continue; + } $found_themes[ $theme_dir ] = array( 'theme_file' => $theme_dir . '/style.css', 'theme_root' => $relative_theme_roots[ $theme_root ], // Convert relative to absolute. @@ -457,8 +478,9 @@ } return $found_themes; } - if ( ! is_int( $cache_expiration ) ) + if ( ! is_int( $cache_expiration ) ) { $cache_expiration = 1800; // half hour + } } else { $cache_expiration = 1800; // half hour } @@ -473,8 +495,9 @@ continue; } foreach ( $dirs as $dir ) { - if ( ! is_dir( $theme_root . '/' . $dir ) || $dir[0] == '.' || $dir == 'CVS' ) + if ( ! is_dir( $theme_root . '/' . $dir ) || $dir[0] == '.' || $dir == 'CVS' ) { continue; + } if ( file_exists( $theme_root . '/' . $dir . '/style.css' ) ) { // wp-content/themes/a-single-theme // wp-content/themes is $theme_root, a-single-theme is $dir @@ -492,38 +515,42 @@ continue; } foreach ( $sub_dirs as $sub_dir ) { - if ( ! is_dir( $theme_root . '/' . $dir . '/' . $sub_dir ) || $dir[0] == '.' || $dir == 'CVS' ) + if ( ! is_dir( $theme_root . '/' . $dir . '/' . $sub_dir ) || $dir[0] == '.' || $dir == 'CVS' ) { continue; - if ( ! file_exists( $theme_root . '/' . $dir . '/' . $sub_dir . '/style.css' ) ) + } + if ( ! file_exists( $theme_root . '/' . $dir . '/' . $sub_dir . '/style.css' ) ) { continue; + } $found_themes[ $dir . '/' . $sub_dir ] = array( 'theme_file' => $dir . '/' . $sub_dir . '/style.css', 'theme_root' => $theme_root, ); - $found_theme = true; + $found_theme = true; } // Never mind the above, it's just a theme missing a style.css. // Return it; WP_Theme will catch the error. - if ( ! $found_theme ) + if ( ! $found_theme ) { $found_themes[ $dir ] = array( 'theme_file' => $dir . '/style.css', 'theme_root' => $theme_root, ); + } } } } asort( $found_themes ); - $theme_roots = array(); + $theme_roots = array(); $relative_theme_roots = array_flip( $relative_theme_roots ); foreach ( $found_themes as $theme_dir => $theme_data ) { $theme_roots[ $theme_dir ] = $relative_theme_roots[ $theme_data['theme_root'] ]; // Convert absolute to relative. } - if ( $theme_roots != get_site_transient( 'theme_roots' ) ) + if ( $theme_roots != get_site_transient( 'theme_roots' ) ) { set_site_transient( 'theme_roots', $theme_roots, $cache_expiration ); + } return $found_themes; } @@ -546,8 +573,9 @@ if ( $stylesheet_or_template && $theme_root = get_raw_theme_root( $stylesheet_or_template ) ) { // Always prepend WP_CONTENT_DIR unless the root currently registered as a theme directory. // This gives relative theme roots the benefit of the doubt when things go haywire. - if ( ! in_array( $theme_root, (array) $wp_theme_directories ) ) + if ( ! in_array( $theme_root, (array) $wp_theme_directories ) ) { $theme_root = WP_CONTENT_DIR . $theme_root; + } } else { $theme_root = WP_CONTENT_DIR . '/themes'; } @@ -572,28 +600,30 @@ * @global array $wp_theme_directories * * @param string $stylesheet_or_template Optional. The stylesheet or template name of the theme. - * Default is to leverage the main theme root. + * Default is to leverage the main theme root. * @param string $theme_root Optional. The theme root for which calculations will be based, preventing - * the need for a get_raw_theme_root() call. + * the need for a get_raw_theme_root() call. * @return string Themes URI. */ function get_theme_root_uri( $stylesheet_or_template = false, $theme_root = false ) { global $wp_theme_directories; - if ( $stylesheet_or_template && ! $theme_root ) + if ( $stylesheet_or_template && ! $theme_root ) { $theme_root = get_raw_theme_root( $stylesheet_or_template ); + } if ( $stylesheet_or_template && $theme_root ) { if ( in_array( $theme_root, (array) $wp_theme_directories ) ) { // Absolute path. Make an educated guess. YMMV -- but note the filter below. - if ( 0 === strpos( $theme_root, WP_CONTENT_DIR ) ) + if ( 0 === strpos( $theme_root, WP_CONTENT_DIR ) ) { $theme_root_uri = content_url( str_replace( WP_CONTENT_DIR, '', $theme_root ) ); - elseif ( 0 === strpos( $theme_root, ABSPATH ) ) + } elseif ( 0 === strpos( $theme_root, ABSPATH ) ) { $theme_root_uri = site_url( str_replace( ABSPATH, '', $theme_root ) ); - elseif ( 0 === strpos( $theme_root, WP_PLUGIN_DIR ) || 0 === strpos( $theme_root, WPMU_PLUGIN_DIR ) ) + } elseif ( 0 === strpos( $theme_root, WP_PLUGIN_DIR ) || 0 === strpos( $theme_root, WPMU_PLUGIN_DIR ) ) { $theme_root_uri = plugins_url( basename( $theme_root ), $theme_root ); - else + } else { $theme_root_uri = $theme_root; + } } else { $theme_root_uri = content_url( $theme_root ); } @@ -636,16 +666,18 @@ // If requesting the root for the current theme, consult options to avoid calling get_theme_roots() if ( ! $skip_cache ) { - if ( get_option('stylesheet') == $stylesheet_or_template ) - $theme_root = get_option('stylesheet_root'); - elseif ( get_option('template') == $stylesheet_or_template ) - $theme_root = get_option('template_root'); + if ( get_option( 'stylesheet' ) == $stylesheet_or_template ) { + $theme_root = get_option( 'stylesheet_root' ); + } elseif ( get_option( 'template' ) == $stylesheet_or_template ) { + $theme_root = get_option( 'template_root' ); + } } - if ( empty($theme_root) ) { + if ( empty( $theme_root ) ) { $theme_roots = get_theme_roots(); - if ( !empty($theme_roots[$stylesheet_or_template]) ) - $theme_root = $theme_roots[$stylesheet_or_template]; + if ( ! empty( $theme_roots[ $stylesheet_or_template ] ) ) { + $theme_root = $theme_roots[ $stylesheet_or_template ]; + } } return $theme_root; @@ -658,8 +690,9 @@ */ function locale_stylesheet() { $stylesheet = get_locale_stylesheet_uri(); - if ( empty($stylesheet) ) + if ( empty( $stylesheet ) ) { return; + } echo ''; } @@ -691,7 +724,13 @@ } if ( is_array( $_sidebars_widgets ) ) { - set_theme_mod( 'sidebars_widgets', array( 'time' => time(), 'data' => $_sidebars_widgets ) ); + set_theme_mod( + 'sidebars_widgets', + array( + 'time' => time(), + 'data' => $_sidebars_widgets, + ) + ); } $nav_menu_locations = get_theme_mod( 'nav_menu_locations' ); @@ -705,6 +744,12 @@ $new_theme = wp_get_theme( $stylesheet ); $template = $new_theme->get_template(); + if ( wp_is_recovery_mode() ) { + $paused_themes = wp_paused_themes(); + $paused_themes->delete( $old_theme->get_stylesheet() ); + $paused_themes->delete( $old_theme->get_template() ); + } + update_option( 'template', $template ); update_option( 'stylesheet', $stylesheet ); @@ -716,7 +761,7 @@ delete_option( 'stylesheet_root' ); } - $new_name = $new_theme->get('Name'); + $new_name = $new_theme->get( 'Name' ); update_option( 'current_theme', $new_name ); @@ -776,8 +821,9 @@ * * @param bool $validate Whether to validate the current theme. Default true. */ - if ( wp_installing() || ! apply_filters( 'validate_current_theme', true ) ) + if ( wp_installing() || ! apply_filters( 'validate_current_theme', true ) ) { return true; + } if ( ! file_exists( get_template_directory() . '/index.php' ) ) { // Invalid. @@ -823,11 +869,12 @@ */ function get_theme_mods() { $theme_slug = get_option( 'stylesheet' ); - $mods = get_option( "theme_mods_$theme_slug" ); + $mods = get_option( "theme_mods_$theme_slug" ); if ( false === $mods ) { $theme_name = get_option( 'current_theme' ); - if ( false === $theme_name ) - $theme_name = wp_get_theme()->get('Name'); + if ( false === $theme_name ) { + $theme_name = wp_get_theme()->get( 'Name' ); + } $mods = get_option( "mods_$theme_name" ); // Deprecated location. if ( is_admin() && false !== $mods ) { update_option( "theme_mods_$theme_slug", $mods ); @@ -849,12 +896,12 @@ * * @param string $name Theme modification name. * @param bool|string $default - * @return string + * @return mixed */ function get_theme_mod( $name, $default = false ) { $mods = get_theme_mods(); - if ( isset( $mods[$name] ) ) { + if ( isset( $mods[ $name ] ) ) { /** * Filters the theme modification, or 'theme_mod', value. * @@ -867,11 +914,12 @@ * * @param string $current_mod The value of the current theme modification. */ - return apply_filters( "theme_mod_{$name}", $mods[$name] ); + return apply_filters( "theme_mod_{$name}", $mods[ $name ] ); } - if ( is_string( $default ) ) + if ( is_string( $default ) ) { $default = sprintf( $default, get_template_directory_uri(), get_stylesheet_directory_uri() ); + } /** This filter is documented in wp-includes/theme.php */ return apply_filters( "theme_mod_{$name}", $default ); @@ -886,7 +934,7 @@ * @param mixed $value Theme modification value. */ function set_theme_mod( $name, $value ) { - $mods = get_theme_mods(); + $mods = get_theme_mods(); $old_value = isset( $mods[ $name ] ) ? $mods[ $name ] : false; /** @@ -920,8 +968,9 @@ function remove_theme_mod( $name ) { $mods = get_theme_mods(); - if ( ! isset( $mods[ $name ] ) ) + if ( ! isset( $mods[ $name ] ) ) { return; + } unset( $mods[ $name ] ); @@ -943,8 +992,9 @@ // Old style. $theme_name = get_option( 'current_theme' ); - if ( false === $theme_name ) - $theme_name = wp_get_theme()->get('Name'); + if ( false === $theme_name ) { + $theme_name = wp_get_theme()->get( 'Name' ); + } delete_option( 'mods_' . $theme_name ); } @@ -956,7 +1006,7 @@ * @return string Header text color in 3- or 6-digit hexadecimal form (minus the hash symbol). */ function get_header_textcolor() { - return get_theme_mod('header_textcolor', get_theme_support( 'custom-header', 'default-text-color' ) ); + return get_theme_mod( 'header_textcolor', get_theme_support( 'custom-header', 'default-text-color' ) ); } /** @@ -976,8 +1026,9 @@ * @return bool */ function display_header_text() { - if ( ! current_theme_supports( 'custom-header', 'header-text' ) ) + if ( ! current_theme_supports( 'custom-header', 'header-text' ) ) { return false; + } $text_color = get_theme_mod( 'header_textcolor', get_theme_support( 'custom-header', 'default-text-color' ) ); return 'blank' !== $text_color; @@ -1006,11 +1057,13 @@ function get_header_image() { $url = get_theme_mod( 'header_image', get_theme_support( 'custom-header', 'default-image' ) ); - if ( 'remove-header' == $url ) + if ( 'remove-header' == $url ) { return false; - - if ( is_random_header_image() ) + } + + if ( is_random_header_image() ) { $url = get_random_header_image(); + } return esc_url_raw( set_url_scheme( $url ) ); } @@ -1025,23 +1078,23 @@ * @return string HTML image element markup or empty string on failure. */ function get_header_image_tag( $attr = array() ) { - $header = get_custom_header(); + $header = get_custom_header(); $header->url = get_header_image(); if ( ! $header->url ) { return ''; } - $width = absint( $header->width ); + $width = absint( $header->width ); $height = absint( $header->height ); $attr = wp_parse_args( $attr, array( - 'src' => $header->url, - 'width' => $width, + 'src' => $header->url, + 'width' => $width, 'height' => $height, - 'alt' => get_bloginfo( 'name' ), + 'alt' => get_bloginfo( 'name' ), ) ); @@ -1052,11 +1105,11 @@ if ( is_array( $image_meta ) ) { $srcset = wp_calculate_image_srcset( $size_array, $header->url, $image_meta, $header->attachment_id ); - $sizes = ! empty( $attr['sizes'] ) ? $attr['sizes'] : wp_calculate_image_sizes( $size_array, $header->url, $image_meta, $header->attachment_id ); + $sizes = ! empty( $attr['sizes'] ) ? $attr['sizes'] : wp_calculate_image_sizes( $size_array, $header->url, $image_meta, $header->attachment_id ); if ( $srcset && $sizes ) { $attr['srcset'] = $srcset; - $attr['sizes'] = $sizes; + $attr['sizes'] = $sizes; } } } @@ -1111,26 +1164,28 @@ if ( empty( $_wp_random_header ) ) { global $_wp_default_headers; $header_image_mod = get_theme_mod( 'header_image', '' ); - $headers = array(); - - if ( 'random-uploaded-image' == $header_image_mod ) + $headers = array(); + + if ( 'random-uploaded-image' == $header_image_mod ) { $headers = get_uploaded_header_images(); - elseif ( ! empty( $_wp_default_headers ) ) { + } elseif ( ! empty( $_wp_default_headers ) ) { if ( 'random-default-image' == $header_image_mod ) { $headers = $_wp_default_headers; } else { - if ( current_theme_supports( 'custom-header', 'random-default' ) ) + if ( current_theme_supports( 'custom-header', 'random-default' ) ) { $headers = $_wp_default_headers; + } } } - if ( empty( $headers ) ) + if ( empty( $headers ) ) { return new stdClass; + } $_wp_random_header = (object) $headers[ array_rand( $headers ) ]; - $_wp_random_header->url = sprintf( $_wp_random_header->url, get_template_directory_uri(), get_stylesheet_directory_uri() ); - $_wp_random_header->thumbnail_url = sprintf( $_wp_random_header->thumbnail_url, get_template_directory_uri(), get_stylesheet_directory_uri() ); + $_wp_random_header->url = sprintf( $_wp_random_header->url, get_template_directory_uri(), get_stylesheet_directory_uri() ); + $_wp_random_header->thumbnail_url = sprintf( $_wp_random_header->thumbnail_url, get_template_directory_uri(), get_stylesheet_directory_uri() ); } return $_wp_random_header; } @@ -1144,8 +1199,9 @@ */ function get_random_header_image() { $random_image = _get_random_header_data(); - if ( empty( $random_image->url ) ) + if ( empty( $random_image->url ) ) { return ''; + } return $random_image->url; } @@ -1165,13 +1221,15 @@ $header_image_mod = get_theme_mod( 'header_image', get_theme_support( 'custom-header', 'default-image' ) ); if ( 'any' == $type ) { - if ( 'random-default-image' == $header_image_mod || 'random-uploaded-image' == $header_image_mod || ( '' != get_random_header_image() && empty( $header_image_mod ) ) ) + if ( 'random-default-image' == $header_image_mod || 'random-uploaded-image' == $header_image_mod || ( '' != get_random_header_image() && empty( $header_image_mod ) ) ) { return true; + } } else { - if ( "random-$type-image" == $header_image_mod ) + if ( "random-$type-image" == $header_image_mod ) { return true; - elseif ( 'default' == $type && empty( $header_image_mod ) && '' != get_random_header_image() ) + } elseif ( 'default' == $type && empty( $header_image_mod ) && '' != get_random_header_image() ) { return true; + } } return false; @@ -1200,27 +1258,38 @@ $header_images = array(); // @todo caching - $headers = get_posts( array( 'post_type' => 'attachment', 'meta_key' => '_wp_attachment_is_custom_header', 'meta_value' => get_option('stylesheet'), 'orderby' => 'none', 'nopaging' => true ) ); - - if ( empty( $headers ) ) + $headers = get_posts( + array( + 'post_type' => 'attachment', + 'meta_key' => '_wp_attachment_is_custom_header', + 'meta_value' => get_option( 'stylesheet' ), + 'orderby' => 'none', + 'nopaging' => true, + ) + ); + + if ( empty( $headers ) ) { return array(); + } foreach ( (array) $headers as $header ) { - $url = esc_url_raw( wp_get_attachment_url( $header->ID ) ); - $header_data = wp_get_attachment_metadata( $header->ID ); + $url = esc_url_raw( wp_get_attachment_url( $header->ID ) ); + $header_data = wp_get_attachment_metadata( $header->ID ); $header_index = $header->ID; - $header_images[$header_index] = array(); - $header_images[$header_index]['attachment_id'] = $header->ID; - $header_images[$header_index]['url'] = $url; - $header_images[$header_index]['thumbnail_url'] = $url; - $header_images[$header_index]['alt_text'] = get_post_meta( $header->ID, '_wp_attachment_image_alt', true ); - $header_images[$header_index]['attachment_parent'] = isset( $header_data['attachment_parent'] ) ? $header_data['attachment_parent'] : ''; - - if ( isset( $header_data['width'] ) ) - $header_images[$header_index]['width'] = $header_data['width']; - if ( isset( $header_data['height'] ) ) - $header_images[$header_index]['height'] = $header_data['height']; + $header_images[ $header_index ] = array(); + $header_images[ $header_index ]['attachment_id'] = $header->ID; + $header_images[ $header_index ]['url'] = $url; + $header_images[ $header_index ]['thumbnail_url'] = $url; + $header_images[ $header_index ]['alt_text'] = get_post_meta( $header->ID, '_wp_attachment_image_alt', true ); + $header_images[ $header_index ]['attachment_parent'] = isset( $header_data['attachment_parent'] ) ? $header_data['attachment_parent'] : ''; + + if ( isset( $header_data['width'] ) ) { + $header_images[ $header_index ]['width'] = $header_data['width']; + } + if ( isset( $header_data['height'] ) ) { + $header_images[ $header_index ]['height'] = $header_data['height']; + } } return $header_images; @@ -1244,14 +1313,14 @@ $data = get_theme_mod( 'header_image_data' ); if ( ! $data && current_theme_supports( 'custom-header', 'default-image' ) ) { $directory_args = array( get_template_directory_uri(), get_stylesheet_directory_uri() ); - $data = array(); - $data['url'] = $data['thumbnail_url'] = vsprintf( get_theme_support( 'custom-header', 'default-image' ), $directory_args ); + $data = array(); + $data['url'] = $data['thumbnail_url'] = vsprintf( get_theme_support( 'custom-header', 'default-image' ), $directory_args ); if ( ! empty( $_wp_default_headers ) ) { foreach ( (array) $_wp_default_headers as $default_header ) { $url = vsprintf( $default_header['url'], $directory_args ); if ( $data['url'] == $url ) { - $data = $default_header; - $data['url'] = $url; + $data = $default_header; + $data['url'] = $url; $data['thumbnail_url'] = vsprintf( $data['thumbnail_url'], $directory_args ); break; } @@ -1335,7 +1404,7 @@ * @return string|false Header video URL or false if there is no video. */ function get_header_video_url() { - $id = absint( get_theme_mod( 'header_video' ) ); + $id = absint( get_theme_mod( 'header_video' ) ); $url = esc_url( get_theme_mod( 'external_header_video' ) ); if ( $id ) { @@ -1394,8 +1463,8 @@ 'l10n' => array( 'pause' => __( 'Pause' ), 'play' => __( 'Play' ), - 'pauseSpeak' => __( 'Video is paused.'), - 'playSpeak' => __( 'Video is playing.'), + 'pauseSpeak' => __( 'Video is paused.' ), + 'playSpeak' => __( 'Video is playing.' ), ), ); @@ -1405,6 +1474,13 @@ $settings['mimeType'] = $video_type['type']; } + /** + * Filters header video settings. + * + * @since 4.7.0 + * + * @param array $settings An array of header video settings. + */ return apply_filters( 'header_video_settings', $settings ); } @@ -1504,7 +1580,7 @@ * @return string */ function get_background_image() { - return get_theme_mod('background_image', get_theme_support( 'custom-background', 'default-image' ) ); + return get_theme_mod( 'background_image', get_theme_support( 'custom-background', 'default-image' ) ); } /** @@ -1524,7 +1600,7 @@ * @return string */ function get_background_color() { - return get_theme_mod('background_color', get_theme_support( 'custom-background', 'default-color' ) ); + return get_theme_mod( 'background_color', get_theme_support( 'custom-background', 'default-color' ) ); } /** @@ -1608,11 +1684,11 @@ $style .= $image . $position . $size . $repeat . $attachment; } -?> + ?> - + if ( $styles || is_customize_preview() ) : + ?> - post; + $post = $query->post; /* * Cache the lookup. See wp_update_custom_css_post(). * @todo This should get cleared if a custom_css post is added/removed. @@ -1674,7 +1752,7 @@ } } else { $query = new WP_Query( $custom_css_query_vars ); - $post = $query->post; + $post = $query->post; } return $post; @@ -1730,13 +1808,16 @@ * @return WP_Post|WP_Error Post on success, error on failure. */ function wp_update_custom_css_post( $css, $args = array() ) { - $args = wp_parse_args( $args, array( - 'preprocessed' => '', - 'stylesheet' => get_stylesheet(), - ) ); + $args = wp_parse_args( + $args, + array( + 'preprocessed' => '', + 'stylesheet' => get_stylesheet(), + ) + ); $data = array( - 'css' => $css, + 'css' => $css, 'preprocessed' => $args['preprocessed'], ); @@ -1776,11 +1857,11 @@ $data = apply_filters( 'update_custom_css_data', $data, array_merge( $args, compact( 'css' ) ) ); $post_data = array( - 'post_title' => $args['stylesheet'], - 'post_name' => sanitize_title( $args['stylesheet'] ), - 'post_type' => 'custom_css', - 'post_status' => 'publish', - 'post_content' => $data['css'], + 'post_title' => $args['stylesheet'], + 'post_name' => sanitize_title( $args['stylesheet'] ), + 'post_type' => 'custom_css', + 'post_status' => 'publish', + 'post_content' => $data['css'], 'post_content_filtered' => $data['preprocessed'], ); @@ -1788,7 +1869,7 @@ $post = wp_get_custom_css_post( $args['stylesheet'] ); if ( $post ) { $post_data['ID'] = $post->ID; - $r = wp_update_post( wp_slash( $post_data ), true ); + $r = wp_update_post( wp_slash( $post_data ), true ); } else { $r = wp_insert_post( wp_slash( $post_data ), true ); @@ -1830,20 +1911,21 @@ * @global array $editor_styles * * @param array|string $stylesheet Optional. Stylesheet name or array thereof, relative to theme root. - * Defaults to 'editor-style.css' + * Defaults to 'editor-style.css' */ function add_editor_style( $stylesheet = 'editor-style.css' ) { add_theme_support( 'editor-style' ); - if ( ! is_admin() ) + if ( ! is_admin() ) { return; + } global $editor_styles; $editor_styles = (array) $editor_styles; $stylesheet = (array) $stylesheet; if ( is_rtl() ) { - $rtl_stylesheet = str_replace('.css', '-rtl.css', $stylesheet[0]); - $stylesheet[] = $rtl_stylesheet; + $rtl_stylesheet = str_replace( '.css', '-rtl.css', $stylesheet[0] ); + $stylesheet[] = $rtl_stylesheet; } $editor_styles = array_merge( $editor_styles, $stylesheet ); @@ -1859,11 +1941,13 @@ * @return bool True on success, false if there were no stylesheets to remove. */ function remove_editor_styles() { - if ( ! current_theme_supports( 'editor-style' ) ) + if ( ! current_theme_supports( 'editor-style' ) ) { return false; + } _remove_theme_support( 'editor-style' ); - if ( is_admin() ) + if ( is_admin() ) { $GLOBALS['editor_styles'] = array(); + } return true; } @@ -1883,8 +1967,8 @@ $editor_styles = $GLOBALS['editor_styles']; $editor_styles = array_unique( array_filter( $editor_styles ) ); - $style_uri = get_stylesheet_directory_uri(); - $style_dir = get_stylesheet_directory(); + $style_uri = get_stylesheet_directory_uri(); + $style_dir = get_stylesheet_directory(); // Support externally referenced styles (like, say, fonts). foreach ( $editor_styles as $key => $file ) { @@ -1939,147 +2023,177 @@ } $core_content = array( - 'widgets' => array( - 'text_business_info' => array( 'text', array( - 'title' => _x( 'Find Us', 'Theme starter content' ), - 'text' => join( '', array( - '' . _x( 'Address', 'Theme starter content' ) . "\n", - _x( '123 Main Street', 'Theme starter content' ) . "\n" . _x( 'New York, NY 10001', 'Theme starter content' ) . "\n\n", - '' . _x( 'Hours', 'Theme starter content' ) . "\n", - _x( 'Monday—Friday: 9:00AM–5:00PM', 'Theme starter content' ) . "\n" . _x( 'Saturday & Sunday: 11:00AM–3:00PM', 'Theme starter content' ) - ) ), - 'filter' => true, - 'visual' => true, - ) ), - 'text_about' => array( 'text', array( - 'title' => _x( 'About This Site', 'Theme starter content' ), - 'text' => _x( 'This may be a good place to introduce yourself and your site or include some credits.', 'Theme starter content' ), - 'filter' => true, - 'visual' => true, - ) ), - 'archives' => array( 'archives', array( - 'title' => _x( 'Archives', 'Theme starter content' ), - ) ), - 'calendar' => array( 'calendar', array( - 'title' => _x( 'Calendar', 'Theme starter content' ), - ) ), - 'categories' => array( 'categories', array( - 'title' => _x( 'Categories', 'Theme starter content' ), - ) ), - 'meta' => array( 'meta', array( - 'title' => _x( 'Meta', 'Theme starter content' ), - ) ), - 'recent-comments' => array( 'recent-comments', array( - 'title' => _x( 'Recent Comments', 'Theme starter content' ), - ) ), - 'recent-posts' => array( 'recent-posts', array( - 'title' => _x( 'Recent Posts', 'Theme starter content' ), - ) ), - 'search' => array( 'search', array( - 'title' => _x( 'Search', 'Theme starter content' ), - ) ), + 'widgets' => array( + 'text_business_info' => array( + 'text', + array( + 'title' => _x( 'Find Us', 'Theme starter content' ), + 'text' => join( + '', + array( + '' . _x( 'Address', 'Theme starter content' ) . "\n", + _x( '123 Main Street', 'Theme starter content' ) . "\n" . _x( 'New York, NY 10001', 'Theme starter content' ) . "\n\n", + '' . _x( 'Hours', 'Theme starter content' ) . "\n", + _x( 'Monday—Friday: 9:00AM–5:00PM', 'Theme starter content' ) . "\n" . _x( 'Saturday & Sunday: 11:00AM–3:00PM', 'Theme starter content' ), + ) + ), + 'filter' => true, + 'visual' => true, + ), + ), + 'text_about' => array( + 'text', + array( + 'title' => _x( 'About This Site', 'Theme starter content' ), + 'text' => _x( 'This may be a good place to introduce yourself and your site or include some credits.', 'Theme starter content' ), + 'filter' => true, + 'visual' => true, + ), + ), + 'archives' => array( + 'archives', + array( + 'title' => _x( 'Archives', 'Theme starter content' ), + ), + ), + 'calendar' => array( + 'calendar', + array( + 'title' => _x( 'Calendar', 'Theme starter content' ), + ), + ), + 'categories' => array( + 'categories', + array( + 'title' => _x( 'Categories', 'Theme starter content' ), + ), + ), + 'meta' => array( + 'meta', + array( + 'title' => _x( 'Meta', 'Theme starter content' ), + ), + ), + 'recent-comments' => array( + 'recent-comments', + array( + 'title' => _x( 'Recent Comments', 'Theme starter content' ), + ), + ), + 'recent-posts' => array( + 'recent-posts', + array( + 'title' => _x( 'Recent Posts', 'Theme starter content' ), + ), + ), + 'search' => array( + 'search', + array( + 'title' => _x( 'Search', 'Theme starter content' ), + ), + ), ), 'nav_menus' => array( - 'link_home' => array( - 'type' => 'custom', + 'link_home' => array( + 'type' => 'custom', 'title' => _x( 'Home', 'Theme starter content' ), - 'url' => home_url( '/' ), + 'url' => home_url( '/' ), ), - 'page_home' => array( // Deprecated in favor of link_home. - 'type' => 'post_type', - 'object' => 'page', + 'page_home' => array( // Deprecated in favor of link_home. + 'type' => 'post_type', + 'object' => 'page', 'object_id' => '{{home}}', ), - 'page_about' => array( - 'type' => 'post_type', - 'object' => 'page', + 'page_about' => array( + 'type' => 'post_type', + 'object' => 'page', 'object_id' => '{{about}}', ), - 'page_blog' => array( - 'type' => 'post_type', - 'object' => 'page', + 'page_blog' => array( + 'type' => 'post_type', + 'object' => 'page', 'object_id' => '{{blog}}', ), - 'page_news' => array( - 'type' => 'post_type', - 'object' => 'page', + 'page_news' => array( + 'type' => 'post_type', + 'object' => 'page', 'object_id' => '{{news}}', ), - 'page_contact' => array( - 'type' => 'post_type', - 'object' => 'page', + 'page_contact' => array( + 'type' => 'post_type', + 'object' => 'page', 'object_id' => '{{contact}}', ), - 'link_email' => array( + 'link_email' => array( 'title' => _x( 'Email', 'Theme starter content' ), - 'url' => 'mailto:wordpress@example.com', + 'url' => 'mailto:wordpress@example.com', ), - 'link_facebook' => array( + 'link_facebook' => array( 'title' => _x( 'Facebook', 'Theme starter content' ), - 'url' => 'https://www.facebook.com/wordpress', + 'url' => 'https://www.facebook.com/wordpress', ), 'link_foursquare' => array( 'title' => _x( 'Foursquare', 'Theme starter content' ), - 'url' => 'https://foursquare.com/', + 'url' => 'https://foursquare.com/', ), - 'link_github' => array( + 'link_github' => array( 'title' => _x( 'GitHub', 'Theme starter content' ), - 'url' => 'https://github.com/wordpress/', + 'url' => 'https://github.com/wordpress/', ), - 'link_instagram' => array( + 'link_instagram' => array( 'title' => _x( 'Instagram', 'Theme starter content' ), - 'url' => 'https://www.instagram.com/explore/tags/wordcamp/', + 'url' => 'https://www.instagram.com/explore/tags/wordcamp/', ), - 'link_linkedin' => array( + 'link_linkedin' => array( 'title' => _x( 'LinkedIn', 'Theme starter content' ), - 'url' => 'https://www.linkedin.com/company/1089783', + 'url' => 'https://www.linkedin.com/company/1089783', ), - 'link_pinterest' => array( + 'link_pinterest' => array( 'title' => _x( 'Pinterest', 'Theme starter content' ), - 'url' => 'https://www.pinterest.com/', + 'url' => 'https://www.pinterest.com/', ), - 'link_twitter' => array( + 'link_twitter' => array( 'title' => _x( 'Twitter', 'Theme starter content' ), - 'url' => 'https://twitter.com/wordpress', + 'url' => 'https://twitter.com/wordpress', ), - 'link_yelp' => array( + 'link_yelp' => array( 'title' => _x( 'Yelp', 'Theme starter content' ), - 'url' => 'https://www.yelp.com', + 'url' => 'https://www.yelp.com', ), - 'link_youtube' => array( + 'link_youtube' => array( 'title' => _x( 'YouTube', 'Theme starter content' ), - 'url' => 'https://www.youtube.com/channel/UCdof4Ju7amm1chz1gi1T2ZA', + 'url' => 'https://www.youtube.com/channel/UCdof4Ju7amm1chz1gi1T2ZA', ), ), - 'posts' => array( - 'home' => array( - 'post_type' => 'page', - 'post_title' => _x( 'Home', 'Theme starter content' ), + 'posts' => array( + 'home' => array( + 'post_type' => 'page', + 'post_title' => _x( 'Home', 'Theme starter content' ), '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' ), ), - 'about' => array( - 'post_type' => 'page', - 'post_title' => _x( 'About', 'Theme starter content' ), + 'about' => array( + 'post_type' => 'page', + 'post_title' => _x( 'About', 'Theme starter content' ), 'post_content' => _x( 'You might be an artist who would like to introduce yourself and your work here or maybe you’re a business with a mission to describe.', 'Theme starter content' ), ), - 'contact' => array( - 'post_type' => 'page', - 'post_title' => _x( 'Contact', 'Theme starter content' ), + 'contact' => array( + 'post_type' => 'page', + 'post_title' => _x( 'Contact', 'Theme starter content' ), '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' ), ), - 'blog' => array( - 'post_type' => 'page', + 'blog' => array( + 'post_type' => 'page', 'post_title' => _x( 'Blog', 'Theme starter content' ), ), - 'news' => array( - 'post_type' => 'page', + 'news' => array( + 'post_type' => 'page', 'post_title' => _x( 'News', 'Theme starter content' ), ), 'homepage-section' => array( - 'post_type' => 'page', - 'post_title' => _x( 'A homepage section', 'Theme starter content' ), + 'post_type' => 'page', + 'post_title' => _x( 'A homepage section', 'Theme starter content' ), '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' ), ), ), @@ -2088,15 +2202,15 @@ $content = array(); foreach ( $config as $type => $args ) { - switch( $type ) { + switch ( $type ) { // Use options and theme_mods as-is. - case 'options' : - case 'theme_mods' : + case 'options': + case 'theme_mods': $content[ $type ] = $config[ $type ]; break; // Widgets are grouped into sidebars. - case 'widgets' : + case 'widgets': foreach ( $config[ $type ] as $sidebar_id => $widgets ) { foreach ( $widgets as $id => $widget ) { if ( is_array( $widget ) ) { @@ -2118,7 +2232,7 @@ break; // And nav menu items are grouped into nav menus. - case 'nav_menus' : + case 'nav_menus': foreach ( $config[ $type ] as $nav_menu_location => $nav_menu ) { // Ensure nav menus get a name. @@ -2145,7 +2259,7 @@ break; // Attachments are posts but have special treatment. - case 'attachments' : + case 'attachments': foreach ( $config[ $type ] as $id => $item ) { if ( ! empty( $item['file'] ) ) { $content[ $type ][ $id ] = $item; @@ -2154,7 +2268,7 @@ break; // All that's left now are posts (besides attachments). Not a default case for the sake of clarity and future work. - case 'posts' : + case 'posts': foreach ( $config[ $type ] as $id => $item ) { if ( is_array( $item ) ) { @@ -2210,22 +2324,27 @@ * @since 4.1.0 The `title-tag` feature was added * @since 4.5.0 The `customize-selective-refresh-widgets` feature was added * @since 4.7.0 The `starter-content` feature was added + * @since 5.0.0 The `responsive-embeds`, `align-wide`, `dark-editor-style`, `disable-custom-colors`, + * `disable-custom-font-sizes`, `editor-color-pallete`, `editor-font-sizes`, + * `editor-styles`, and `wp-block-styles` features were added. * * @global array $_wp_theme_features * * @param string $feature The feature being added. Likely core values include 'post-formats', * 'post-thumbnails', 'html5', 'custom-logo', 'custom-header-uploads', - * 'custom-header', 'custom-background', 'title-tag', 'starter-content', etc. + * 'custom-header', 'custom-background', 'title-tag', 'starter-content', + * 'responsive-embeds', etc. * @param mixed $args,... Optional extra arguments to pass along with certain features. * @return void|bool False on failure, void otherwise. */ function add_theme_support( $feature ) { global $_wp_theme_features; - if ( func_num_args() == 1 ) + if ( func_num_args() == 1 ) { $args = true; - else + } else { $args = array_slice( func_get_args(), 1 ); + } switch ( $feature ) { case 'post-thumbnails': @@ -2244,7 +2363,7 @@ break; - case 'post-formats' : + case 'post-formats': if ( is_array( $args[0] ) ) { $post_formats = get_post_format_slugs(); unset( $post_formats['standard'] ); @@ -2253,7 +2372,7 @@ } break; - case 'html5' : + case 'html5': // You can't just pass 'html5', you need to pass an array of types. if ( empty( $args[0] ) ) { // Build an array of types for back-compat. @@ -2264,8 +2383,9 @@ } // Calling 'html5' again merges, rather than overwrites. - if ( isset( $_wp_theme_features['html5'] ) ) + if ( isset( $_wp_theme_features['html5'] ) ) { $args[0] = array_merge( $_wp_theme_features['html5'][0], $args[0] ); + } break; case 'custom-logo': @@ -2279,7 +2399,7 @@ 'flex-height' => false, 'header-text' => '', ); - $args[0] = wp_parse_args( array_intersect_key( $args[0], $defaults ), $defaults ); + $args[0] = wp_parse_args( array_intersect_key( $args[0], $defaults ), $defaults ); // Allow full flexibility if no size is specified. if ( is_null( $args[0]['width'] ) && is_null( $args[0]['height'] ) ) { @@ -2288,28 +2408,29 @@ } break; - case 'custom-header-uploads' : + case 'custom-header-uploads': return add_theme_support( 'custom-header', array( 'uploads' => true ) ); - case 'custom-header' : - if ( ! is_array( $args ) ) + case 'custom-header': + if ( ! is_array( $args ) ) { $args = array( 0 => array() ); + } $defaults = array( - 'default-image' => '', - 'random-default' => false, - 'width' => 0, - 'height' => 0, - 'flex-height' => false, - 'flex-width' => false, - 'default-text-color' => '', - 'header-text' => true, - 'uploads' => true, - 'wp-head-callback' => '', - 'admin-head-callback' => '', + 'default-image' => '', + 'random-default' => false, + 'width' => 0, + 'height' => 0, + 'flex-height' => false, + 'flex-width' => false, + 'default-text-color' => '', + 'header-text' => true, + 'uploads' => true, + 'wp-head-callback' => '', + 'admin-head-callback' => '', 'admin-preview-callback' => '', - 'video' => false, - 'video-active-callback' => 'is_front_page', + 'video' => false, + 'video-active-callback' => 'is_front_page', ); $jit = isset( $args[0]['__jit'] ); @@ -2317,13 +2438,15 @@ // Merge in data from previous add_theme_support() calls. // The first value registered wins. (A child theme is set up first.) - if ( isset( $_wp_theme_features['custom-header'] ) ) + if ( isset( $_wp_theme_features['custom-header'] ) ) { $args[0] = wp_parse_args( $_wp_theme_features['custom-header'][0], $args[0] ); + } // Load in the defaults at the end, as we need to insure first one wins. // This will cause all constants to be defined, as each arg will then be set to the default. - if ( $jit ) + if ( $jit ) { $args[0] = wp_parse_args( $args[0], $defaults ); + } // If a constant was defined, use that value. Otherwise, define the constant to ensure // the constant is always accurate (and is not defined later, overriding our value). @@ -2331,48 +2454,57 @@ // Once we get to wp_loaded (just-in-time), define any constants we haven't already. // Constants are lame. Don't reference them. This is just for backward compatibility. - if ( defined( 'NO_HEADER_TEXT' ) ) + if ( defined( 'NO_HEADER_TEXT' ) ) { $args[0]['header-text'] = ! NO_HEADER_TEXT; - elseif ( isset( $args[0]['header-text'] ) ) + } elseif ( isset( $args[0]['header-text'] ) ) { define( 'NO_HEADER_TEXT', empty( $args[0]['header-text'] ) ); - - if ( defined( 'HEADER_IMAGE_WIDTH' ) ) + } + + if ( defined( 'HEADER_IMAGE_WIDTH' ) ) { $args[0]['width'] = (int) HEADER_IMAGE_WIDTH; - elseif ( isset( $args[0]['width'] ) ) + } elseif ( isset( $args[0]['width'] ) ) { define( 'HEADER_IMAGE_WIDTH', (int) $args[0]['width'] ); - - if ( defined( 'HEADER_IMAGE_HEIGHT' ) ) + } + + if ( defined( 'HEADER_IMAGE_HEIGHT' ) ) { $args[0]['height'] = (int) HEADER_IMAGE_HEIGHT; - elseif ( isset( $args[0]['height'] ) ) + } elseif ( isset( $args[0]['height'] ) ) { define( 'HEADER_IMAGE_HEIGHT', (int) $args[0]['height'] ); - - if ( defined( 'HEADER_TEXTCOLOR' ) ) + } + + if ( defined( 'HEADER_TEXTCOLOR' ) ) { $args[0]['default-text-color'] = HEADER_TEXTCOLOR; - elseif ( isset( $args[0]['default-text-color'] ) ) + } elseif ( isset( $args[0]['default-text-color'] ) ) { define( 'HEADER_TEXTCOLOR', $args[0]['default-text-color'] ); - - if ( defined( 'HEADER_IMAGE' ) ) + } + + if ( defined( 'HEADER_IMAGE' ) ) { $args[0]['default-image'] = HEADER_IMAGE; - elseif ( isset( $args[0]['default-image'] ) ) + } elseif ( isset( $args[0]['default-image'] ) ) { define( 'HEADER_IMAGE', $args[0]['default-image'] ); - - if ( $jit && ! empty( $args[0]['default-image'] ) ) + } + + if ( $jit && ! empty( $args[0]['default-image'] ) ) { $args[0]['random-default'] = false; + } // If headers are supported, and we still don't have a defined width or height, // we have implicit flex sizes. if ( $jit ) { - if ( empty( $args[0]['width'] ) && empty( $args[0]['flex-width'] ) ) + if ( empty( $args[0]['width'] ) && empty( $args[0]['flex-width'] ) ) { $args[0]['flex-width'] = true; - if ( empty( $args[0]['height'] ) && empty( $args[0]['flex-height'] ) ) + } + if ( empty( $args[0]['height'] ) && empty( $args[0]['flex-height'] ) ) { $args[0]['flex-height'] = true; + } } break; - case 'custom-background' : - if ( ! is_array( $args ) ) + case 'custom-background': + if ( ! is_array( $args ) ) { $args = array( 0 => array() ); + } $defaults = array( 'default-image' => '', @@ -2392,31 +2524,42 @@ unset( $args[0]['__jit'] ); // Merge in data from previous add_theme_support() calls. The first value registered wins. - if ( isset( $_wp_theme_features['custom-background'] ) ) + if ( isset( $_wp_theme_features['custom-background'] ) ) { $args[0] = wp_parse_args( $_wp_theme_features['custom-background'][0], $args[0] ); - - if ( $jit ) + } + + if ( $jit ) { $args[0] = wp_parse_args( $args[0], $defaults ); - - if ( defined( 'BACKGROUND_COLOR' ) ) + } + + if ( defined( 'BACKGROUND_COLOR' ) ) { $args[0]['default-color'] = BACKGROUND_COLOR; - elseif ( isset( $args[0]['default-color'] ) || $jit ) + } elseif ( isset( $args[0]['default-color'] ) || $jit ) { define( 'BACKGROUND_COLOR', $args[0]['default-color'] ); - - if ( defined( 'BACKGROUND_IMAGE' ) ) + } + + if ( defined( 'BACKGROUND_IMAGE' ) ) { $args[0]['default-image'] = BACKGROUND_IMAGE; - elseif ( isset( $args[0]['default-image'] ) || $jit ) + } elseif ( isset( $args[0]['default-image'] ) || $jit ) { define( 'BACKGROUND_IMAGE', $args[0]['default-image'] ); + } break; // Ensure that 'title-tag' is accessible in the admin. - case 'title-tag' : + case 'title-tag': // Can be called in functions.php but must happen before wp_loaded, i.e. not in header.php. if ( did_action( 'wp_loaded' ) ) { - /* translators: 1: Theme support 2: hook name */ - _doing_it_wrong( "add_theme_support( 'title-tag' )", sprintf( __( 'Theme support for %1$s should be registered before the %2$s hook.' ), - 'title-tag', 'wp_loaded' ), '4.1.0' ); + /* translators: 1: title-tag, 2: wp_loaded */ + _doing_it_wrong( + "add_theme_support( 'title-tag' )", + sprintf( + __( 'Theme support for %1$s should be registered before the %2$s hook.' ), + 'title-tag', + 'wp_loaded' + ), + '4.1.0' + ); return false; } @@ -2442,8 +2585,9 @@ add_theme_support( 'custom-header', array( '__jit' => true ) ); $args = get_theme_support( 'custom-header' ); - if ( $args[0]['wp-head-callback'] ) + if ( $args[0]['wp-head-callback'] ) { add_action( 'wp_head', $args[0]['wp-head-callback'] ); + } if ( is_admin() ) { require_once( ABSPATH . 'wp-admin/custom-header.php' ); @@ -2485,7 +2629,7 @@ clip: rect(1px, 1px, 1px, 1px); } - false ) ); return; // Do not continue - custom-header-uploads no longer exists. } - if ( ! isset( $_wp_theme_features[ $feature ] ) ) + if ( ! isset( $_wp_theme_features[ $feature ] ) ) { return false; + } switch ( $feature ) { - case 'custom-header' : - if ( ! did_action( 'wp_loaded' ) ) + case 'custom-header': + if ( ! did_action( 'wp_loaded' ) ) { break; + } $support = get_theme_support( 'custom-header' ); if ( isset( $support[0]['wp-head-callback'] ) ) { remove_action( 'wp_head', $support[0]['wp-head-callback'] ); @@ -2580,11 +2731,14 @@ } break; - case 'custom-background' : - if ( ! did_action( 'wp_loaded' ) ) + case 'custom-background': + if ( ! did_action( 'wp_loaded' ) ) { break; + } $support = get_theme_support( 'custom-background' ); - remove_action( 'wp_head', $support[0]['wp-head-callback'] ); + if ( isset( $support[0]['wp-head-callback'] ) ) { + remove_action( 'wp_head', $support[0]['wp-head-callback'] ); + } remove_action( 'admin_menu', array( $GLOBALS['custom_background'], 'init' ) ); unset( $GLOBALS['custom_background'] ); break; @@ -2595,27 +2749,30 @@ } /** - * Checks a theme's support for a given feature + * Checks a theme's support for a given feature. * * @since 2.9.0 * * @global array $_wp_theme_features * - * @param string $feature the feature being checked - * @return bool + * @param string $feature The feature being checked. + * @return bool True if the current theme supports the feature, false otherwise. */ function current_theme_supports( $feature ) { global $_wp_theme_features; - if ( 'custom-header-uploads' == $feature ) + if ( 'custom-header-uploads' == $feature ) { return current_theme_supports( 'custom-header', 'uploads' ); - - if ( !isset( $_wp_theme_features[$feature] ) ) + } + + if ( ! isset( $_wp_theme_features[ $feature ] ) ) { return false; + } // If no args passed then no extra checks need be performed - if ( func_num_args() <= 1 ) + if ( func_num_args() <= 1 ) { return true; + } $args = array_slice( func_get_args(), 1 ); @@ -2624,10 +2781,11 @@ // post-thumbnails can be registered for only certain content/post types by passing // an array of types to add_theme_support(). If no array was passed, then // any type is accepted - if ( true === $_wp_theme_features[$feature] ) // Registered for all types + if ( true === $_wp_theme_features[ $feature ] ) { // Registered for all types return true; + } $content_type = $args[0]; - return in_array( $content_type, $_wp_theme_features[$feature][0] ); + return in_array( $content_type, $_wp_theme_features[ $feature ][0] ); case 'html5': case 'post-formats': @@ -2637,7 +2795,7 @@ // Specific areas of HTML5 support *must* be passed via an array to add_theme_support() $type = $args[0]; - return in_array( $type, $_wp_theme_features[$feature][0] ); + return in_array( $type, $_wp_theme_features[ $feature ][0] ); case 'custom-logo': case 'custom-header': @@ -2660,7 +2818,7 @@ * @param array $args Array of arguments for the feature. * @param string $feature The theme feature. */ - return apply_filters( "current_theme_supports-{$feature}", true, $args, $_wp_theme_features[$feature] ); + return apply_filters( "current_theme_supports-{$feature}", true, $args, $_wp_theme_features[ $feature ] ); } /** @@ -2674,7 +2832,7 @@ */ function require_if_theme_supports( $feature, $include ) { if ( current_theme_supports( $feature ) ) { - require ( $include ); + require( $include ); return true; } return false; @@ -2773,7 +2931,7 @@ function _wp_customize_include() { $is_customize_admin_page = ( is_admin() && 'customize.php' == basename( $_SERVER['PHP_SELF'] ) ); - $should_include = ( + $should_include = ( $is_customize_admin_page || ( isset( $_REQUEST['wp_customize'] ) && 'on' == $_REQUEST['wp_customize'] ) @@ -2790,17 +2948,17 @@ * called before wp_magic_quotes() gets called. Besides this fact, none of * the values should contain any characters needing slashes anyway. */ - $keys = array( 'changeset_uuid', 'customize_changeset_uuid', 'customize_theme', 'theme', 'customize_messenger_channel', 'customize_autosaved' ); + $keys = array( 'changeset_uuid', 'customize_changeset_uuid', 'customize_theme', 'theme', 'customize_messenger_channel', 'customize_autosaved' ); $input_vars = array_merge( wp_array_slice_assoc( $_GET, $keys ), wp_array_slice_assoc( $_POST, $keys ) ); - $theme = null; - $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. + $theme = null; + $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. $messenger_channel = null; - $autosaved = null; - $branching = false; // Set initially fo false since defaults to true for back-compat; can be overridden via the customize_changeset_branching filter. + $autosaved = null; + $branching = false; // Set initially fo false since defaults to true for back-compat; can be overridden via the customize_changeset_branching filter. if ( $is_customize_admin_page && isset( $input_vars['changeset_uuid'] ) ) { $changeset_uuid = sanitize_key( $input_vars['changeset_uuid'] ); @@ -2837,7 +2995,7 @@ && 'customize_save' === wp_unslash( $_REQUEST['action'] ) ); - $settings_previewed = ! $is_customize_save_action; + $settings_previewed = ! $is_customize_save_action; require_once ABSPATH . WPINC . '/class-wp-customize-manager.php'; $GLOBALS['wp_customize'] = new WP_Customize_Manager( compact( 'changeset_uuid', 'theme', 'messenger_channel', 'settings_previewed', 'autosaved', 'branching' ) ); @@ -2872,10 +3030,12 @@ if ( empty( $wp_customize ) ) { require_once ABSPATH . WPINC . '/class-wp-customize-manager.php'; - $wp_customize = new WP_Customize_Manager( array( - 'changeset_uuid' => $changeset_post->post_name, - 'settings_previewed' => false, - ) ); + $wp_customize = new WP_Customize_Manager( + array( + 'changeset_uuid' => $changeset_post->post_name, + 'settings_previewed' => false, + ) + ); } if ( ! did_action( 'customize_register' ) ) { @@ -2899,13 +3059,13 @@ /** This filter is documented in /wp-includes/class-wp-customize-manager.php */ do_action( 'customize_register', $wp_customize ); } - $wp_customize->_publish_changeset_values( $changeset_post->ID ) ; + $wp_customize->_publish_changeset_values( $changeset_post->ID ); /* * Trash the changeset post if revisions are not enabled. Unpublished * changesets by default get garbage collected due to the auto-draft status. * When a changeset post is published, however, it would no longer get cleaned - * out. Ths is a problem when the changeset posts are never displayed anywhere, + * out. This is a problem when the changeset posts are never displayed anywhere, * since they would just be endlessly piling up. So here we use the revisions * feature to indicate whether or not a published changeset should get trashed * and thus garbage collected. @@ -2947,7 +3107,7 @@ function _wp_customize_loader_settings() { $admin_origin = parse_url( admin_url() ); $home_origin = parse_url( home_url() ); - $cross_domain = ( strtolower( $admin_origin[ 'host' ] ) != strtolower( $home_origin[ 'host' ] ) ); + $cross_domain = ( strtolower( $admin_origin['host'] ) != strtolower( $home_origin['host'] ) ); $browser = array( 'mobile' => wp_is_mobile(), @@ -2967,9 +3127,10 @@ $script = 'var _wpCustomizeLoaderSettings = ' . wp_json_encode( $settings ) . ';'; $wp_scripts = wp_scripts(); - $data = $wp_scripts->get_data( 'customize-loader', 'data' ); - if ( $data ) + $data = $wp_scripts->get_data( 'customize-loader', 'data' ); + if ( $data ) { $script = "$data\n$script"; + } $wp_scripts->add_data( 'customize-loader', 'data', $script ); } @@ -2980,13 +3141,14 @@ * @since 3.4.0 * * @param string $stylesheet Optional. Theme to customize. Defaults to current theme. - * The theme's stylesheet will be urlencoded if necessary. + * The theme's stylesheet will be urlencoded if necessary. * @return string */ function wp_customize_url( $stylesheet = null ) { $url = admin_url( 'customize.php' ); - if ( $stylesheet ) + if ( $stylesheet ) { $url .= '?theme=' . urlencode( $stylesheet ); + } return esc_url( $url ); } @@ -3009,7 +3171,7 @@ function wp_customize_support_script() { $admin_origin = parse_url( admin_url() ); $home_origin = parse_url( home_url() ); - $cross_domain = ( strtolower( $admin_origin[ 'host' ] ) != strtolower( $home_origin[ 'host' ] ) ); + $cross_domain = ( strtolower( $admin_origin['host'] ) != strtolower( $home_origin['host'] ) ); ?>