Add WP_Block_Editor_Context::$name

Adds a new `WP_Block_Editor_Context::$name` and field. This allows plugin
developers to tell which block editor is being loaded when using filters such as
`allowed_block_types_all` and `block_editor_rest_api_preload_paths`.

Fixes #55301.
Props talldanwp, gziolo, andraganescu.


git-svn-id: https://develop.svn.wordpress.org/trunk@52942 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Robert Anderson
2022-03-17 03:35:13 +00:00
parent dc210fcaa6
commit 3b8dc986d2
5 changed files with 60 additions and 9 deletions

View File

@@ -80,6 +80,7 @@ class Tests_Blocks_Editor extends WP_UnitTestCase {
public function test_block_editor_context_no_settings() {
$context = new WP_Block_Editor_Context();
$this->assertSame( 'core/edit-post', $context->name );
$this->assertNull( $context->post );
}
@@ -89,9 +90,40 @@ class Tests_Blocks_Editor extends WP_UnitTestCase {
public function test_block_editor_context_post() {
$context = new WP_Block_Editor_Context( array( 'post' => get_post() ) );
$this->assertSame( 'core/edit-post', $context->name );
$this->assertSame( get_post(), $context->post );
}
/**
* @ticket 55301
*/
public function test_block_editor_context_widgets() {
$context = new WP_Block_Editor_Context( array( 'name' => 'core/edit-widgets' ) );
$this->assertSame( 'core/edit-widgets', $context->name );
$this->assertNull( $context->post );
}
/**
* @ticket 55301
*/
public function test_block_editor_context_widgets_customizer() {
$context = new WP_Block_Editor_Context( array( 'name' => 'core/customize-widgets' ) );
$this->assertSame( 'core/customize-widgets', $context->name );
$this->assertNull( $context->post );
}
/**
* @ticket 55301
*/
public function test_block_editor_context_site() {
$context = new WP_Block_Editor_Context( array( 'name' => 'core/edit-site' ) );
$this->assertSame( 'core/edit-site', $context->name );
$this->assertNull( $context->post );
}
/**
* @ticket 52920
* @expectedDeprecated block_categories