Repository navigation
Icons: Move the public property from icons to collections #83277
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 all commits
49dfee8
15b9486
62b3d5c
f9a27a9
9e1603f
bd0d8ec
24a5d54
63b34ae
ac7f221
040514b
64cfc13
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 |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| https://github.com/WordPress/wordpress-develop/pull/13633 | ||
|
|
||
| * https://github.com/WordPress/gutenberg/pull/83277 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| <?php | ||
| /** | ||
| * Icons API: Gutenberg icon collections registry. | ||
| * | ||
| * @package gutenberg | ||
| */ | ||
|
|
||
| /** | ||
| * Adds collection visibility to the WordPress icon collections registry. | ||
| * | ||
| * @since 7.2.0 | ||
| */ | ||
| class WP_Icon_Collections_Registry_Gutenberg extends WP_Icon_Collections_Registry { | ||
|
|
||
| /** | ||
| * Registers an icon collection. | ||
| * | ||
| * @param string $collection_slug Icon collection slug. | ||
| * @param array $collection_properties { | ||
| * List of properties for the icon collection. | ||
| * | ||
| * @type string $label Required. A human-readable label for the icon collection. | ||
| * @type string $description Optional. A human-readable description for the icon collection. | ||
| * @type bool $public Optional. Whether the collection and its icons are exposed through | ||
| * the REST API and selectable in the editor's Icon block. Icons in | ||
| * non-public collections remain available via {@see wp_get_icon()}. | ||
| * Default true. | ||
| * } | ||
| * @return bool True if the collection was registered successfully, false otherwise. | ||
| */ | ||
| public function register( $collection_slug, $collection_properties ) { | ||
| if ( ! is_array( $collection_properties ) ) { | ||
| return parent::register( $collection_slug, $collection_properties ); | ||
| } | ||
|
|
||
| if ( array_key_exists( 'public', $collection_properties ) && ! is_bool( $collection_properties['public'] ) ) { | ||
| _doing_it_wrong( | ||
| __METHOD__, | ||
| __( 'Icon collection public property must be a boolean.', 'gutenberg' ), | ||
| '7.2.0' | ||
| ); | ||
| return false; | ||
| } | ||
|
|
||
| $public = $collection_properties['public'] ?? true; | ||
| unset( $collection_properties['public'] ); | ||
|
|
||
| if ( ! parent::register( $collection_slug, $collection_properties ) ) { | ||
| return false; | ||
| } | ||
|
|
||
| $this->registered_collections[ $collection_slug ]['public'] = $public; | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the shared registry instance, preserving existing collections. | ||
| * | ||
| * @return WP_Icon_Collections_Registry_Gutenberg The shared registry instance. | ||
| */ | ||
| public static function get_instance() { | ||
| if ( ! self::$instance instanceof self ) { | ||
| $original_registry = self::$instance; | ||
| $gutenberg_registry = new self(); | ||
|
|
||
| if ( null !== $original_registry ) { | ||
| foreach ( $original_registry->get_all_registered() as $collection ) { | ||
| $slug = $collection['slug']; | ||
| unset( $collection['slug'] ); | ||
| $gutenberg_registry->register( $slug, $collection ); | ||
| } | ||
| } | ||
|
|
||
| self::$instance = $gutenberg_registry; | ||
| } | ||
|
|
||
| return self::$instance; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Upgrades the shared collection registry before default collections are registered. | ||
| */ | ||
| function gutenberg_override_wp_icon_collections_registry() { | ||
| WP_Icon_Collections_Registry_Gutenberg::get_instance(); | ||
| } | ||
| add_action( 'init', 'gutenberg_override_wp_icon_collections_registry', -1 ); |
|
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. Similar to the collection registry, this is also intended to override the core REST controller. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| <?php | ||
| /** | ||
| * REST API: Gutenberg icon collections controller. | ||
| * | ||
| * Changes to this class should be synced to the corresponding class | ||
| * in WordPress core: src/wp-includes/rest-api/endpoints/class-wp-rest-icon-collections-controller.php. | ||
| * | ||
| * @package gutenberg | ||
| * @subpackage REST_API | ||
| */ | ||
|
|
||
| /** | ||
| * Gutenberg Icon Collections REST API Controller. | ||
| * | ||
| * @since 7.2.0 | ||
| */ | ||
| class WP_REST_Icon_Collections_Controller_Gutenberg extends WP_REST_Icon_Collections_Controller { | ||
|
|
||
| /** | ||
| * Retrieves all public icon collections. | ||
| * | ||
| * @param WP_REST_Request $request Full details about the request. | ||
| * @return WP_REST_Response Response object. | ||
| */ | ||
| public function get_items( $request ) { | ||
| $response = array(); | ||
| $collections = WP_Icon_Collections_Registry::get_instance()->get_all_registered(); | ||
| foreach ( $collections as $collection ) { | ||
| if ( ! $collection['public'] ) { | ||
| continue; | ||
| } | ||
| $prepared_collection = $this->prepare_item_for_response( $collection, $request ); | ||
| $response[] = $this->prepare_response_for_collection( $prepared_collection ); | ||
| } | ||
| return rest_ensure_response( $response ); | ||
| } | ||
|
|
||
| /** | ||
| * Retrieves a specific public icon collection. | ||
| * | ||
| * @param WP_REST_Request $request Full details about the request. | ||
| * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. | ||
| */ | ||
| public function get_item( $request ) { | ||
| $collection = WP_Icon_Collections_Registry::get_instance()->get_registered( $request['slug'] ); | ||
|
|
||
| if ( null !== $collection && ! $collection['public'] ) { | ||
| return new WP_Error( | ||
| 'rest_icon_collection_not_found', | ||
| sprintf( | ||
| /* translators: %s: Icon collection slug. */ | ||
| __( 'Icon collection not found: "%s".', 'gutenberg' ), | ||
| $request['slug'] | ||
| ), | ||
| array( 'status' => 404 ) | ||
| ); | ||
| } | ||
|
|
||
| return parent::get_item( $request ); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ | |
| - Redraw a further 236 icons as stroke-based for variable stroke-width support, following the convention introduced in [#78808](https://github.com/WordPress/gutenberg/pull/78808), and refine the already stroke-based `image` and `commentAuthorAvatar` drawings. Most retain their original footprint; the table icons, `capturePhoto`, and `image` are slightly smaller, and several drawings in the final batch change by design. ([#82540](https://github.com/WordPress/gutenberg/pull/82540), [#82754](https://github.com/WordPress/gutenberg/pull/82754)) | ||
| - `manifest.json`: The `public` property is now a tri-state. Omitting it keeps an icon in the JS library only; `true` ships it to WordPress Core and exposes it through the icons REST API, making it selectable in the Icon block; `false` ships it and registers it in the `core` collection for server-side use via `wp_get_icon()`, while hiding it from the REST API and the Icon block. ([#82634](https://github.com/WordPress/gutenberg/pull/82634)) | ||
| - The `brush`, `dashboard`, `link`, `media`, `page`, `pin`, `plugins`, `sites`, `tool`, `update` and `wordpress` icons now ship to WordPress Core as non-public icons: they are registered in the `core` collection and stay available to server-side code via `wp_get_icon()`, but are not exposed through the icons REST API and are not selectable in the Icon block. ([#82634](https://github.com/WordPress/gutenberg/pull/82634), [#79451](https://github.com/WordPress/gutenberg/pull/79451)) | ||
| - `manifest.json`: The `public` field now only controls whether an icon ships to WordPress Core ([#83277](https://github.com/WordPress/gutenberg/pull/83277)). | ||
|
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. Hmm maybe we can just remove the following old entry instead? It's still in the Unreleased section.
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. Admittedly, this is confusing, but I believe that changelog entries should basically be append-only and past entries should not be removed. As long as README.md reflects the latest specifications, it shouldn't be an issue. |
||
|
|
||
| ### Bug Fixes | ||
|
|
||
|
|
||
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.
This is for backward compatibility. I add a dedicated collection registry for Gutenberg to ensure that the latest registry supporting
publicproperties is always used across all WordPress versions supported by the Gutenberg plugin, regardless of the state of the core collection registry.