From 19822523315c3ff1d9d87f5ed53cc2ca929da20b Mon Sep 17 00:00:00 2001 From: Grzegorz Ziolkowski Date: Thu, 22 Apr 2021 09:24:22 +0200 Subject: [PATCH] Update PHP filters for block editor to be a type agnostic --- lib/block-editor.php | 14 +++++++------- phpunit/block-editor-test.php | 24 +++++++----------------- 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/lib/block-editor.php b/lib/block-editor.php index 372da86eafa3b5..1b438b99b009ba 100644 --- a/lib/block-editor.php +++ b/lib/block-editor.php @@ -86,7 +86,7 @@ function gutenberg_get_block_categories( $editor_name_or_post ) { * * @param array[] $default_categories Array of categories for block types. */ - $block_categories = apply_filters( "block_categories_{$editor_name}", $default_categories ); + $block_categories = apply_filters( 'block_categories_all', $default_categories ); if ( 'post-editor' === $editor_name ) { $post = is_object( $editor_name_or_post ) ? $editor_name_or_post : get_post(); @@ -99,7 +99,7 @@ function gutenberg_get_block_categories( $editor_name_or_post ) { * @param array[] $block_categories Array of categories for block types. * @param WP_Post $post Post being loaded. */ - $block_categories = apply_filters_deprecated( 'block_categories', array( $block_categories, $post ), '5.8.0', "block_categories_{$editor_name}" ); + $block_categories = apply_filters_deprecated( 'block_categories', array( $block_categories, $post ), '5.8.0', 'block_categories_all' ); } return $block_categories; @@ -131,7 +131,7 @@ function gutenberg_get_allowed_block_types( $editor_name ) { * @param bool|array $allowed_block_types Array of block type slugs, or * boolean to enable/disable all. */ - $allowed_block_types = apply_filters( "allowed_block_types_{$editor_name}", $allowed_block_types ); + $allowed_block_types = apply_filters( 'allowed_block_types_all', $allowed_block_types ); if ( 'post-editor' === $editor_name ) { $post = get_post(); @@ -146,7 +146,7 @@ function gutenberg_get_allowed_block_types( $editor_name ) { * boolean to enable/disable all. * @param WP_Post $post The post resource data. */ - $allowed_block_types = apply_filters_deprecated( 'allowed_block_types', array( $allowed_block_types, $post ), '5.8.0', "allowed_block_types_{$editor_name}" ); + $allowed_block_types = apply_filters_deprecated( 'allowed_block_types', array( $allowed_block_types, $post ), '5.8.0', 'allowed_block_types_all' ); } return $allowed_block_types; @@ -267,13 +267,13 @@ function gutenberg_get_block_editor_settings( $editor_name, $custom_settings = a ); /** - * Filters the settings to pass to the block editor for a given editor type. + * Filters the settings to pass to the block editor for all editor types. * * @since 5.8.0 * * @param array $editor_settings Default editor settings. */ - $editor_settings = apply_filters( "block_editor_settings_{$editor_name}", $editor_settings ); + $editor_settings = apply_filters( 'block_editor_settings_all', $editor_settings ); if ( 'post-editor' === $editor_name ) { $post = get_post(); @@ -286,7 +286,7 @@ function gutenberg_get_block_editor_settings( $editor_name, $custom_settings = a * @param array $editor_settings Default editor settings. * @param WP_Post $post Post being edited. */ - $editor_settings = apply_filters_deprecated( 'block_editor_settings', array( $editor_settings, $post ), '5.8.0', "block_editor_settings_{$editor_name}" ); + $editor_settings = apply_filters_deprecated( 'block_editor_settings', array( $editor_settings, $post ), '5.8.0', 'block_editor_settings_all' ); } return $editor_settings; diff --git a/phpunit/block-editor-test.php b/phpunit/block-editor-test.php index 938b575cb80caf..154f2d9d1c66ab 100644 --- a/phpunit/block-editor-test.php +++ b/phpunit/block-editor-test.php @@ -239,16 +239,6 @@ function test_get_default_block_editor_settings() { $this->assertInternalType( 'int', $settings['maxUploadFileSize'] ); } - /** - * @ticket 52920 - */ - function test_get_block_editor_settings_returns_default_settings() { - $this->assertSameSets( - gutenberg_get_block_editor_settings( 'my-editor' ), - gutenberg_get_default_block_editor_settings() - ); - } - /** * @ticket 52920 */ @@ -265,21 +255,21 @@ function filter_block_categories_my_editor() { ), ); } - function filter_block_editor_settings_my_editor( $editor_settings ) { + function filter_block_editor_settings_all_editors( $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_categories_my-editor', 'filter_block_categories_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 = gutenberg_get_block_editor_settings( 'my-editor' ); - remove_filter( 'allowed_block_types_my-editor', 'filter_allowed_block_types_my_editor' ); - remove_filter( 'block_categories_my-editor', 'filter_block_categories_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->assertSameSets(