Skip to content

SVG Icon API: Iteration for WordPress 7.1 #75715

@t-hamano

Description

@t-hamano

Important Issues and PRs:


We have stabilized three core features and shipped them in 7.0 Beta1:

  • WP_Icons_Registry class: The singleton class that loads core SVG icons from a manifest file, stores them, and exposes methods to check registration and retrieve icon data and content. There is currently no way to register a custom icon.
  • WP_REST_Icons_Controller: The REST API controller that exposes the icon registry over wp/v2/icons, letting the editor list icons and fetch a single icon by name.
  • Icon block (core/icon): The core block that retrieves a list of icons from the endpoint and lists them in a modal. The selected icon name is saved as an attribute, and the content is rendered server-side via the icon registry.

To make the Icon API more robust and extensible, I believe the following features are necessary:

Icon registry enhancements

  • Create public APIs (ref): I think we need APIs like the one below to allow consumers to filter the core icons and submit custom icons.
    • register_icon() function
    • unregister_icon() function
    • core-icons theme support: This is similar to the core-block-patterns theme support: if this support is disabled, all core icons will not be registered.
  • SVG sanitization (ref): There is no core function to properly sanitize SVGs, so a class method currently does the job, but it is not perfect, and there is room for improvement. See #75550 for more details. Maybe we could create a core function like sanitize_svg() instead.
    Icons Registry: improve SVG sanitizer #75550
  • Icon namespace validation (ref): Currently, custom icon registration is not allowed, and the namespace is hardcoded as core/. If we allow custom icon registration in the future, we will need to strictly check that the icon name follows the {namespace/icon-name} format.
    Icons: Enforce strict name validation in register method #76079

REST API enhancements

Category Support

Similar to block patterns, it should be possible to support categories: consumers will want to group icon sets based on their own brand.

  • Create a registry like WP_Icon_Categories_Registry
  • Create an endpoint like WP_REST_Icons_Categories_Controller
  • Create public APIs:
    • register_icon_category() function
    • unregister_icon_category() function

Create Icon Picker Modal component

  • To avoid increasing bundle size, the initial implementation built a custom picker without using DataViewPicker. (ref) Perhaps it should be possible to add a component like IconPickerModal to the @wordpress/block-editor package and load it from a block. This icon picker should be useful for blocks other than the Icon block as well.
    • DataViewsPicker based UI
    • Filter icons by category

Icon block enhancements

  • For example, the early prototype of the Icon Block had the following features, which we can consider as enhancements:
    • Flip icon (Vertical or Horizontal)
    • Rotate
    • Should we allow icons to have links?

Customizable icon support for other blocks

Some icons render their own hard-coded SVG content or symbols. Make those icons selectable via the Icon API.

Inline SVG icon (Inline format)

  • At the moment I don't know how to implement this. Perhaps it will be based on "BITS". (ref)

Metadata

Metadata

Assignees

Labels

[Block] IconAffects the Icon block[Feature] IconRelated to Icon registration API and Icon REST API[Type] IterationScoped iteration of an effort from a tracking issue or overview issue ideally for a major release.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions