WP_REST_Controller
- Since
- 4.7.0
- Source
wp-includes/rest-api/endpoints/class-wp-rest-controller.php:15
Core base controller for managing and interacting with REST API items.
Compatibility
- WordPress
- since 4.7.0
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0).
Properties · 3
$namespacestringprotected- The namespace of this controller's route.
$rest_basestringprotected- The base of this controller's route.
$schemaarrayprotected- Cached results of get_item_schema.
Methods · 27
- register_routes()Registers the routes for the objects of the controller.
- get_items_permissions_check()Checks if a given request has access to get items.
- get_items()Retrieves a collection of items.
- get_item_permissions_check()Checks if a given request has access to get a specific item.
- get_item()Retrieves one item from the collection.
- create_item_permissions_check()Checks if a given request has access to create items.
- create_item()Creates one item from the collection.
- update_item_permissions_check()Checks if a given request has access to update a specific item.
- update_item()Updates one item from the collection.
- delete_item_permissions_check()Checks if a given request has access to delete a specific item.
- delete_item()Deletes one item from the collection.
- prepare_item_for_database()Prepares one item for create or update operation.
- prepare_item_for_response()Prepares the item for the REST response.
- prepare_response_for_collection()Prepares a response for insertion into a collection.
- filter_response_by_context()Filters a response based on the context defined in the schema.
- get_item_schema()Retrieves the item's schema, conforming to JSON Schema.
- get_public_item_schema()Retrieves the item's schema for display / public consumption purposes.
- get_collection_params()Retrieves the query params for the collections.
- get_context_param()Retrieves the magical context param.
- add_additional_fields_to_object()Adds the values from additional fields to a data object.
- update_additional_fields_for_object()Updates the values of additional fields added to a data object.
- add_additional_fields_schema()Adds the schema from additional fields to a schema array.
- get_additional_fields()Retrieves all of the registered additional fields for a given object-type.
- get_object_type()Retrieves the object type this controller is responsible for managing.
- get_fields_for_response()Gets an array of fields to be included on the response.
- get_endpoint_args_for_item_schema()Retrieves an array of endpoint arguments from the item schema for the controller.
- sanitize_slug()Sanitizes the slug value.
Source code
#[AllowDynamicProperties]abstract class WP_REST_Controller { /** * The namespace of this controller's route. * * @since 4.7.0 * @var string */ protected $namespace; /** * The base of this controller's route. * * @since 4.7.0 * @var string */ protected $rest_base; /** * Cached results of get_item_schema. * * @since 5.3.0 * @var array */ protected $schema; /** * Registers the routes for the objects of the controller. * * @since 4.7.0 * * @see register_rest_route() */ public function register_routes() { _doing_it_wrong( 'WP_REST_Controller::register_routes', /* translators: %s: register_routes() */ sprintf( __( "Method '%s' must be overridden." ), __METHOD__ ), '4.7.0' ); } /** * Checks if a given request has access to get items. * * @since 4.7.0 * * @param WP_REST_Request $request Full details about the request. * @return true|WP_Error True if the request has read access, WP_Error object otherwise. */ public function get_items_permissions_check( $request ) { return new WP_Error( 'invalid-method', /* translators: %s: Method name. */ sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); } /** * Retrieves a collection of items. * * @since 4.7.0 * * @param WP_REST_Request $request Full details about the request. * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. */ public function get_items( $request ) { return new WP_Error( 'invalid-method', /* translators: %s: Method name. */ sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); } /** * Checks if a given request has access to get a specific item. *Changelog
Introduced in 4.7.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.7.7 tag, from
src/wp-includes/rest-api/endpoints/class-wp-rest-controller.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.