Skip to content

Icons: Add APIs for collection and icon registration: SHA update test#12483

Closed
t-hamano wants to merge 23 commits into
WordPress:trunkfrom
t-hamano:64847-icon-api-extend-gb-sha-update-test
Closed

Icons: Add APIs for collection and icon registration: SHA update test#12483
t-hamano wants to merge 23 commits into
WordPress:trunkfrom
t-hamano:64847-icon-api-extend-gb-sha-update-test

Conversation

@t-hamano

Copy link
Copy Markdown
Contributor

This PR is to verify that the CI errors occurring in #11559 are resolved after the Gutenberg 23.5.2 release.

This PR is checked out from #11559, and only the Gutenberg SHA has been updated. The selected SHA is from WordPress/gutenberg#80139, and by including this PR in Gutenberg 23.5.2, the CI errors occurring in #11559 should be resolved.

t-hamano and others added 23 commits June 11, 2026 17:04
Align the icon registry's internal property with WordPress core's
snake_case array-key convention by renaming the registered icon property
from filePath to file_path. The conversion now happens only at the
registration/mapping boundary in the constructor: the generated manifest
keeps the upstream camelCase `filePath` key (as produced by Gutenberg),
which is read and mapped to the internal `file_path` property when each
icon is registered.

This updates the registry validation, allowed property keys,
`get_content()` lookup, and the related docblocks and error messages,
while leaving the manifest and the copy:icon-library-manifest Grunt task
untouched.

Co-Authored-By: Claude <noreply@anthropic.com>
Add the public icon collection and icon registration APIs on top of the
snake_case icon registry. Introduces WP_Icon_Collections_Registry,
icons.php (wp_register_icon/wp_unregister_icon/wp_register_icon_collection
and the default registration callbacks), the collection-scoped REST routes,
and the related tests.

Icon properties use the internal snake_case `file_path` key established in
the icon registry; the Gutenberg manifest's upstream camelCase `filePath`
key is read and mapped to `file_path` at the registration boundary.

Co-Authored-By: Claude <noreply@anthropic.com>
The icon registries warn via _doing_it_wrong() when a collection or icon
is already registered. Because tests such as the Customize widgets suite
fire `do_action( 'init' )` again after bootstrap, the default icon
registration runs twice and triggers those notices, failing unrelated
tests.

Match the existing pattern used for font and connector registration by
unhooking `_wp_register_default_icon_collections` and
`_wp_register_default_icons` from `init` after the first run.

Co-Authored-By: Claude <noreply@anthropic.com>
The REST icons controller now registers a per-collection route,
`/wp/v2/icons/(?P<namespace>[a-z][a-z-]*)`. Add it to the expected
routes list so test_expected_routes_in_schema reflects the registered
routes.

Co-Authored-By: Claude <noreply@anthropic.com>
The icons controller now exposes a `namespace` argument on the
collection endpoint and a new per-collection route. Regenerate the
QUnit fixtures so `git diff --exit-code` passes in CI.

Co-Authored-By: Claude <noreply@anthropic.com>
Custom icons can be registered with a `file_path`, but the path was never
checked before `file_get_contents()`, so a missing, unreadable, non-SVG, or
non-string path emitted a raw PHP warning and a misleading "invalid SVG
markup" error. Guard `get_content()` by resolving the path via `realpath()`,
then requiring an `.svg` extension, a regular file, and readability,
returning null with a clear message otherwise. Add tests covering valid and
invalid file paths.

Co-Authored-By: Claude <noreply@anthropic.com>
The collection slug pattern required a leading lowercase letter and rejected
digits, which excluded legitimate plugin slugs such as `a8c` or vendor names
containing numbers. Relax the validation to accept any combination of
lowercase alphanumeric characters and hyphens, and update the error message
and tests to match.

Co-Authored-By: Claude <noreply@anthropic.com>
…tag.

