wppaste
WordPress

WP_Icon_Collections_Registry

Since
7.1.0
Source
wp-includes/class-wp-icon-collections-registry.php:18
Core class used for interacting with registered icon collections.

Description

Icons are always associated with a single collection. Collections act as a namespace for icons and allow grouping icons coming from different sources (e.g. core, Font Awesome, Google Material Icons).

Compatibility

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

Present in 1 of the 5 tracked releases, added in 7.1.0.

Properties · 2

$registered_collectionsarray[]protected
Registered icon collections array.
$instanceWP_Icon_Collections_Registry|nullprotected static
Container for the main instance of the class.

Methods · 6

Source code

class WP_Icon_Collections_Registry { 	/**	 * Registered icon collections array.	 *	 * @since 7.1.0	 * @var array[]	 */	protected $registered_collections = array(); 	/**	 * Container for the main instance of the class.	 *	 * @since 7.1.0	 * @var WP_Icon_Collections_Registry|null	 */	protected static $instance = null; 	/**	 * Registers an icon collection.	 *	 * @since 7.1.0	 *	 * @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.	 * }	 * @return bool True if the collection was registered successfully, false otherwise.	 */	public function register( $collection_slug, $collection_properties ) {		if ( ! isset( $collection_slug ) || ! is_string( $collection_slug ) ) {			_doing_it_wrong(				__METHOD__,				__( 'Icon collection slug must be a string.' ),				'7.1.0'			);			return false;		} 		if ( ! preg_match( '/^[a-z0-9]([a-z0-9_-]*[a-z0-9])?$/', $collection_slug ) ) {			_doing_it_wrong(				__METHOD__,				__( 'Icon collection slug must start and end with a lowercase letter or digit and contain only lowercase letters, digits, hyphens, and underscores.' ),				'7.1.0'			);			return false;		} 		if ( $this->is_registered( $collection_slug ) ) {			_doing_it_wrong(				__METHOD__,				__( 'Icon collection is already registered.' ),				'7.1.0'			);			return false;		} 		if ( ! is_array( $collection_properties ) ) {			_doing_it_wrong(				__METHOD__,				__( 'Icon collection properties must be an array.' ),				'7.1.0'			);			return false;		} 		$allowed_keys = array_fill_keys( array( 'label', 'description' ), 1 );		foreach ( array_keys( $collection_properties ) as $key ) {			if ( ! array_key_exists( $key, $allowed_keys ) ) {				_doing_it_wrong(					__METHOD__,					sprintf(						/* translators: %s: The name of a user-provided key. */						__( 'Invalid icon collection property: "%s".' ),						$key					),					'7.1.0'

Changelog

Introduced in 7.1.0.

Signature, return type and hooks compared across 1 parsed release.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/class-wp-icon-collections-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.