Make WordPress Core

Changeset 52593


Ignore:
Timestamp:
01/17/2022 10:40:51 PM (2 years ago)
Author:
hellofromTonya
Message:

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.

Location:
trunk/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/edit-form-blocks.php

    r52409 r52593  
    2828$current_screen = get_current_screen();
    2929$current_screen->is_block_editor( true );
     30
     31// Load block patterns from w.org.
     32_load_remote_block_patterns();
     33_load_remote_featured_patterns();
    3034
    3135// Default to is-fullscreen-mode to avoid jumps in the UI.
  • trunk/src/wp-admin/site-editor.php

    r52372 r52593  
    3131$current_screen = get_current_screen();
    3232$current_screen->is_block_editor( true );
     33
     34// Load block patterns from w.org.
     35_load_remote_block_patterns();
     36_load_remote_featured_patterns();
    3337
    3438// Default to is-fullscreen-mode to avoid jumps in the UI.
  • trunk/src/wp-includes/block-patterns.php

    r52377 r52593  
    4949 *
    5050 * @since 5.8.0
     51 * @since 5.9.0 The $current_screen argument was removed.
    5152 *
    52  * @param WP_Screen $current_screen The screen that the current request was triggered from.
     53 * @param WP_Screen $deprecated Unused. Formerly the screen that the current request was triggered from.
    5354 */
    54 function _load_remote_block_patterns( $current_screen ) {
    55     if ( ! $current_screen->is_block_editor ) {
    56         return;
     55function _load_remote_block_patterns( $deprecated = null ) {
     56    if ( ! empty( $deprecated ) ) {
     57        _deprecated_argument( __FUNCTION__, '5.9.0' );
     58        $current_screen = $deprecated;
     59        if ( ! $current_screen->is_block_editor ) {
     60            return;
     61        }
    5762    }
    5863
     
    8994 *
    9095 * @since 5.9.0
    91  *
    92  * @param WP_Screen $current_screen The screen that the current request was triggered from.
    9396 */
    94 function _load_remote_featured_patterns( $current_screen ) {
    95     if ( ! $current_screen->is_block_editor ) {
    96         return;
    97     }
    98 
     97function _load_remote_featured_patterns() {
    9998    $supports_core_patterns = get_theme_support( 'core-block-patterns' );
    10099
  • trunk/src/wp-includes/default-filters.php

    r52437 r52593  
    333333add_action( 'wp_print_footer_scripts', '_wp_footer_scripts' );
    334334add_action( 'init', '_register_core_block_patterns_and_categories' );
    335 add_action( 'current_screen', '_load_remote_block_patterns' );
    336 add_action( 'current_screen', '_load_remote_featured_patterns' );
    337335add_action( 'init', 'check_theme_switched', 99 );
    338336add_action( 'init', array( 'WP_Block_Supports', 'init' ), 22 );
Note: See TracChangeset for help on using the changeset viewer.