From e158979d3d8e5d693969721341c711d012b7fcc7 Mon Sep 17 00:00:00 2001 From: hellofromTonya Date: Mon, 17 Jan 2022 22:42:03 +0000 Subject: [PATCH] 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 --- wp-admin/edit-form-blocks.php | 4 ++++ wp-admin/site-editor.php | 4 ++++ wp-includes/block-patterns.php | 21 ++++++++++----------- wp-includes/default-filters.php | 2 -- wp-includes/version.php | 2 +- 5 files changed, 19 insertions(+), 14 deletions(-) diff --git a/wp-admin/edit-form-blocks.php b/wp-admin/edit-form-blocks.php index e05be4c356..5e7b39d619 100644 --- a/wp-admin/edit-form-blocks.php +++ b/wp-admin/edit-form-blocks.php @@ -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', diff --git a/wp-admin/site-editor.php b/wp-admin/site-editor.php index 421ceb4861..cbbf38e7ea 100644 --- a/wp-admin/site-editor.php +++ b/wp-admin/site-editor.php @@ -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', diff --git a/wp-includes/block-patterns.php b/wp-includes/block-patterns.php index b1dfaeb403..55c0dd29ba 100644 --- a/wp-includes/block-patterns.php +++ b/wp-includes/block-patterns.php @@ -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 */ diff --git a/wp-includes/default-filters.php b/wp-includes/default-filters.php index d9663946d6..20559dd179 100644 --- a/wp-includes/default-filters.php +++ b/wp-includes/default-filters.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' ) ); diff --git a/wp-includes/version.php b/wp-includes/version.php index 75c5bdfea3..8bb6125bd6 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -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.