1111 * Registers a new icon collection.
1212 *
1313 * @since 7.1.0
14+ * @since 7.2.0 Added the `public` property.
1415 *
1516 * @param string $slug Icon collection slug.
1617 * @param array $args {
1718 * Arguments for registering an icon collection.
1819 *
1920 * @type string $label Required. A human-readable label for the icon collection.
2021 * @type string $description Optional. A human-readable description for the icon collection.
22+ * @type bool $public Optional. Whether the collection and its icons are exposed through
23+ * the REST API, and therefore selectable in the editor's icon picker.
24+ * Icons in non-public collections stay available to server-side code
25+ * via {@see wp_get_icon()}. Default true.
2126 * }
2227 * @return bool True if the icon collection was registered successfully, else false.
2328 */
@@ -41,13 +46,13 @@ function wp_unregister_icon_collection( $slug ) {
4146 * Registers a new icon.
4247 *
4348 * @since 7.1.0
44- * @since 7.2.0 Added the `public` and ` keywords` properties .
49+ * @since 7.2.0 Added the `keywords` property .
4550 *
4651 * @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 .
52+ * (e.g. "my-plugin/arrow-left"). The "core" and "core-admin"
53+ * collections are reserved for WordPress core icons; third-party
54+ * code should register icons under its own collection rather than
55+ * a reserved one .
5156 * @param array $args {
5257 * List of properties for the icon.
5358 *
@@ -56,10 +61,6 @@ function wp_unregister_icon_collection( $slug ) {
5661 * If not provided, the content will be retrieved from the `file_path` if set.
5762 * If both `content` and `file_path` are not set, the icon will not be registered.
5863 * @type string $file_path Optional. The full path to the file containing the icon content.
59- * @type bool $public Optional. Whether the icon is exposed through the REST API, and
60- * therefore selectable in the editor's icon picker. Non-public icons
61- * stay available to server-side code via {@see wp_get_icon()}.
62- * Default true.
6364 * @type string[] $keywords Optional. Additional search terms for the icon, matched by
6465 * `get_registered_icons()` alongside the name and label.
6566 * }
@@ -96,10 +97,18 @@ function _wp_register_default_icon_collections() {
9697 'description ' => __ ( 'Default icon collection. ' ),
9798 )
9899 );
100+ wp_register_icon_collection (
101+ 'core-admin ' ,
102+ array (
103+ 'label ' => __ ( 'WordPress Admin ' ),
104+ 'description ' => __ ( 'Icon collection used by the WordPress admin interface. ' ),
105+ 'public ' => false ,
106+ )
107+ );
99108}
100109
101110/**
102- * Registers the default core icons from the manifest.
111+ * Registers the default core and core-admin icons from the manifest.
103112 *
104113 * @since 7.1.0
105114 * @access private
@@ -139,20 +148,27 @@ function _wp_register_default_icons() {
139148 return ;
140149 }
141150
151+ if ( empty ( $ icon_data ['collections ' ] ) || ! is_array ( $ icon_data ['collections ' ] ) ) {
152+ _doing_it_wrong (
153+ __FUNCTION__ ,
154+ __ ( 'Core icon collection manifest must provide a non-empty "collections" array for each icon. ' ),
155+ '7.2.0 '
156+ );
157+ return ;
158+ }
159+
142160 $ icon_args = array (
143161 'label ' => $ icon_data ['label ' ],
144162 'file_path ' => $ icons_directory . $ icon_data ['filePath ' ],
145163 );
146164
147- if ( isset ( $ icon_data ['public ' ] ) ) {
148- $ icon_args ['public ' ] = $ icon_data ['public ' ];
149- }
150-
151165 if ( isset ( $ icon_data ['keywords ' ] ) ) {
152166 $ icon_args ['keywords ' ] = $ icon_data ['keywords ' ];
153167 }
154168
155- wp_register_icon ( 'core/ ' . $ icon_name , $ icon_args );
169+ foreach ( $ icon_data ['collections ' ] as $ collection_slug ) {
170+ wp_register_icon ( $ collection_slug . '/ ' . $ icon_name , $ icon_args );
171+ }
156172 }
157173}
158174
0 commit comments