Registers an icon collection.
Parameters
$collection_slugstringrequired- Icon collection slug.
$collection_propertiesarrayrequired- List of properties for the icon collection.
labelstringRequired. A human-readable label for the icon collection.descriptionstringOptional. A human-readable description for the icon collection.
Source
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 )
);
$this->registered_collections[ $collection_slug ] = $collection;
return true;
}
Changelog
| Version | Description |
|---|---|
| 7.1.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.