Skip to content

Commit a0128fe

Browse files
t-hamanoclaude
andcommitted
Icons: Add a core-admin collection for the admin interface.
The icons the admin bar and the admin menu are meant to render live in the `core` collection, so unregistering that collection to keep the default icon set out of the Icon block would also wipe out every icon in the dashboard chrome. A new `admin` property in the icons manifest marks the icons the admin interface renders. Those are registered in a `core-admin` collection in addition to `core`, always as non-public icons there, so that the collection contributes nothing to the icons REST API or to the Icon block. The manifest is generated from `gutenberg/packages/icons` by `grunt copy:icon-library-manifest`, so the `admin` flags arrive with the next Gutenberg hash bump. Backports WordPress/gutenberg#83261 to core. Props wildworks. See #66114. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 0a460e0 commit a0128fe

1 file changed

Lines changed: 22 additions & 7 deletions

File tree

‎src/wp-includes/icons.php‎

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ function wp_unregister_icon_collection( $slug ) {
4444
* @since 7.2.0 Added the `public` property.
4545
*
4646
* @param string $icon_name Namespaced icon name in the form "collection/icon-name"
47-
* (e.g. "my-plugin/arrow-left"). The "core" collection is
48-
* reserved for WordPress core icons; third-party code should
49-
* register icons under its own collection rather than the
50-
* "core" collection.
47+
* (e.g. "my-plugin/arrow-left"). The "core" and "core-admin"
48+
* collections are reserved for WordPress core icons; third-party
49+
* code should register icons under its own collection rather than
50+
* a reserved one.
5151
* @param array $args {
5252
* List of properties for the icon.
5353
*
@@ -94,11 +94,21 @@ function _wp_register_default_icon_collections() {
9494
'description' => __( 'Default icon collection.' ),
9595
)
9696
);
97+
wp_register_icon_collection(
98+
'core-admin',
99+
array(
100+
'label' => __( 'WordPress Admin' ),
101+
'description' => __( 'Icon collection used by the WordPress admin interface.' ),
102+
)
103+
);
97104
}
98105

99106
/**
100107
* Registers the default core icons from the manifest.
101108
*
109+
* Icons flagged as `admin` in the manifest are also registered in the "core-admin"
110+
* collection, always as non-public icons there.
111+
*
102112
* @since 7.1.0
103113
* @access private
104114
*/
@@ -114,17 +124,17 @@ function _wp_register_default_icons() {
114124
return;
115125
}
116126

117-
$collection = include $manifest_path;
127+
$manifest = include $manifest_path;
118128

119-
if ( empty( $collection ) ) {
129+
if ( empty( $manifest ) ) {
120130
wp_trigger_error(
121131
__FUNCTION__,
122132
__( 'Core icon collection manifest is empty or invalid.' )
123133
);
124134
return;
125135
}
126136

127-
foreach ( $collection as $icon_name => $icon_data ) {
137+
foreach ( $manifest as $icon_name => $icon_data ) {
128138
if (
129139
empty( $icon_data['filePath'] )
130140
|| ! is_string( $icon_data['filePath'] )
@@ -147,6 +157,11 @@ function _wp_register_default_icons() {
147157
}
148158

149159
wp_register_icon( 'core/' . $icon_name, $icon_args );
160+
161+
if ( ! empty( $icon_data['admin'] ) ) {
162+
$icon_args['public'] = false;
163+
wp_register_icon( 'core-admin/' . $icon_name, $icon_args );
164+
}
150165
}
151166
}
152167

0 commit comments

Comments
 (0)