WP_Ability_Categories_Registry::register( string $slug,  $args ): WP_Ability_Category|null

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.
}

Return

WP_Ability_Category|null The registered ability category instance on success, null on failure.

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

VersionDescription
6.9.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.