-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
PHP: backport from 6.1 again. #46363
Changes from all commits
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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -25,6 +25,19 @@ class WP_Theme_JSON_Resolver_6_1 extends WP_Theme_JSON_Resolver_6_0 { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
protected static $core = null; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
* Container for keep track of registered blocks. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
* | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
* @since 6.1.0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
* @var array | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
protected static $blocks_cache = array( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
'core' => array(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
'blocks' => array(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
'theme' => array(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
'user' => array(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
* Given a theme.json structure modifies it in place | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
* to update certain values by its translated strings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -50,7 +63,7 @@ protected static function translate( $theme_json, $domain = 'default' ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
* @return WP_Theme_JSON_Gutenberg Entity that holds core data. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
public static function get_core_data() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
if ( null !== static::$core ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
if ( null !== static::$core && static::has_same_registered_blocks( 'core' ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
return static::$core; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -74,7 +87,7 @@ public static function get_core_data() { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
* @return WP_Theme_JSON_Gutenberg Entity that holds styles for user data. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
public static function get_user_data() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
if ( null !== static::$user ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
if ( null !== static::$user && static::has_same_registered_blocks( 'user' ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
return static::$user; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -188,4 +201,35 @@ public static function get_user_data_from_wp_global_styles( $theme, $create_post | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
return $user_cpt; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
* Checks whether the registered blocks were already processed for this origin. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
* | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
* @since 6.1.0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
* | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
* @param string $origin Data source for which to cache the blocks. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
* Valid values are 'core', 'blocks', 'theme', and 'user'. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
* @return bool True on success, false otherwise. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
protected static function has_same_registered_blocks( $origin ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Bail out if the origin is invalid. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
if ( ! isset( static::$blocks_cache[ $origin ] ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
return false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
$registry = WP_Block_Type_Registry::get_instance(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
$blocks = $registry->get_all_registered(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Is there metadata for all currently registered blocks? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
$block_diff = array_diff_key( $blocks, static::$blocks_cache[ $origin ] ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
if ( empty( $block_diff ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
return true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
foreach ( $blocks as $block_name => $block_type ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
static::$blocks_cache[ $origin ][ $block_name ] = true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
return false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
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. Also need to add the changes for 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.
Suggested change
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. The above suggested code will bypass 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. But wait a minute. This won't work if the site is running < WP 6.1 with the plugin. So the entire |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed, as this class will inherit it from Core's
WP_Theme_JSON_Resolver
class.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After talking with Jonny, this code is needed for sites that are running < WP 6.1 with the plugin.
Also need:
this too.
Sorry for the confusion.