Skip to content

[Gutenberg 23.5.2] Icons: Make WP_Icons_Registry::register() public - #80139

Merged
t-hamano merged 4 commits into
release/23.5from
release/23.5-icon-public-method
Jul 13, 2026
Merged

t-hamano merged 4 commits into
release/23.5from
release/23.5-icon-public-method

Conversation

@t-hamano

Copy link
Copy Markdown
Contributor

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:

PHP Fatal error:  Access level to WP_Icons_Registry_Gutenberg::register() must be public (as in class WP_Icons_Registry) in /var/www/src/wp-content/plugins/gutenberg/lib/class-wp-icons-registry-gutenberg.php on line 68

PHP Fatal error:  Access level to WP_Icons_Registry_Gutenberg::register() must be public (as in class WP_Icons_Registry) in /var/www/src/wp-content/plugins/gutenberg/lib/class-wp-icons-registry-gutenberg.php on line 68

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.

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.
@t-hamano t-hamano self-assigned this Jul 11, 2026
@t-hamano t-hamano added Gutenberg Plugin Issues or PRs related to Gutenberg Plugin management related efforts Backwards Compatibility Issues or PRs that impact backwards compatability labels Jul 11, 2026
@github-actions

Copy link
Copy Markdown

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.

  • Required label: Any label starting with [Type].
  • Labels found: Gutenberg Plugin, Backwards Compatibility.

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.

t-hamano and others added 2 commits July 11, 2026 22:25
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>
Comment on lines +791 to 801
// 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 );
}

@t-hamano t-hamano Jul 11, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@t-hamano
t-hamano marked this pull request as ready for review July 11, 2026 13:47
@t-hamano
t-hamano requested a review from spacedmonkey as a code owner July 11, 2026 13:47
@github-actions

github-actions Bot commented Jul 11, 2026 •

Copy link
Copy Markdown

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: tyxla <tyxla@git.wordpress.org>

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>
Comment on lines +244 to +252
/*
* 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 );
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions

Copy link
Copy Markdown

Flaky tests detected in 4f74a25.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/29218405726
📝 Reported issues:

@tyxla tyxla left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@t-hamano

Copy link
Copy Markdown
Contributor Author

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.

#80139 (comment)

@t-hamano
t-hamano merged commit 9f25d0c into release/23.5 Jul 13, 2026
105 of 108 checks passed
@t-hamano
t-hamano deleted the release/23.5-icon-public-method branch August 28, 2026 06:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Backwards Compatibility Issues or PRs that impact backwards compatability Gutenberg Plugin Issues or PRs related to Gutenberg Plugin management related efforts [Type] Task Issues or PRs that have been broken down into an individual action to take

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants