| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Source view] [Print] [Project Stats]
Abilities API Defines WP_Ability class.
| File Size: | 1109 lines (42 kb) |
| Included or required: | 0 times |
| Referenced: | 0 times |
| Includes or requires: | 0 files |
WP_Ability:: (24 methods):
__construct()
prepare_properties()
get_name()
get_label()
get_description()
get_category()
get_input_schema()
get_output_schema()
get_meta()
get_required_capabilities()
get_meta_item()
normalize_input()
sanitize_input()
get_input_error()
validate_input()
prepare_input()
is_valid_capability_list()
invoke_callback()
check_permissions()
do_execute()
validate_output()
execute()
__wakeup()
__sleep()
Class: WP_Ability - X-Ref
Encapsulates the properties and methods related to a specific ability in the registry.| __construct( string $name, array $args ) X-Ref |
| Constructor. Do not use this constructor directly. Instead, use the `wp_register_ability()` function. param: string $name The name of the ability, with its namespace. param: array<string, mixed> $args { |
| prepare_properties( array $args ) X-Ref |
| Prepares and validates the properties used to instantiate the ability. Errors are thrown as exceptions instead of WP_Errors to allow for simpler handling and overloading. They are then caught and converted to a WP_Error by WP_Abilities_Registry::register(). param: array<string, mixed> $args { return: array<string, mixed> { |
| get_name() X-Ref |
| Retrieves the name of the ability, with its namespace. Example: `my-plugin/my-ability`. return: string The ability name, with its namespace. |
| get_label() X-Ref |
| Retrieves the human-readable label for the ability. return: string The human-readable ability label. |
| get_description() X-Ref |
| Retrieves the detailed description for the ability. return: string The detailed description for the ability. |
| get_category() X-Ref |
| Retrieves the ability category for the ability. return: string The ability category for the ability. |
| get_input_schema() X-Ref |
| Retrieves the input schema for the ability. return: array<string, mixed> The input schema for the ability. |
| get_output_schema() X-Ref |
| Retrieves the output schema for the ability. return: array<string, mixed> The output schema for the ability. |
| get_meta() X-Ref |
| Retrieves the metadata for the ability. return: array<string, mixed> The metadata for the ability. |
| get_required_capabilities() X-Ref |
| Retrieves the capabilities the current user must have to run the ability. return: list<string> The required capabilities. Empty when the ability declares none. |
| get_meta_item( string $key, $default_value = null ) X-Ref |
| Retrieves a specific metadata item for the ability. param: string $key The metadata key to retrieve. param: mixed $default_value Optional. The default value to return if the metadata item is not found. Default `null`. return: mixed The value of the metadata item, or the default value if not found. |
| normalize_input( $input = null ) X-Ref |
| Normalizes the input for the ability, applying the default value from the input schema when needed. When no input is provided and the input schema is defined with a top-level `default` key, this method returns the value of that key. If the input schema does not define a `default`, or if the input schema is empty, this method returns null. If input is provided, it is returned as-is. The {@see 'wp_ability_normalize_input'} filter fires after the built-in default-value handling, allowing plugins to transform the result. param: mixed $input Optional. The raw input provided for the ability. Default `null`. return: mixed The normalized input, or a `WP_Error` if a filter returned one. |
| sanitize_input( $input ) X-Ref |
| Sanitizes validated input against the input schema. Converts values to the types declared in the input schema, and applies schema format sanitization, such as stripping tags for `text-field` and sanitizing URLs for `uri`, using `rest_sanitize_value_from_schema()`. The input must be validated first. Sanitizing unvalidated input can remove unknown properties or cast invalid values, hiding validation errors. If sanitization produces an error, including in a nested value, an invalid input error is returned to prevent execution with unsanitized values. param: mixed $input Validated ability input. return: mixed|WP_Error Sanitized input, or `WP_Error` when it cannot be safely sanitized. |
| get_input_error( $value ) X-Ref |
| Retrieves the first WP_Error in a sanitized value. param: mixed $value The value to inspect. return: WP_Error|null The first error found, or null if the value contains no errors. |
| validate_input( $input = null ) X-Ref |
| Validates input data against the input schema. param: mixed $input Optional. The input data to validate. Default `null`. return: true|WP_Error Returns true if valid or the WP_Error object if validation fails. |
| prepare_input( $input = null ) X-Ref |
| Prepares input for the ability. Normalizes the input, validates it against the input schema, and then sanitizes it. `execute()` passes the result to the permission and execute callbacks. Validation runs before sanitization, so sanitization cannot make invalid input valid. param: mixed $input Optional. The raw input provided for the ability. Default `null`. return: mixed|WP_Error The prepared input, or `WP_Error` when any step fails. |
| is_valid_capability_list( $capabilities ) X-Ref |
| Checks whether a value is a list of non-empty capability strings. param: mixed $capabilities The value to check. return: bool Whether the value is a valid list of capabilities. |
| invoke_callback( callable $callback, $input = null ) X-Ref |
| Invokes a callable, ensuring the input is passed through only if the input schema is defined. param: callable $callback The callable to invoke. param: mixed $input Optional. The input data for the ability. Default `null`. return: mixed The result of the callable execution, or a `WP_Error` if the callback threw. |
| check_permissions( $input = null ) X-Ref |
| Checks whether the ability has the necessary permissions. This method does not prepare the input. Use `execute()` to run the full ability lifecycle, which prepares the input before calling this method. When calling this method directly, pass the input returned by `prepare_input()`, and stop if it returns a `WP_Error`. Skipping this step means the permission callback may receive different input than it does during `execute()`, such as a missing schema default or a string instead of an integer. The checks run in this order: 1. When the ability declares `required_capabilities`, each one is checked with `current_user_can()`. The check fails right away if one is missing. 2. When all capabilities pass and the ability has a `permission_callback`, it runs with the given input. The {@see 'wp_ability_permission_result'} filter fires on the final result, allowing plugins to override it. param: mixed $input Optional. The input prepared by `prepare_input()` for permission checking. return: bool|WP_Error Whether the ability has the necessary permission. |
| do_execute( $input = null ) X-Ref |
| Executes the ability callback. The {@see 'wp_ability_execute_result'} filter fires before this method returns, allowing plugins to transform the result produced by the registered `execute_callback`. param: mixed $input Optional. The input data for the ability. Default `null`. return: mixed|WP_Error The result of the ability execution, or WP_Error on failure. |
| validate_output( $output ) X-Ref |
| Validates output data against the output schema. param: mixed $output The output data to validate. return: true|WP_Error Returns true if valid, or a WP_Error object if validation fails. |
| execute( $input = null ) X-Ref |
| Executes the ability after preparing the input and checking permissions. Before returning the return value, it also validates the output. param: mixed $input Optional. The input data for the ability. Default `null`. return: mixed|WP_Error The result of the ability execution, or WP_Error on failure. |
| __wakeup() X-Ref |
| Wakeup magic method. |
| __sleep() X-Ref |
| Sleep magic method. |
| Generated : Sun Nov 22 08:20:01 2026 | Cross-referenced by PHPXref |