Repository navigation
[Gutenberg 23.5.2] Icons: Make WP_Icons_Registry::register() public - #80139
Conversation
The register() method was protected, so every caller outside the registry had to reach it through ReflectionMethod. Registering an icon is the registry's primary purpose and is meant to be called by plugins and by Gutenberg's own override routine, so the method should be part of the public API rather than something callers work around with reflection.
|
Warning: Type of PR label mismatch To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.
Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task. |
Core registers _wp_get_entity_view_config_post_type_* on the shared
get_entity_view_config_postType_{$post_type} hooks at priority 5, while the
plugin tried to remove them at the default priority 10. remove_filter() only
matches a callback at the priority it is given, so the core callbacks survived
and ran ahead of the plugin's own. They expect an object container, but this
branch's filter passes an array, so they fatal with "Call to a member function
set() on array" on every view config request.
Pass the priority reported by has_filter() to remove_filter() so the core
defaults are actually removed and only the plugin's array-based callbacks run.
Co-Authored-By: Claude <noreply@anthropic.com>
Follow-up to the previous commit, mirroring the registration logic that landed on trunk in #79809. Register the plugin's callbacks at priority 5, the same priority core uses for its own base definitions, so that third-party callbacks registered at the default priority compose on top of them regardless of registration order. Guard the registration with function_exists() so a post type that core covers but the plugin does not simply falls back to the default configuration instead of hooking a callback that does not exist. Co-Authored-By: Claude <noreply@anthropic.com>
| // has_filter() returns the priority the callback was registered at. | ||
| $wp_priority = has_filter( $hook, $wp_callback ); | ||
| if ( false !== $wp_priority ) { | ||
| remove_filter( $hook, $wp_callback, $wp_priority ); | ||
| } | ||
| if ( function_exists( $gb_callback ) ) { | ||
| // Base definitions run before the default priority, so third-party | ||
| // callbacks registered at the default compose on top of them | ||
| // regardless of registration order. | ||
| add_filter( $hook, $gb_callback, 5, 1 ); | ||
| } |
There was a problem hiding this comment.
This is to fix a CI error occurring on the release/23.5 branch. The cause was that the priority of core hooks was not being checked correctly, and thus they were not being removed. This priority check exists on the trunk branch but was missing on the release/23.5 branch.
As a result, if Gutenberg 23.5.1 is enabled on the WordPress trunk, Dataview will cause a critical error in the site editor.
Since we're at it, let's fix this issue in Gutenberg 23.5.2.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
…gistry Core registers its `core/` icons on `init` at priority 10 via `_wp_register_default_icons()`. The plugin swaps the registry singleton for WP_Icons_Registry_Gutenberg on `init` at priority 1, and that registry already populated the `core/` icons from the plugin's own manifest. Core's callback then re-registers the same names on the plugin registry, emitting an "Icon is already registered." notice for every core icon on plugin activation. Remove core's callback before it runs, reading its priority from has_action() so the removal keeps working if core changes it. Co-Authored-By: Claude <noreply@anthropic.com>
| /* | ||
| * The plugin registers the `core/` icons from its own manifest, so core's | ||
| * registration would only re-register the same names on this registry. | ||
| */ | ||
| $wp_priority = has_action( 'init', '_wp_register_default_icons' ); | ||
| if ( false !== $wp_priority ) { | ||
| remove_action( 'init', '_wp_register_default_icons', $wp_priority ); | ||
| } | ||
|
|
There was a problem hiding this comment.
This change should have been added in #77260, but it was missed. Without it, the Gutenberg plugin would display the following error after WordPress/wordpress-develop#11559 is committed.
Notice: Function WP_Icons_Registry_Gutenberg::register was called incorrectly. Icon is already registered. Please see Debugging in WordPress for more information. (This message was added in version 7.1.0.) in /var/www/src/wp-includes/functions.php on line 6213
I would like to submit a separate PR, as this error may also occur in Gutenberg trunk.
|
Flaky tests detected in 4f74a25. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/29218405726
|
|
The performance test is failing, and it seems to be an issue with the View Config API. Hopefully, once this PR is merged, the performance on the trunk branch will also be fixed. |
This PR is for the Gutenberg 23.5.2 release.
What?
In WordPress/wordpress-develop#11559, we are attempting to commit the icon APIs to core. This PR also introduces the public method
WP_Icons_Registry::register(). However, the version of the Gutenberg plugin installed in the CI for wordpress-develop is 23.5.1, and in this version, the overridden method is still private, causing the following error in the CI:This implies that a fatal error may occur in environments using the WordPress nightly and the Gutenberg plugin. This PR aims to prevent this fatal error in advance by making the overridden methods public.