WP_Icon_Collections_Registry::register
Registers an icon collection.
Метод класса: WP_Icon_Collections_Registry{}
Хуков нет.
Возвращает
bool. True if the collection was registered successfully, false otherwise.
Использование
$WP_Icon_Collections_Registry = new WP_Icon_Collections_Registry(); $WP_Icon_Collections_Registry->register( $collection_slug, $collection_properties );
- $collection_slug(строка) (обязательный)
- Icon collection slug.
- $collection_properties(массив) (обязательный)
List of properties for the icon collection.
-
label(строка)
Required. A human-readable label for the icon collection. - description(строка)
Optional. A human-readable description for the icon collection.
-
Список изменений
| С версии 7.1.0 | Введена. |
Код WP_Icon_Collections_Registry::register() WP Icon Collections Registry::register WP 7.1.2
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;
}