Make WordPress Core


Ignore:
Timestamp:
05/24/2021 09:20:31 PM (5 years ago)
Author:
gziolo
Message:

Editor: Use the block editor context in filters that used the editor name

Follow-up for [50956].
Props azaozz, chrisvanpatten, timothyblynjacobs, youknowriad.
Fixes #52920.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/blocks/block-editor.php

    r50956 r50983  
    7777     */
    7878    function test_block_editor_context_post() {
    79         $context = new WP_Block_Editor_Context( array( 'post' => $this->post ) );
    80 
    81         $this->assertSame( $this->post, $context->post );
     79        $context = new WP_Block_Editor_Context( array( 'post' => get_post() ) );
     80
     81        $this->assertSame( get_post(), $context->post );
    8282    }
    8383
     
    112112        add_filter( 'block_categories', array( $this, 'filter_set_block_categories_post' ), 10, 2 );
    113113
    114         $block_categories = get_block_categories( 'post-editor' );
     114        $post_editor_context = new WP_Block_Editor_Context( array( 'post' => get_post() ) );
     115        $block_categories    = get_block_categories( $post_editor_context );
    115116
    116117        remove_filter( 'block_categories', array( $this, 'filter_set_block_categories_post' ) );
     
    132133     */
    133134    function test_get_allowed_block_types_default() {
    134         $allowed_block_types = get_allowed_block_types( 'post-editor' );
     135        $post_editor_context = new WP_Block_Editor_Context( array( 'post' => get_post() ) );
     136        $allowed_block_types = get_allowed_block_types( $post_editor_context );
    135137
    136138        $this->assertTrue( $allowed_block_types );
     
    144146        add_filter( 'allowed_block_types', array( $this, 'filter_set_allowed_block_types_post' ), 10, 2 );
    145147
    146         $allowed_block_types = get_allowed_block_types( 'post-editor' );
     148        $post_editor_context = new WP_Block_Editor_Context( array( 'post' => get_post() ) );
     149        $allowed_block_types = get_allowed_block_types( $post_editor_context );
    147150
    148151        remove_filter( 'allowed_block_types', array( $this, 'filter_set_allowed_block_types_post' ) );
     
    280283        add_filter( 'block_editor_settings_all', 'filter_block_editor_settings_my_editor', 10, 1 );
    281284
    282         $settings = get_block_editor_settings( 'my-editor' );
     285        $my_editor_context = new WP_Block_Editor_Context();
     286        $settings          = get_block_editor_settings( array(), $my_editor_context );
    283287
    284288        remove_filter( 'allowed_block_types_all', 'filter_allowed_block_types_my_editor' );
     
    307311        add_filter( 'block_editor_settings', array( $this, 'filter_set_block_editor_settings_post' ), 10, 2 );
    308312
    309         $settings = get_block_editor_settings( 'post-editor' );
     313        $post_editor_context = new WP_Block_Editor_Context( array( 'post' => get_post() ) );
     314        $settings            = get_block_editor_settings( array(), $post_editor_context );
    310315
    311316        remove_filter( 'block_editor_settings', array( $this, 'filter_set_block_editor_settings_post' ) );
     
    323328     */
    324329    function test_block_editor_rest_api_preload_no_paths() {
    325         $context = new WP_Block_Editor_Context();
    326         block_editor_rest_api_preload( array(), $context );
     330        $editor_context = new WP_Block_Editor_Context();
     331        block_editor_rest_api_preload( array(), $editor_context );
    327332
    328333        $after = implode( '', wp_scripts()->registered['wp-api-fetch']->extra['after'] );
     
    343348        add_filter( 'block_editor_preload_paths', 'filter_remove_preload_paths', 10, 2 );
    344349
    345         $context = new WP_Block_Editor_Context( array( 'post' => get_post() ) );
     350        $post_editor_context = new WP_Block_Editor_Context( array( 'post' => get_post() ) );
    346351        block_editor_rest_api_preload(
    347352            array(
    348353                array( '/wp/v2/blocks', 'OPTIONS' ),
    349354            ),
    350             $context
     355            $post_editor_context
    351356        );
    352357
     
    370375        add_filter( 'block_editor_rest_api_preload_paths', 'filter_add_preload_paths', 10, 2 );
    371376
    372         $context = new WP_Block_Editor_Context();
     377        $editor_context = new WP_Block_Editor_Context();
    373378        block_editor_rest_api_preload(
    374379            array(
    375380                array( '/wp/v2/blocks', 'OPTIONS' ),
    376381            ),
    377             $context
     382            $editor_context
    378383        );
    379384
Note: See TracChangeset for help on using the changeset viewer.