[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/abilities-api/ -> class-wp-ability.php (summary)

Abilities API Defines WP_Ability class.

File Size: 680 lines (23 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

WP_Ability:: (19 methods):
  __construct()
  prepare_properties()
  get_name()
  get_label()
  get_description()
  get_category()
  get_input_schema()
  get_output_schema()
  get_meta()
  get_meta_item()
  normalize_input()
  validate_input()
  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_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.

param: mixed $input Optional. The raw input provided for the ability. Default `null`.
return: mixed The same input, or the default from schema, or `null` if default not set.

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.

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.

check_permissions( $input = null )   X-Ref
Checks whether the ability has the necessary permissions.

Please note that input is not automatically validated against the input schema.
Use `validate_input()` method to validate input before calling this method if needed.

param: mixed $input Optional. The valid input data for permission checking. Default `null`.
return: bool|WP_Error Whether the ability has the necessary permission.

do_execute( $input = null )   X-Ref
Executes the ability 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 input validation and running a permission check.
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 : Tue May 5 08:20:14 2026 Cross-referenced by PHPXref