mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-22 17:18:32 +01:00
Editor: Explicitly load remote block patterns in the block and site editor screens.
Remote block patterns from wp.org were to be loaded through a callback hooked into the `current_screen` filter. Within 2 callbacks, i.e. `_load_remote_featured_patterns()` and `_load_remote_block_patterns()`, a guard clause bailed out early if the `$current_screen->is_block_editor` is `false`. However, the `current_screen` filter is unreliable to detect the block editor. Why? In the block and Site Editor screens, `$current_scren->is_block_editor` is not set until after the filter is executed. Whoopsie. This commit no longer uses the `current_screen` filter. Instead, it explicitly loads the remote block patterns by invoking both private functions (now not callbacks) directly in the screen files for the block and site editor screens. With this change, passing `WP_Screen` object into these functions is no longer needed. As the `_load_remote_block_patterns()` function was introduced in 5.8.0, its function parameter is now deprecated and the guard clause retained for backwards compatibility. Follow-up to [51021], [52377]. Props poena, noisysocks, peterwilsoncc, hellofromTonya, audrasjb. Fixes #54806. Built from https://develop.svn.wordpress.org/trunk@52593 git-svn-id: http://core.svn.wordpress.org/trunk@52181 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
c20c8a99bd
commit
e158979d3d
@ -28,6 +28,10 @@ $block_editor_context = new WP_Block_Editor_Context( array( 'post' => $post ) );
|
||||
$current_screen = get_current_screen();
|
||||
$current_screen->is_block_editor( true );
|
||||
|
||||
// Load block patterns from w.org.
|
||||
_load_remote_block_patterns();
|
||||
_load_remote_featured_patterns();
|
||||
|
||||
// Default to is-fullscreen-mode to avoid jumps in the UI.
|
||||
add_filter(
|
||||
'admin_body_class',
|
||||
|
@ -31,6 +31,10 @@ $parent_file = 'themes.php';
|
||||
$current_screen = get_current_screen();
|
||||
$current_screen->is_block_editor( true );
|
||||
|
||||
// Load block patterns from w.org.
|
||||
_load_remote_block_patterns();
|
||||
_load_remote_featured_patterns();
|
||||
|
||||
// Default to is-fullscreen-mode to avoid jumps in the UI.
|
||||
add_filter(
|
||||
'admin_body_class',
|
||||
|
@ -48,12 +48,17 @@ function _register_core_block_patterns_and_categories() {
|
||||
* Register Core's official patterns from wordpress.org/patterns.
|
||||
*
|
||||
* @since 5.8.0
|
||||
* @since 5.9.0 The $current_screen argument was removed.
|
||||
*
|
||||
* @param WP_Screen $current_screen The screen that the current request was triggered from.
|
||||
* @param WP_Screen $deprecated Unused. Formerly the screen that the current request was triggered from.
|
||||
*/
|
||||
function _load_remote_block_patterns( $current_screen ) {
|
||||
if ( ! $current_screen->is_block_editor ) {
|
||||
return;
|
||||
function _load_remote_block_patterns( $deprecated = null ) {
|
||||
if ( ! empty( $deprecated ) ) {
|
||||
_deprecated_argument( __FUNCTION__, '5.9.0' );
|
||||
$current_screen = $deprecated;
|
||||
if ( ! $current_screen->is_block_editor ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$supports_core_patterns = get_theme_support( 'core-block-patterns' );
|
||||
@ -88,14 +93,8 @@ function _load_remote_block_patterns( $current_screen ) {
|
||||
* Register `Featured` (category) patterns from wordpress.org/patterns.
|
||||
*
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param WP_Screen $current_screen The screen that the current request was triggered from.
|
||||
*/
|
||||
function _load_remote_featured_patterns( $current_screen ) {
|
||||
if ( ! $current_screen->is_block_editor ) {
|
||||
return;
|
||||
}
|
||||
|
||||
function _load_remote_featured_patterns() {
|
||||
$supports_core_patterns = get_theme_support( 'core-block-patterns' );
|
||||
|
||||
/** This filter is documented in wp-includes/block-patterns.php */
|
||||
|
@ -332,8 +332,6 @@ add_action( 'wp_footer', 'wp_print_footer_scripts', 20 );
|
||||
add_action( 'template_redirect', 'wp_shortlink_header', 11, 0 );
|
||||
add_action( 'wp_print_footer_scripts', '_wp_footer_scripts' );
|
||||
add_action( 'init', '_register_core_block_patterns_and_categories' );
|
||||
add_action( 'current_screen', '_load_remote_block_patterns' );
|
||||
add_action( 'current_screen', '_load_remote_featured_patterns' );
|
||||
add_action( 'init', 'check_theme_switched', 99 );
|
||||
add_action( 'init', array( 'WP_Block_Supports', 'init' ), 22 );
|
||||
add_action( 'switch_theme', array( 'WP_Theme_JSON_Resolver', 'clean_cached_data' ) );
|
||||
|
@ -16,7 +16,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '6.0-alpha-52591';
|
||||
$wp_version = '6.0-alpha-52593';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
Loading…
Reference in New Issue
Block a user