Registers a new ability category.
Description
Do not use this method directly. Instead, use the wp_register_ability_category() function.
See also
Parameters
$slugstringrequired- The unique slug for the ability category. Must contain only lowercase alphanumeric characters and dashes.
- mixed> $args { An associative array of arguments for the ability category.
@type string $label The human-readable label for the ability category.
@type string $description A description of the ability category.
@type array<string, mixed> $meta Optional. Additional metadata for the ability category.
}
Source
public function register( string $slug, array $args ): ?WP_Ability_Category {
if ( $this->is_registered( $slug ) ) {
_doing_it_wrong(
__METHOD__,
/* translators: %s: Ability category slug. */
sprintf( __( 'Ability category "%s" is already registered.' ), esc_html( $slug ) ),
'6.9.0'
);
return null;
}
if ( ! preg_match( '/^[a-z0-9]+(?:-[a-z0-9]+)*$/', $slug ) ) {
_doing_it_wrong(
__METHOD__,
__( 'Ability category slug must contain only lowercase alphanumeric characters and dashes.' ),
'6.9.0'
);
return null;
}
/**
* Filters the ability category arguments before they are validated and used to instantiate the ability category.
*
* @since 6.9.0
*
* @param array<string, mixed> $args {
* The arguments used to instantiate the ability category.
*
* @type string $label The human-readable label for the ability category.
* @type string $description A description of the ability category.
* @type array<string, mixed> $meta Optional. Additional metadata for the ability category.
* }
* @param string $slug The slug of the ability category.
*/
$args = apply_filters( 'wp_register_ability_category_args', $args, $slug );
try {
// WP_Ability_Category::prepare_properties() will throw an exception if the properties are invalid.
$category = new WP_Ability_Category( $slug, $args );
} catch ( InvalidArgumentException $e ) {
_doing_it_wrong(
__METHOD__,
$e->getMessage(),
'6.9.0'
);
return null;
}
$this->registered_categories[ $slug ] = $category;
return $category;
}
Hooks
- apply_filters( ‘wp_register_ability_category_args’,
array<string, ,string $slug ) Filters the ability category arguments before they are validated and used to instantiate the ability category.
Changelog
| Version | Description |
|---|---|
| 6.9.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.