WP_Icons_Registry
- Since
- 7.0.0
- Source
wp-includes/class-wp-icons-registry.php:15
Core class used for interacting with registered icons.
Compatibility
- WordPress
- since 7.0.0
- 6.7.10
- 6.8.11
- 6.9.10
- 7.0.7
- 7.1.3
Present in 2 of the 5 tracked releases, added in 7.0.0.
Properties · 2
$registered_iconsarray[]protected- Registered icons array.
$instanceWP_Icons_Registry|nullprotected static- Container for the main instance of the class.
Methods · 8
- __construct()Constructor.
- register()Registers an icon.
- sanitize_icon_content()Sanitizes the icon SVG content.
- get_content()Retrieves the content of a registered icon.
- get_registered_icon()Retrieves an array containing the properties of a registered icon.
- get_registered_icons()Retrieves all registered icons.
- is_registered()Checks if an icon is registered.
- get_instance()Utility method to retrieve the main instance of the class.
Source code
class WP_Icons_Registry { /** * Registered icons array. * * @var array[] */ protected $registered_icons = array(); /** * Container for the main instance of the class. * * @var WP_Icons_Registry|null */ protected static $instance = null; /** * Constructor. * * WP_Icons_Registry is a singleton class, so keep this protected. * * For 7.0, the Icons Registry is closed for third-party icon registry, * serving only a subset of core icons. * * These icons are defined in @wordpress/packages (Gutenberg repository) as * SVG files and as entries in a single manifest file. On init, the * registry is loaded with those icons listed in the manifest. */ protected function __construct() { $icons_directory = __DIR__ . '/images/icon-library/'; $manifest_path = __DIR__ . '/assets/icon-library-manifest.php'; if ( ! is_readable( $manifest_path ) ) { wp_trigger_error( __METHOD__, __( 'Core icon collection manifest is missing or unreadable.' ) ); return; } $collection = include $manifest_path; if ( empty( $collection ) ) { wp_trigger_error( __METHOD__, __( 'Core icon collection manifest is empty or invalid.' ) ); return; } foreach ( $collection as $icon_name => $icon_data ) { if ( empty( $icon_data['filePath'] ) || ! is_string( $icon_data['filePath'] ) ) { _doing_it_wrong( __METHOD__, __( 'Core icon collection manifest must provide valid a "filePath" for each icon.' ), '7.0.0' ); return; } $this->register( 'core/' . $icon_name, array( 'label' => $icon_data['label'], 'filePath' => $icons_directory . $icon_data['filePath'], ) ); } } /** * Registers an icon. * * @param string $icon_name Icon name including namespace. * @param array $icon_properties { * List of properties for the icon. *Changelog
Introduced in 7.0.0. One change between 7.0.7 and 7.1.3.
Signature, return type and hooks compared across 2 parsed releases.
7.1.3
Method
unregister() added.verified against source7.0.0
Introduced.from the docblock
About this page
- Parsed data
- Generated from the wordpress-develop 7.0.7 tag, from
src/wp-includes/class-wp-icons-registry.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.