wppaste
WordPress

WP_Icons_Registry::register( string $icon_name, array $icon_properties ): bool

Since
7.0.0, 7.1.0
Source
wp-includes/class-wp-icons-registry.php:63
Registers an icon.

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 2 of the 5 tracked releases, added in 7.1.0, and compiles on PHP 7.4 through 8.6-dev.

Parameters

$icon_namestring
Namespaced icon name in the form "collection/icon-name" (e.g. "core/arrow-left").
$icon_propertiesarray
List of properties for the icon.
  • $labelstring

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

    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.
  • $file_pathstring

    Optional. The full path to the file containing the icon content.

Return value

bool
True if the icon was registered with success and false otherwise.

Performance profile

How much work a call to WP_Icons_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–82

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

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_Icons_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 · 10 distinct outcomes

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

WhenInstructionsCalls it makes
always13–17__(), _doing_it_wrong()
isset($icon_name) && is_string($icon_name) && $icon_name27–29explode(), __(), _doing_it_wrong()
isset($icon_name) && is_string($icon_name) && $icon_name && !array_keys() && !$key46explode(), array_fill_keys(), array_keys(), __(), sprintf(), _doing_it_wrong()
isset($icon_name) && is_string($icon_name) && $icon_name && ->is_registered()47–64explode(), array_fill_keys(), array_keys(), ::WP_Icon_Collections_Registry(), ->is_registered(), __(), _doing_it_wrong()
isset($icon_name) && is_string($icon_name) && $icon_name && !->is_registered()49–50explode(), array_fill_keys(), array_keys(), ::WP_Icon_Collections_Registry(), ->is_registered(), __(), sprintf(), _doing_it_wrong()
isset($icon_name) && is_string($icon_name) && $icon_name && ->is_registered()62–67explode(), array_fill_keys(), array_keys(), ::WP_Icon_Collections_Registry(), ->is_registered(), ->is_registered(), __(), _doing_it_wrong()
isset($icon_name) && is_string($icon_name) && $icon_name64–69explode(), array_fill_keys(), array_keys(), ::WP_Icon_Collections_Registry(), ->is_registered(), ->is_registered(), name()
isset($icon_name) && is_string($icon_name) && $icon_name && ->is_registered() && empty($sanitized_icon_content)67–72explode(), array_fill_keys(), array_keys(), ::WP_Icon_Collections_Registry(), ->is_registered(), ->sanitize_icon_content(), __(), _doing_it_wrong()
isset($icon_name) && is_string($icon_name) && $icon_name && ->is_registered() && !empty($sanitized_icon_content)75–80explode(), array_fill_keys(), array_keys(), ::WP_Icon_Collections_Registry(), ->is_registered(), ->sanitize_icon_content(), ->is_registered(), __(), _doing_it_wrong()
isset($icon_name) && is_string($icon_name) && $icon_name && !empty($sanitized_icon_content)77–82explode(), array_fill_keys(), array_keys(), ::WP_Icon_Collections_Registry(), ->is_registered(), ->sanitize_icon_content(), ->is_registered(), name()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev19213–8219
8.519213–8219
8.419213–82199 fewer instructions than PHP 8.3
8.320113–9119
8.220113–9119
8.120113–9119
7.420113–9119

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

Source code

	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;		} 		if ( ! preg_match( '/^[a-z0-9](?:[a-z0-9_-]*[a-z0-9])?$/', $unqualified_name ) ) {			_doing_it_wrong(				__METHOD__,				__( 'Icon names must start and end with a lowercase letter or digit and contain only lowercase letters, digits, hyphens, and underscores.' ),				'7.1.0'			);			return false;		} 		$allowed_keys = array_fill_keys( array( 'label', 'content', 'file_path' ), 1 );		foreach ( array_keys( $icon_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 property: "%s".' ),						$key					),					'7.0.0'				);				return false;			}		} 		if ( ! WP_Icon_Collections_Registry::get_instance()->is_registered( $collection ) ) {			_doing_it_wrong(				__METHOD__,				sprintf(					/* translators: %s: Icon collection slug. */					__( 'Icon collection "%s" is not registered.' ),					$collection				),				'7.1.0'			);			return false;		} 		if ( ! isset( $icon_properties['label'] ) || ! is_string( $icon_properties['label'] ) ) {			_doing_it_wrong(				__METHOD__,				__( 'Icon label must be a string.' ),				'7.0.0'			);			return false;		} 		if (

Changelog

Introduced in 7.0.0. Unchanged from 7.0.4 through 7.1.0.

  1. 7.0.4
  2. 7.1.0

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

7.1.0
The icon name must be namespaced in the form "collection/icon-name".from the docblock
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.