[ 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: 617 lines (19 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

WP_Ability:: (18 methods):
  __construct()
  prepare_properties()
  get_name()
  get_label()
  get_description()
  get_category()
  get_input_schema()
  get_output_schema()
  get_meta()
  get_meta_item()
  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 when by WP_Abilities_Registry::register().

return: array<string, mixed> {
param: array<string, mixed> $args {

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.

return: mixed The value of the metadata item, or the default value if not found.
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`.

validate_input( $input = null )   X-Ref
Validates input data against the input schema.

return: true|WP_Error Returns true if valid or the WP_Error object if validation fails.
param: mixed $input Optional. The input data to validate. Default `null`.

invoke_callback( callable $callback, $input = null )   X-Ref
Invokes a callable, ensuring the input is passed through only if the input schema is defined.

return: mixed The result of the callable execution.
param: callable $callback The callable to invoke.
param: mixed    $input    Optional. The input data for the ability. Default `null`.

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.

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

do_execute( $input = null )   X-Ref
Executes the ability callback.

return: mixed|WP_Error The result of the ability execution, or WP_Error on failure.
param: mixed $input Optional. The input data for the ability. Default `null`.

validate_output( $output )   X-Ref
Validates output data against the output schema.

return: true|WP_Error Returns true if valid, or a WP_Error object if validation fails.
param: mixed $output The output data to validate.

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.

return: mixed|WP_Error The result of the ability execution, or WP_Error on failure.
param: mixed $input Optional. The input data for the ability. Default `null`.

__wakeup()   X-Ref
Wakeup magic method.


__sleep()   X-Ref
Sleep magic method.




Generated : Wed Oct 22 08:20:04 2025 Cross-referenced by PHPXref