PHP: backport from 6.1 again. #46363
Conversation
| /** | ||
| * 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(), | ||
| ); | ||
|
|
||
| /** | ||
| * Container for data coming from the blocks. | ||
| * | ||
| * @since 6.1.0 | ||
| * @var WP_Theme_JSON | ||
| */ | ||
| protected static $blocks = null; |
There was a problem hiding this comment.
These changes were not part of Core commit https://core.trac.wordpress.org/changeset/54493. I'll revert them.
| /** | ||
| * 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 ) { |
There was a problem hiding this comment.
Same with this one. 6.1.0 did not add this method to WP_Theme_JSON_Data. I'll revert this change too.
| /** | ||
| * Container for data coming from the blocks. | ||
| * | ||
| * @since 6.1.0 | ||
| * @var WP_Theme_JSON | ||
| */ | ||
| protected static $blocks = null; | ||
|
|
There was a problem hiding this comment.
This change is not in Core 6.1. Needs to be reverted too.
|
|
||
| return false; | ||
| } | ||
| } |
There was a problem hiding this comment.
Also need to add the changes for WP_Theme_JSON_Resolver::get_theme_data(). Why? Gutenberg's class extends from WP_Theme_JSON_Resolver_6_0 which will overload Core's get_theme_data() method, meaning Core's won't be used. That can cause unexpected differences in the way the plugin works vs Core.
There was a problem hiding this comment.
| } | |
| /** | |
| * Returns the theme's data. | |
| * | |
| * Data from theme.json will be backfilled from existing | |
| * theme supports, if any. Note that if the same data | |
| * is present in theme.json and in theme supports, | |
| * the theme.json takes precedence. | |
| * | |
| * @since 5.8.0 | |
| * @since 5.9.0 Theme supports have been inlined and the `$theme_support_data` argument removed. | |
| * @since 6.0.0 Added an `$options` parameter to allow the theme data to be returned without theme supports. | |
| * | |
| * @param array $deprecated Deprecated. Not used. | |
| * @param array $options { | |
| * Options arguments. | |
| * | |
| * @type bool $with_supports Whether to include theme supports in the data. Default true. | |
| * } | |
| * @return WP_Theme_JSON Entity that holds theme data. | |
| */ | |
| public static function get_theme_data( $deprecated = array(), $options = array() ) { | |
| return WP_Theme_JSON_Resolver::get_theme_data( $deprecated, $options ); | |
| } | |
| } |
There was a problem hiding this comment.
The above suggested code will bypass WP_Theme_JSON_Resolver_6_0::get_theme_data() implementation, to call the version in Core 6.1.
There was a problem hiding this comment.
But wait a minute. This won't work if the site is running < WP 6.1 with the plugin. So the entire WP_Theme_JSON_Resolver::get_theme_data() code needs to be copied here it seems.
| /** | ||
| * 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(), | ||
| ); | ||
|
|
There was a problem hiding this comment.
| /** | |
| * 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(), | |
| ); |
Not needed, as this class will inherit it from Core's WP_Theme_JSON_Resolver class.
There was a problem hiding this comment.
After talking with Jonny, this code is needed for sites that are running < WP 6.1 with the plugin.
Also need:
protected static $blocks = null;this too.
Sorry for the confusion.
|
@hellofromtonya What do you want to me to do? |
|
I was looking at this fatal error with Gutenberg 14.8.2 and WordPress 6.0 introduced at #46250 and found this PR was missing from the 14.8 release. The issue is now fixed as of #46750 and this can be closed. |
What?
Change from WordPress/wordpress-develop@4be7661 by @hellofromtonya.
Fixes issue reported by #46250 (comment) by @mirka
Why?
How?
Testing Instructions
Testing Instructions for Keyboard
Screenshots or screencast