-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Plugin: Call deprecated hooks only when new filters not present #31027
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -380,8 +380,10 @@ function gutenberg_register_theme_block_category( $categories ) { | |
); | ||
return $categories; | ||
} | ||
|
||
add_filter( 'block_categories', 'gutenberg_register_theme_block_category' ); | ||
// This can be removed when plugin support requires WordPress 5.8.0+. | ||
if ( ! function_exists( 'get_default_block_categories' ) ) { | ||
add_filter( 'block_categories', 'gutenberg_register_theme_block_category' ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The question I have is whether these should be deprecated in the first place. I know you've thought about the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean to use <?php
// my-plugin.php
function my_plugin_block_categories( $categories, $post ) {
if ( $post->post_type !== 'post' ) {
return $categories;
}
return array_merge(
$categories,
array(
array(
'slug' => 'my-category',
'title' => __( 'My category', 'my-plugin' ),
'icon' => 'wordpress',
),
)
);
}
add_filter( 'block_categories', 'my_plugin_block_categories', 10, 2 ); If you have some ideas on how to address it safely then we should do it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mmm right :) if it's already receiving There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jeremyfelt raised the same issue in his comment on WordPress trac: https://core.trac.wordpress.org/ticket/52920#comment:24. |
||
} | ||
|
||
/** | ||
* Checks whether the current block type supports the feature requested. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -242,17 +242,7 @@ function test_get_default_block_editor_settings() { | |
/** | ||
* @ticket 52920 | ||
*/ | ||
function test_get_block_editor_settings_returns_default_settings() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test is bad conceptually, at some point the default settings and the block editor settings might diverge. More importantly, in the context of the plugin hooks applied change the output of |
||
$this->assertSameSets( | ||
gutenberg_get_block_editor_settings( 'my-editor' ), | ||
gutenberg_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' ); | ||
} | ||
|
@@ -271,15 +261,15 @@ function filter_block_editor_settings_my_editor( $editor_settings ) { | |
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( | ||
|
@@ -297,7 +287,6 @@ function filter_block_editor_settings_my_editor( $editor_settings ) { | |
|
||
/** | ||
* @ticket 52920 | ||
* @expectedDeprecated block_categories | ||
* @expectedDeprecated block_editor_settings | ||
*/ | ||
function test_get_block_editor_settings_deprecated_filter_post_editor() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I read WordPress/wordpress-develop#1118 (comment) and this issue's description I thought that we'd do this: check if
block_categories_${editor_name}
exists, and don't run the deprecatedblock_categories
filter if it does (same for the other filters). Would it work if we limit this PR to do that and so fixing the warnings whenWP_DEBUG
istrue
?Related: what do you think of not introducing a
*_all
filters at the moment? I think it'd be fine to do in the case all take the same config:I'm thinking that
*_all
is just a particular use case (all editor use the same settings) but there may be more (post and site use the same but widgets doesn't, etc), that's why I'm not fully convinced is worth introducing the_all
filters at the moment.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this mean? That there are subscribers (
has_filter
), or that there are consumers? I'm trying to understand how this would help.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a completely opposite direction that @youknowriad advocates for in #31027 (comment) and expands on in #31027 (comment).