[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/rest-api/endpoints/ -> class-wp-rest-abilities-v1-run-controller.php (summary)

REST API run controller for Abilities API.

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

Defines 1 class

WP_REST_Abilities_V1_Run_Controller:: (11 methods):
  register_routes()
  execute_ability()
  validate_request_method()
  check_ability_permissions()
  ensure_error_status()
  get_input_from_request()
  sanitize_input_for_ability()
  coerce_input_to_schema()
  input_contains_error()
  get_run_args()
  get_run_schema()


Class: WP_REST_Abilities_V1_Run_Controller  - X-Ref

Core controller used to execute abilities via the REST API.

register_routes()   X-Ref
Registers the routes for ability execution.


execute_ability( $request )   X-Ref
Executes an ability.

return: WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
param: WP_REST_Request $request Full details about the request.

validate_request_method( string $request_method, array $annotations )   X-Ref
Validates if the HTTP method matches the expected method for the ability based on its annotations.

return: true|WP_Error True on success, or WP_Error object on failure.
param: string                     $request_method The HTTP method of the request.
param: array<string, (null|bool)> $annotations    The ability annotations.

check_ability_permissions( $request )   X-Ref
Checks if a given request has permission to execute a specific ability.

return: true|WP_Error True if the request has execution permission, WP_Error object otherwise.
param: WP_REST_Request $request Full details about the request.

ensure_error_status( WP_Error $error, int $status )   X-Ref
Ensures a WP_Error object carries an HTTP status, adding a default when none is set.

return: WP_Error The error object, with a default status when needed.
param: WP_Error $error  Error object to update.
param: int      $status HTTP status code to add if not already present.

get_input_from_request( $request )   X-Ref
Extracts input parameters from the request.

return: mixed|null The input parameters.
param: WP_REST_Request $request The request object.

sanitize_input_for_ability( $input, $request )   X-Ref
Sanitizes the run input by coercing it to the ability's input schema.

Registered as the `input` argument `sanitize_callback` so that both
`check_ability_permissions()` and `execute_ability()` receive natively typed input
regardless of transport.

return: mixed Coerced input, or the raw input when it cannot be safely coerced.
param: mixed           $input   Raw input extracted from the request.
param: WP_REST_Request $request The request object.

coerce_input_to_schema( $input, WP_Ability $ability )   X-Ref
Coerces raw request input to the types declared in the ability input schema.

GET and DELETE deliver every scalar as a string ("10", "true") and a list as a single
comma-separated string, so without coercion an ability receives raw strings where its
schema declares integers, booleans, or arrays.

Coercion never changes what validation accepts. Input is coerced only when
{@see WP_Ability::validate_input()} already accepts it, and any error surfaced while
sanitizing falls back to the raw input, so `validate_input()` stays the single authority
on what is rejected.

return: mixed Coerced input, or the raw input when it cannot be safely coerced.
param: mixed      $input   Raw input extracted from the request.
param: WP_Ability $ability The ability being executed.

input_contains_error( $value )   X-Ref
Determines whether a sanitized value is, or contains, a WP_Error.

return: bool True if the value is, or contains, a WP_Error.
param: mixed $value The value to inspect.

get_run_args()   X-Ref
Retrieves the arguments for ability execution endpoint.

return: array<string, mixed> Arguments for the run endpoint.

get_run_schema()   X-Ref
Retrieves the schema for ability execution endpoint.

return: array<string, mixed> Schema for the run endpoint.



Generated : Sat Jul 25 08:20:20 2026 Cross-referenced by PHPXref