Several @SInCE 7.0.0 tags were accidentally dropped from properties and
internal methods while reworking the Icons API, leaving docblocks without
a version per the inline documentation standards. Restore them.

Also remove the stray blank line after the opening PHP tag to match the
rest of the core class files.

Co-Authored-By: Claude <noreply@anthropic.com>
Derive the collection from the icon name instead of passing it separately,
so an icon is always identified by a single namespaced name. The collection
prefix is now required; a non-namespaced name is rejected via _doing_it_wrong().

This drops the $collection parameter from wp_register_icon()/wp_unregister_icon()
and the "collection" icon property, and simplifies the cascade unregister when a
collection is removed. The "core" collection is reserved for WordPress core icons.

Co-Authored-By: Claude <noreply@anthropic.com>
# Conflicts:
#	src/wp-includes/class-wp-icons-registry.php
#	tests/phpunit/tests/icons/wpIconsRegistry.php
The REST controller tests depend on the default core icons, but those are
registered only once on `init` and the registration is then unhooked, so
once another suite resets the `WP_Icons_Registry` singleton in teardown the
core icons are gone. The affected tests were therefore skipped.

Re-register the default icons in `set_up()` when the registry is empty so the
tests run deterministically regardless of execution order, and drop the
`markTestSkipped()` guards.

Co-Authored-By: Claude <noreply@anthropic.com>
Relax the icon slug validation so names can start with a lowercase
letter or digit and contain lowercase letters, digits, hyphens, and
underscores. Many real-world icon sets use digits (e.g. html5, 500px,
w3c) and some consumers want underscores, which the previous regex
rejected.

Co-Authored-By: Claude <noreply@anthropic.com>
Port the equivalent of WordPress/gutenberg#79686 to core:

- Add WP_REST_Icon_Collections_Controller exposing /wp/v2/icon-collections
  and /wp/v2/icon-collections/<slug> so the editor can group icons by
  collection in the icon picker.
- Unify the naming rules for icon controllers and the collection registry
  on /^[a-z0-9]([a-z0-9_-]*[a-z0-9])?$/, allowing leading digits and
  underscores while still requiring alphanumeric boundaries. This fixes
  requests such as /wp/v2/icons/bootstrap-icons/0-circle-fill that
  previously 404'd.
- Add unit tests for the new collection controller and extend the
  collection registry tests to cover the updated slug rules.

Co-Authored-By: Claude <noreply@anthropic.com>
Replace the legacy false === strpos() idiom with str_contains(), which
expresses the intent more clearly and avoids the loose/strict comparison
pitfalls of the strpos()-against-false pattern. WordPress polyfills
str_contains() in wp-includes/compat.php, so it is safe on PHP 7.4.

Co-Authored-By: Claude <noreply@anthropic.com>
The collection label was already type-checked, but the optional
description was merged into the collection unvalidated, allowing
non-string values to violate the documented @type string contract.
Reject a non-string description with _doing_it_wrong() for consistency.

Co-Authored-By: Claude <noreply@anthropic.com>
The icon name/namespace regexes were tightened and an icon-collections
controller was added, but the expected route list in the schema test
was not updated to match, causing the full-set comparison to fail.

Co-Authored-By: Claude <noreply@anthropic.com>
The collection-scoped icons route used a `namespace` URL param whose
value is actually a collection slug, which both collided with the REST
API namespace concept and diverged from the icon `collection` field
that names the same relationship. Rename it to `collection` so the
same concept reads consistently across the icons endpoints.

Co-Authored-By: Claude <noreply@anthropic.com>
The icon REST routes changed on this branch: the collection-scoping route
param was renamed from `namespace` to `collection`, the slug pattern was
relaxed, and the `/wp/v2/icon-collections` route was added. The generated
fixture was left stale, so the PHPUnit job regenerated it and failed the
"version-controlled files are not modified" check.

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@t-hamano t-hamano closed this Jul 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant