mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 14:20:15 +00:00
Editor: Remove editor type specific filters for block editor configuration
Aligns with changes introduced in the Gutenberg plugin. The planned follow-up replace the editor name string with a context object to bring back an optional reference to the actual post. Props youknowriad. See #52920. git-svn-id: https://develop.svn.wordpress.org/trunk@50920 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -120,21 +120,6 @@ function get_allowed_block_types( $editor_name ) {
|
||||
* @param string $editor_name The name of the editor, e.g. 'post-editor'.
|
||||
*/
|
||||
$allowed_block_types = apply_filters( 'allowed_block_types_all', $allowed_block_types, $editor_name );
|
||||
|
||||
/**
|
||||
* Filters the allowed block types for the given editor, defaulting to `true`
|
||||
* (all registered block types supported).
|
||||
*
|
||||
* The dynamic portion of the hook name, `$editor_name`, refers to the name
|
||||
* of the editor type, e.g. 'post-editor', 'site-editor', etc.
|
||||
*
|
||||
* @since 5.8.0
|
||||
*
|
||||
* @param bool|array $allowed_block_types Array of block type slugs, or
|
||||
* boolean to enable/disable all.
|
||||
* @param string $editor_name The name of the editor, e.g. 'post-editor'.
|
||||
*/
|
||||
$allowed_block_types = apply_filters( "allowed_block_types_{$editor_name}", $allowed_block_types, $editor_name );
|
||||
if ( 'post-editor' === $editor_name ) {
|
||||
$post = get_post();
|
||||
|
||||
@@ -267,19 +252,6 @@ function get_block_editor_settings( $editor_name, $custom_settings = array() ) {
|
||||
* @param string $editor_name The name of the editor, e.g. 'post-editor'.
|
||||
*/
|
||||
$editor_settings = apply_filters( 'block_editor_settings_all', $editor_settings, $editor_name );
|
||||
|
||||
/**
|
||||
* Filters the settings to pass to the block editor for a given editor type.
|
||||
*
|
||||
* The dynamic portion of the hook name, `$editor_name`, refers to the name
|
||||
* of the editor type, e.g. 'post-editor', 'site-editor', etc.
|
||||
*
|
||||
* @since 5.8.0
|
||||
*
|
||||
* @param array $editor_settings Default editor settings.
|
||||
* @param string $editor_name The name of the editor, e.g. 'post-editor'.
|
||||
*/
|
||||
$editor_settings = apply_filters( "block_editor_settings_{$editor_name}", $editor_settings, $editor_name );
|
||||
if ( 'post-editor' === $editor_name ) {
|
||||
$post = get_post();
|
||||
|
||||
|
||||
@@ -238,82 +238,47 @@ class WP_Test_Block_Editor extends WP_UnitTestCase {
|
||||
/**
|
||||
* @ticket 52920
|
||||
*/
|
||||
function test_get_block_editor_settings_returns_default_settings() {
|
||||
$this->assertSameSets(
|
||||
get_block_editor_settings( 'my-editor' ),
|
||||
get_default_block_editor_settings()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 52920
|
||||
*/
|
||||
function test_get_block_editor_settings_overrides_default_settings_my_editor() {
|
||||
function test_get_block_editor_settings_overrides_default_settings_all_editors() {
|
||||
function filter_allowed_block_types_my_editor() {
|
||||
return array( 'test/filtered-my-block' );
|
||||
}
|
||||
function filter_block_categories_my_editor() {
|
||||
return array(
|
||||
array(
|
||||
'slug' => 'filtered-my-category',
|
||||
'title' => 'Filtered My Category',
|
||||
'icon' => null,
|
||||
),
|
||||
);
|
||||
}
|
||||
function filter_block_editor_settings_my_editor( $editor_settings ) {
|
||||
$editor_settings['maxUploadFileSize'] = 12345;
|
||||
|
||||
return $editor_settings;
|
||||
}
|
||||
|
||||
add_filter( 'allowed_block_types_my-editor', 'filter_allowed_block_types_my_editor', 10, 1 );
|
||||
add_filter( 'block_editor_settings_my-editor', 'filter_block_editor_settings_my_editor', 10, 1 );
|
||||
add_filter( 'allowed_block_types_all', 'filter_allowed_block_types_my_editor', 10, 1 );
|
||||
add_filter( 'block_categories_all', 'filter_block_categories_my_editor', 10, 1 );
|
||||
add_filter( 'block_editor_settings_all', 'filter_block_editor_settings_my_editor', 10, 1 );
|
||||
|
||||
$settings = get_block_editor_settings( 'my-editor' );
|
||||
|
||||
remove_filter( 'allowed_block_types_my-editor', 'filter_allowed_block_types_my_editor' );
|
||||
remove_filter( 'block_editor_settings_my-editor', 'filter_block_editor_settings_my_editor' );
|
||||
remove_filter( 'allowed_block_types_all', 'filter_allowed_block_types_my_editor' );
|
||||
remove_filter( 'block_categories_all', 'filter_block_categories_my_editor' );
|
||||
remove_filter( 'block_editor_settings_all', 'filter_block_editor_settings_my_editor' );
|
||||
|
||||
$this->assertSameSets( array( 'test/filtered-my-block' ), $settings['allowedBlockTypes'] );
|
||||
$this->assertSame( 12345, $settings['maxUploadFileSize'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 52920
|
||||
*/
|
||||
function test_get_block_editor_settings_overrides_default_settings_any_editor() {
|
||||
function filter_allowed_block_types_any_editor() {
|
||||
return array( 'test/filtered-any-block' );
|
||||
}
|
||||
function filter_block_categories_any_editor() {
|
||||
return array(
|
||||
array(
|
||||
'slug' => 'filtered-any-category',
|
||||
'title' => 'Filtered Any Category',
|
||||
'icon' => null,
|
||||
),
|
||||
);
|
||||
}
|
||||
function filter_block_editor_settings_any_editor( $editor_settings ) {
|
||||
$editor_settings['maxUploadFileSize'] = 54321;
|
||||
|
||||
return $editor_settings;
|
||||
}
|
||||
|
||||
add_filter( 'allowed_block_types_all', 'filter_allowed_block_types_any_editor', 10, 1 );
|
||||
add_filter( 'block_categories_all', 'filter_block_categories_any_editor', 10, 1 );
|
||||
add_filter( 'block_editor_settings_all', 'filter_block_editor_settings_any_editor', 10, 1 );
|
||||
|
||||
$settings = get_block_editor_settings( 'any-editor' );
|
||||
|
||||
remove_filter( 'allowed_block_types_all', 'filter_allowed_block_types_any_editor' );
|
||||
remove_filter( 'block_categories_all', 'filter_block_categories_any_editor' );
|
||||
remove_filter( 'block_editor_settings_all', 'filter_block_editor_settings_any_editor' );
|
||||
|
||||
$this->assertSameSets( array( 'test/filtered-any-block' ), $settings['allowedBlockTypes'] );
|
||||
$this->assertSameSets(
|
||||
array(
|
||||
array(
|
||||
'slug' => 'filtered-any-category',
|
||||
'title' => 'Filtered Any Category',
|
||||
'slug' => 'filtered-my-category',
|
||||
'title' => 'Filtered My Category',
|
||||
'icon' => null,
|
||||
),
|
||||
),
|
||||
$settings['blockCategories']
|
||||
);
|
||||
$this->assertSame( 54321, $settings['maxUploadFileSize'] );
|
||||
$this->assertSame( 12345, $settings['maxUploadFileSize'] );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user