-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Icons: Override WP_Icons_Registry singleton with Gutenberg icons registry #76455
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
Changes from 9 commits
a44fafe
b610839
55892ed
78ec29f
d0daaf6
491c9fb
493d230
7d47012
196e4b3
b3d1dae
c56e31c
6160049
a75a322
7309547
b30292f
bdd9972
8d80eae
55b6070
14fe750
a3027c6
fdd080f
60bafaa
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 |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| <?php | ||
|
|
||
| class Gutenberg_Icons_Registry_7_1 extends WP_Icons_Registry { | ||
| class WP_Icons_Registry_Gutenberg extends WP_Icons_Registry { | ||
| /** | ||
| * Modified to point $manifest_path to Gutenberg packages | ||
| */ | ||
|
|
@@ -87,3 +87,39 @@ public static function get_instance() { | |
| return self::$instance; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Forces WP_Icons_Registry_Gutenberg instantiation and overrides WP_Icons_Registry | ||
| * so that all code using WP_Icons_Registry::{method_name}() receives the Gutenberg | ||
| * registry. | ||
| */ | ||
| function gutenberg_override_wp_icons_registry() { | ||
| $reflection = new ReflectionClass( WP_Icons_Registry::class ); | ||
| $property = $reflection->getProperty( 'instance' ); | ||
| $property->setAccessible( true ); | ||
| $original_registry = $property->getValue( null ); | ||
| $gutenberg_registry = WP_Icons_Registry_Gutenberg::get_instance(); | ||
|
|
||
| // If the original registry was already instantiated, replay any icons outside | ||
| // the `core/` namespace onto the Gutenberg registry so they are not lost. | ||
| if ( null !== $original_registry ) { | ||
| $register_method = new ReflectionMethod( WP_Icons_Registry_Gutenberg::class, 'register' ); | ||
|
Contributor
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. Same here: different class, same deprecation.
Contributor
Author
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. Addressed in commit 60bafaa |
||
| $register_method->setAccessible( true ); | ||
| foreach ( $original_registry->get_registered_icons() as $icon ) { | ||
| if ( strpos( $icon['name'], 'core/' ) === 0 ) { | ||
| continue; | ||
| } | ||
| $icon_properties = array( 'label' => $icon['label'] ); | ||
| if ( ! empty( $icon['content'] ) ) { | ||
| $icon_properties['content'] = $icon['content']; | ||
| } elseif ( ! empty( $icon['filePath'] ) ) { | ||
| $icon_properties['filePath'] = $icon['filePath']; | ||
| } else { | ||
| continue; | ||
| } | ||
| $register_method->invoke( $gutenberg_registry, $icon['name'], $icon_properties ); | ||
| } | ||
| } | ||
| $property->setValue( null, $gutenberg_registry ); | ||
| } | ||
| add_action( 'init', 'gutenberg_override_wp_icons_registry', 1 ); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| <?php | ||
| /** | ||
| * REST API: Bundle WP_Icons_Registry_Gutenberg class instead of inheriting per WordPress version class | ||
| * | ||
| * Changes to this class should be synced to the corresponding class | ||
| * in WordPress core: src/wp-includes/rest-api/endpoints/class-wp-rest-icons-controller.php. | ||
| * | ||
| * @package gutenberg | ||
| * @subpackage REST_API | ||
| */ | ||
|
|
||
| /** | ||
| * Gutenberg Icons REST API Controller. | ||
| * | ||
| * @since 7.1.0 | ||
| */ | ||
| class WP_REST_Icons_Controller_Gutenberg extends WP_REST_Icons_Controller { | ||
| } | ||
|
Comment on lines
+17
to
+18
Contributor
Author
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. Currently, there is no need to expand the core controller, but it may be necessary in the future. |
||
|
Contributor
Author
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. My understanding is that this class was only needed internally to reference the Gutenberg icon registry. Now that we use reflection, this class should no longer be necessary.
Contributor
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. Correct |
This file was deleted.
This file was deleted.
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.
Considering the deprecation of
setAccessible, should we do as we did here?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.
Addressed in commit 60bafaa