-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Fix wp_head performance regression for classic themes
#3536
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
787b2c2
aff6347
196c215
0c768d3
b9ff774
f34fe53
6a835a4
1ab511c
bf4e711
4966109
3a24f75
34c1957
392391a
782c49d
3ab53bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -246,8 +246,13 @@ public static function get_theme_data( $deprecated = array(), $options = array() | |
| $options = wp_parse_args( $options, array( 'with_supports' => true ) ); | ||
|
|
||
| if ( null === static::$theme || ! static::has_same_registered_blocks( 'theme' ) ) { | ||
| $theme_json_data = static::read_json_file( static::get_file_path_from_theme( 'theme.json' ) ); | ||
| $theme_json_data = static::translate( $theme_json_data, wp_get_theme()->get( 'TextDomain' ) ); | ||
| $theme_json_file = static::get_file_path_from_theme( 'theme.json' ); | ||
| if ( '' !== $theme_json_file ) { | ||
| $theme_json_data = static::read_json_file( $theme_json_file ); | ||
| $theme_json_data = static::translate( $theme_json_data, wp_get_theme()->get( 'TextDomain' ) ); | ||
| } else { | ||
| $theme_json_data = array(); | ||
| } | ||
|
|
||
| /** | ||
| * Filters the data provided by the theme for global styles and settings. | ||
|
|
@@ -259,20 +264,23 @@ public static function get_theme_data( $deprecated = array(), $options = array() | |
| $theme_json = apply_filters( 'wp_theme_json_data_theme', new WP_Theme_JSON_Data( $theme_json_data, 'theme' ) ); | ||
| $theme_json_data = $theme_json->get_data(); | ||
| static::$theme = new WP_Theme_JSON( $theme_json_data ); | ||
| } | ||
felixarntz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if ( wp_get_theme()->parent() ) { | ||
| // Get parent theme.json. | ||
| $parent_theme_json_data = static::read_json_file( static::get_file_path_from_theme( 'theme.json', true ) ); | ||
| $parent_theme_json_data = static::translate( $parent_theme_json_data, wp_get_theme()->parent()->get( 'TextDomain' ) ); | ||
| $parent_theme = new WP_Theme_JSON( $parent_theme_json_data ); | ||
|
|
||
| /* | ||
| * Merge the child theme.json into the parent theme.json. | ||
| * The child theme takes precedence over the parent. | ||
| */ | ||
| $parent_theme->merge( static::$theme ); | ||
| static::$theme = $parent_theme; | ||
| if ( wp_get_theme()->parent() ) { | ||
felixarntz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // Get parent theme.json. | ||
| $parent_theme_json_file = static::get_file_path_from_theme( 'theme.json', true ); | ||
| if ( '' !== $parent_theme_json_file ) { | ||
felixarntz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| $parent_theme_json_data = static::read_json_file( $parent_theme_json_file ); | ||
| $parent_theme_json_data = static::translate( $parent_theme_json_data, wp_get_theme()->parent()->get( 'TextDomain' ) ); | ||
| $parent_theme = new WP_Theme_JSON( $parent_theme_json_data ); | ||
|
|
||
| /* | ||
| * Merge the child theme.json into the parent theme.json. | ||
| * The child theme takes precedence over the parent. | ||
| */ | ||
| $parent_theme->merge( static::$theme ); | ||
| static::$theme = $parent_theme; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if ( ! $options['with_supports'] ) { | ||
|
|
@@ -403,6 +411,18 @@ public static function get_user_data_from_wp_global_styles( $theme, $create_post | |
| if ( ! $theme instanceof WP_Theme ) { | ||
| $theme = wp_get_theme(); | ||
| } | ||
|
|
||
| /* | ||
| * Bail early if the theme does not support a theme.json. | ||
| * | ||
| * Since WP_Theme_JSON_Resolver::theme_has_support() only supports the active | ||
| * theme, the extra condition for whether $theme is the active theme is | ||
| * present here. | ||
| */ | ||
| if ( $theme->get_stylesheet() === get_stylesheet() && ! static::theme_has_support() ) { | ||
felixarntz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return array(); | ||
| } | ||
|
|
||
| $user_cpt = array(); | ||
| $post_type_filter = 'wp_global_styles'; | ||
| $stylesheet = $theme->get_stylesheet(); | ||
|
|
@@ -582,8 +602,8 @@ public static function get_user_global_styles_post_id() { | |
| public static function theme_has_support() { | ||
| if ( ! isset( static::$theme_has_support ) ) { | ||
| static::$theme_has_support = ( | ||
| is_readable( static::get_file_path_from_theme( 'theme.json' ) ) || | ||
| is_readable( static::get_file_path_from_theme( 'theme.json', true ) ) | ||
| static::get_file_path_from_theme( 'theme.json' ) !== '' || | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is nice, |
||
| static::get_file_path_from_theme( 'theme.json', true ) !== '' | ||
|
Comment on lines
+605
to
+606
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yoda
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this is needed here. Yoda conditions are only required around variable to value comparisons, not with functions (since setting a function to another value would result in an error anyway). |
||
| ); | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.