wppaste
WordPress

WP_Icons_Registry

Since
7.0.0
Source
wp-includes/class-wp-icons-registry.php:14
Core class used for interacting with registered icons.

Compatibility

WordPress
since 7.0.0
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

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 · 9

Source code

class WP_Icons_Registry {	/**	 * Registered icons array.	 *	 * @since 7.0.0	 * @var array[]	 */	protected $registered_icons = array(); 	/**	 * Container for the main instance of the class.	 *	 * @since 7.0.0	 * @var WP_Icons_Registry|null	 */	protected static $instance = null; 	/**	 * Constructor.	 *	 * WP_Icons_Registry is a singleton class, so keep this protected.	 *	 * Icons are populated via `_wp_register_default_icons()` during the	 * `init` action. Third-party icons can be registered via	 * {@see wp_register_icon()} once their collection is registered.	 *	 * @since 7.0.0	 */	protected function __construct() {} 	/**	 * Registers an icon.	 *	 * @since 7.0.0	 * @since 7.1.0 The icon name must be namespaced in the form "collection/icon-name".	 *	 * @param string $icon_name       Namespaced icon name in the form "collection/icon-name"	 *                                (e.g. "core/arrow-left").	 * @param array  $icon_properties {	 *     List of properties for the icon.	 *	 *     @type string $label     Required. A human-readable label for the icon.	 *     @type string $content   Optional. SVG markup for the icon.	 *                             If not provided, the content will be retrieved from the `file_path` if set.	 *                             If both `content` and `file_path` are not set, the icon will not be registered.	 *     @type string $file_path Optional. The full path to the file containing the icon content.	 * }	 * @return bool True if the icon was registered with success and false otherwise.	 */	public function register( $icon_name, $icon_properties ) {		if ( ! isset( $icon_name ) || ! is_string( $icon_name ) ) {			_doing_it_wrong(				__METHOD__,				__( 'Icon name must be a string.' ),				'7.0.0'			);			return false;		} 		// Require a namespaced name in the form "collection/icon-name".		if ( ! str_contains( $icon_name, '/' ) ) {			_doing_it_wrong(				__METHOD__,				__( 'Icon name must be namespaced in the form "collection/icon-name".' ),				'7.1.0'			);			return false;		} 		// Split the namespaced name into a collection slug and an unqualified icon name.		list( $collection, $unqualified_name ) = explode( '/', $icon_name, 2 ); 		if ( preg_match( '/[A-Z]/', $unqualified_name ) ) {			_doing_it_wrong(				__METHOD__,				__( 'Icon names must not contain uppercase characters.' ),				'7.1.0'			);			return false;		}

Changelog

Introduced in 7.0.0. One change between 7.0.4 and 7.1.0.

  1. 7.0.4
  2. 7.1.0

Signature, return type and hooks compared across 2 parsed releases.

7.1.0
Method unregister() added.verified against source
7.0.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 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.