wppaste
WordPress

WP_Icon_Collections_Registry::register( string $collection_slug, array $collection_properties ): bool

Since
7.1.0
Source
wp-includes/class-wp-icon-collections-registry.php:50
Registers an icon collection.

Compatibility

WordPress
since 7.1.0
PHP
7.4–8.6-dev
  • 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, and compiles on PHP 7.4 through 8.6-dev.

Parameters

$collection_slugstring
Icon collection slug.
$collection_propertiesarray
List of properties for the icon collection.
  • $labelstring

    Required. A human-readable label for the icon collection.
  • $descriptionstring

    Optional. A human-readable description for the icon collection.

Return value

bool
True if the collection was registered successfully, false otherwise.

Performance profile

How much work a call to WP_Icon_Collections_Registry::register() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Light

Touches nothing outside its own arguments.

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
13–46

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 116.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • hookthird-party callbacksdo_action()one call below WP_Icon_Collections_Registry::register()

Further down the call graph this can also reach query, option, cache, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 5 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Icon_Collections_Registry::register() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always13–17__(), _doing_it_wrong()
isset($collection_slug) && is_string($collection_slug) && $collection_slug21–23->is_registered(), __(), _doing_it_wrong()
isset($collection_slug) && is_string($collection_slug) && $collection_slug && !->is_registered() && is_array($collection_properties)35–44->is_registered(), array_fill_keys(), array_keys(), __(), _doing_it_wrong()
isset($collection_slug) && is_string($collection_slug) && $collection_slug && !->is_registered() && is_array($collection_properties) && !array_keys() && !$key40->is_registered(), array_fill_keys(), array_keys(), __(), sprintf(), _doing_it_wrong()
isset($collection_slug) && is_string($collection_slug) && $collection_slug && !->is_registered() && is_array($collection_properties) && isset($collection_properties)42–46->is_registered(), array_fill_keys(), array_keys(), slug()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev11613–4612
8.511613–4612
8.411613–46123 fewer instructions than PHP 8.3
8.311913–4912
8.211913–4912
8.111913–4912
7.411913–4912

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Uses · 3

Source code

	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'				);				return false;			}		} 		if ( ! isset( $collection_properties['label'] ) || ! is_string( $collection_properties['label'] ) ) {			_doing_it_wrong(				__METHOD__,				__( 'Icon collection label must be a string.' ),				'7.1.0'			);			return false;		} 		if ( isset( $collection_properties['description'] ) && ! is_string( $collection_properties['description'] ) ) {			_doing_it_wrong(				__METHOD__,				__( 'Icon collection description must be a string.' ),				'7.1.0'			);			return false;		} 		$defaults = array(			'description' => '',		); 		$collection = array_merge(			$defaults,			$collection_properties,			array( 'slug' => $collection_slug )		);

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.