Title: WP_REST_Controller
Published: December 6, 2016
Last modified: May 20, 2026

---

# class WP_REST_Controller {}

## In this article

 * [Methods](https://developer.wordpress.org/reference/classes/wp_rest_controller/?output_format=md#methods)
 * [Source](https://developer.wordpress.org/reference/classes/wp_rest_controller/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_rest_controller/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_rest_controller/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_rest_controller/?output_format=md#wp--skip-link--target)

Core base controller for managing and interacting with REST API items.

## 󠀁[Methods](https://developer.wordpress.org/reference/classes/wp_rest_controller/?output_format=md#methods)󠁿

| Name | Description | 
| [WP_REST_Controller::add_additional_fields_schema](https://developer.wordpress.org/reference/classes/wp_rest_controller/add_additional_fields_schema/) | Adds the schema from additional fields to a schema array. | 
| [WP_REST_Controller::add_additional_fields_to_object](https://developer.wordpress.org/reference/classes/wp_rest_controller/add_additional_fields_to_object/) | Adds the values from additional fields to a data object. | 
| [WP_REST_Controller::create_item](https://developer.wordpress.org/reference/classes/wp_rest_controller/create_item/) | Creates one item from the collection. | 
| [WP_REST_Controller::create_item_permissions_check](https://developer.wordpress.org/reference/classes/wp_rest_controller/create_item_permissions_check/) | Checks if a given request has access to create items. | 
| [WP_REST_Controller::delete_item](https://developer.wordpress.org/reference/classes/wp_rest_controller/delete_item/) | Deletes one item from the collection. | 
| [WP_REST_Controller::delete_item_permissions_check](https://developer.wordpress.org/reference/classes/wp_rest_controller/delete_item_permissions_check/) | Checks if a given request has access to delete a specific item. | 
| [WP_REST_Controller::filter_response_by_context](https://developer.wordpress.org/reference/classes/wp_rest_controller/filter_response_by_context/) | Filters a response based on the context defined in the schema. | 
| [WP_REST_Controller::get_additional_fields](https://developer.wordpress.org/reference/classes/wp_rest_controller/get_additional_fields/) | Retrieves all of the registered additional fields for a given object-type. | 
| [WP_REST_Controller::get_collection_params](https://developer.wordpress.org/reference/classes/wp_rest_controller/get_collection_params/) | Retrieves the query params for the collections. | 
| [WP_REST_Controller::get_context_param](https://developer.wordpress.org/reference/classes/wp_rest_controller/get_context_param/) | Retrieves the magical context param. | 
| [WP_REST_Controller::get_endpoint_args_for_item_schema](https://developer.wordpress.org/reference/classes/wp_rest_controller/get_endpoint_args_for_item_schema/) | Retrieves an array of endpoint arguments from the item schema for the controller. | 
| [WP_REST_Controller::get_fields_for_response](https://developer.wordpress.org/reference/classes/wp_rest_controller/get_fields_for_response/) | Gets an array of fields to be included on the response. | 
| [WP_REST_Controller::get_item](https://developer.wordpress.org/reference/classes/wp_rest_controller/get_item/) | Retrieves one item from the collection. | 
| [WP_REST_Controller::get_item_permissions_check](https://developer.wordpress.org/reference/classes/wp_rest_controller/get_item_permissions_check/) | Checks if a given request has access to get a specific item. | 
| [WP_REST_Controller::get_item_schema](https://developer.wordpress.org/reference/classes/wp_rest_controller/get_item_schema/) | Retrieves the item’s schema, conforming to JSON Schema. | 
| [WP_REST_Controller::get_items](https://developer.wordpress.org/reference/classes/wp_rest_controller/get_items/) | Retrieves a collection of items. | 
| [WP_REST_Controller::get_items_permissions_check](https://developer.wordpress.org/reference/classes/wp_rest_controller/get_items_permissions_check/) | Checks if a given request has access to get items. | 
| [WP_REST_Controller::get_object_type](https://developer.wordpress.org/reference/classes/wp_rest_controller/get_object_type/) | Retrieves the object type this controller is responsible for managing. | 
| [WP_REST_Controller::get_public_item_schema](https://developer.wordpress.org/reference/classes/wp_rest_controller/get_public_item_schema/) | Retrieves the item’s schema for display / public consumption purposes. | 
| [WP_REST_Controller::prepare_item_for_database](https://developer.wordpress.org/reference/classes/wp_rest_controller/prepare_item_for_database/) | Prepares one item for create or update operation. | 
| [WP_REST_Controller::prepare_item_for_response](https://developer.wordpress.org/reference/classes/wp_rest_controller/prepare_item_for_response/) | Prepares the item for the REST response. | 
| [WP_REST_Controller::prepare_response_for_collection](https://developer.wordpress.org/reference/classes/wp_rest_controller/prepare_response_for_collection/) | Prepares a response for insertion into a collection. | 
| [WP_REST_Controller::register_routes](https://developer.wordpress.org/reference/classes/wp_rest_controller/register_routes/) | Registers the routes for the objects of the controller. | 
| [WP_REST_Controller::sanitize_slug](https://developer.wordpress.org/reference/classes/wp_rest_controller/sanitize_slug/) | Sanitizes the slug value. | 
| [WP_REST_Controller::update_additional_fields_for_object](https://developer.wordpress.org/reference/classes/wp_rest_controller/update_additional_fields_for_object/) | Updates the values of additional fields added to a data object. | 
| [WP_REST_Controller::update_item](https://developer.wordpress.org/reference/classes/wp_rest_controller/update_item/) | Updates one item from the collection. | 
| [WP_REST_Controller::update_item_permissions_check](https://developer.wordpress.org/reference/classes/wp_rest_controller/update_item_permissions_check/) | Checks if a given request has access to update a specific item. |

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_rest_controller/?output_format=md#source)󠁿

    ```php
    #[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.
    	 *
    	 * @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 for the item, WP_Error object otherwise.
    	 */
    	public function get_item_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 one item from the collection.
    	 *
    	 * @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_item( $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 create items.
    	 *
    	 * @since 4.7.0
    	 *
    	 * @param WP_REST_Request $request Full details about the request.
    	 * @return true|WP_Error True if the request has access to create items, WP_Error object otherwise.
    	 */
    	public function create_item_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 )
    		);
    	}

    	/**
    	 * Creates one item from the collection.
    	 *
    	 * @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 create_item( $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 update a specific item.
    	 *
    	 * @since 4.7.0
    	 *
    	 * @param WP_REST_Request $request Full details about the request.
    	 * @return true|WP_Error True if the request has access to update the item, WP_Error object otherwise.
    	 */
    	public function update_item_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 )
    		);
    	}

    	/**
    	 * Updates one item from the collection.
    	 *
    	 * @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 update_item( $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 delete a specific item.
    	 *
    	 * @since 4.7.0
    	 *
    	 * @param WP_REST_Request $request Full details about the request.
    	 * @return true|WP_Error True if the request has access to delete the item, WP_Error object otherwise.
    	 */
    	public function delete_item_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 )
    		);
    	}

    	/**
    	 * Deletes one item from the collection.
    	 *
    	 * @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 delete_item( $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 )
    		);
    	}

    	/**
    	 * Prepares one item for create or update operation.
    	 *
    	 * @since 4.7.0
    	 *
    	 * @param WP_REST_Request $request Request object.
    	 * @return object|WP_Error The prepared item, or WP_Error object on failure.
    	 */
    	protected function prepare_item_for_database( $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 )
    		);
    	}

    	/**
    	 * Prepares the item for the REST response.
    	 *
    	 * @since 4.7.0
    	 *
    	 * @param mixed           $item    WordPress representation of the item.
    	 * @param WP_REST_Request $request Request object.
    	 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
    	 */
    	public function prepare_item_for_response( $item, $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 )
    		);
    	}

    	/**
    	 * Prepares a response for insertion into a collection.
    	 *
    	 * @since 4.7.0
    	 *
    	 * @param WP_REST_Response $response Response object.
    	 * @return array|mixed Response data, ready for insertion into collection data.
    	 */
    	public function prepare_response_for_collection( $response ) {
    		if ( ! ( $response instanceof WP_REST_Response ) ) {
    			return $response;
    		}

    		$data   = (array) $response->get_data();
    		$server = rest_get_server();
    		$links  = $server::get_compact_response_links( $response );

    		if ( ! empty( $links ) ) {
    			$data['_links'] = $links;
    		}

    		return $data;
    	}

    	/**
    	 * Filters a response based on the context defined in the schema.
    	 *
    	 * @since 4.7.0
    	 *
    	 * @param array  $response_data Response data to filter.
    	 * @param string $context       Context defined in the schema.
    	 * @return array Filtered response.
    	 */
    	public function filter_response_by_context( $response_data, $context ) {

    		$schema = $this->get_item_schema();

    		return rest_filter_response_by_context( $response_data, $schema, $context );
    	}

    	/**
    	 * Retrieves the item's schema, conforming to JSON Schema.
    	 *
    	 * @since 4.7.0
    	 *
    	 * @return array Item schema data.
    	 */
    	public function get_item_schema() {
    		return $this->add_additional_fields_schema( array() );
    	}

    	/**
    	 * Retrieves the item's schema for display / public consumption purposes.
    	 *
    	 * @since 4.7.0
    	 *
    	 * @return array Public item schema data.
    	 */
    	public function get_public_item_schema() {

    		$schema = $this->get_item_schema();

    		if ( ! empty( $schema['properties'] ) ) {
    			foreach ( $schema['properties'] as &$property ) {
    				unset( $property['arg_options'] );
    			}
    		}

    		return $schema;
    	}

    	/**
    	 * Retrieves the query params for the collections.
    	 *
    	 * @since 4.7.0
    	 *
    	 * @return array Query parameters for the collection.
    	 */
    	public function get_collection_params() {
    		return array(
    			'context'  => $this->get_context_param(),
    			'page'     => array(
    				'description'       => __( 'Current page of the collection.' ),
    				'type'              => 'integer',
    				'default'           => 1,
    				'sanitize_callback' => 'absint',
    				'validate_callback' => 'rest_validate_request_arg',
    				'minimum'           => 1,
    			),
    			'per_page' => array(
    				'description'       => __( 'Maximum number of items to be returned in result set.' ),
    				'type'              => 'integer',
    				'default'           => 10,
    				'minimum'           => 1,
    				'maximum'           => 100,
    				'sanitize_callback' => 'absint',
    				'validate_callback' => 'rest_validate_request_arg',
    			),
    			'search'   => array(
    				'description'       => __( 'Limit results to those matching a string.' ),
    				'type'              => 'string',
    				'sanitize_callback' => 'sanitize_text_field',
    				'validate_callback' => 'rest_validate_request_arg',
    			),
    		);
    	}

    	/**
    	 * Retrieves the magical context param.
    	 *
    	 * Ensures consistent descriptions between endpoints, and populates enum from schema.
    	 *
    	 * @since 4.7.0
    	 *
    	 * @param array $args Optional. Additional arguments for context parameter. Default empty array.
    	 * @return array Context parameter details.
    	 */
    	public function get_context_param( $args = array() ) {
    		$param_details = array(
    			'description'       => __( 'Scope under which the request is made; determines fields present in response.' ),
    			'type'              => 'string',
    			'sanitize_callback' => 'sanitize_key',
    			'validate_callback' => 'rest_validate_request_arg',
    		);

    		$schema = $this->get_item_schema();

    		if ( empty( $schema['properties'] ) ) {
    			return array_merge( $param_details, $args );
    		}

    		$contexts = array();

    		foreach ( $schema['properties'] as $attributes ) {
    			if ( ! empty( $attributes['context'] ) ) {
    				$contexts = array_merge( $contexts, $attributes['context'] );
    			}
    		}

    		if ( ! empty( $contexts ) ) {
    			$param_details['enum'] = array_unique( $contexts );
    			rsort( $param_details['enum'] );
    		}

    		return array_merge( $param_details, $args );
    	}

    	/**
    	 * Adds the values from additional fields to a data object.
    	 *
    	 * @since 4.7.0
    	 *
    	 * @param array           $response_data Prepared response array.
    	 * @param WP_REST_Request $request       Full details about the request.
    	 * @return array Modified data object with additional fields.
    	 */
    	protected function add_additional_fields_to_object( $response_data, $request ) {

    		$additional_fields = $this->get_additional_fields();

    		$requested_fields = $this->get_fields_for_response( $request );

    		foreach ( $additional_fields as $field_name => $field_options ) {
    			if ( ! $field_options['get_callback'] ) {
    				continue;
    			}

    			if ( ! rest_is_field_included( $field_name, $requested_fields ) ) {
    				continue;
    			}

    			$response_data[ $field_name ] = call_user_func(
    				$field_options['get_callback'],
    				$response_data,
    				$field_name,
    				$request,
    				$this->get_object_type()
    			);
    		}

    		return $response_data;
    	}

    	/**
    	 * Updates the values of additional fields added to a data object.
    	 *
    	 * @since 4.7.0
    	 *
    	 * @param object          $data_object Data model like WP_Term or WP_Post.
    	 * @param WP_REST_Request $request     Full details about the request.
    	 * @return true|WP_Error True on success, WP_Error object if a field cannot be updated.
    	 */
    	protected function update_additional_fields_for_object( $data_object, $request ) {
    		$additional_fields = $this->get_additional_fields();

    		foreach ( $additional_fields as $field_name => $field_options ) {
    			if ( ! $field_options['update_callback'] ) {
    				continue;
    			}

    			// Don't run the update callbacks if the data wasn't passed in the request.
    			if ( ! isset( $request[ $field_name ] ) ) {
    				continue;
    			}

    			$result = call_user_func(
    				$field_options['update_callback'],
    				$request[ $field_name ],
    				$data_object,
    				$field_name,
    				$request,
    				$this->get_object_type()
    			);

    			if ( is_wp_error( $result ) ) {
    				return $result;
    			}
    		}

    		return true;
    	}

    	/**
    	 * Adds the schema from additional fields to a schema array.
    	 *
    	 * The type of object is inferred from the passed schema.
    	 *
    	 * @since 4.7.0
    	 *
    	 * @param array $schema Schema array.
    	 * @return array Modified Schema array.
    	 */
    	protected function add_additional_fields_schema( $schema ) {
    		if ( empty( $schema['title'] ) ) {
    			return $schema;
    		}

    		// Can't use $this->get_object_type otherwise we cause an inf loop.
    		$object_type = $schema['title'];

    		$additional_fields = $this->get_additional_fields( $object_type );

    		foreach ( $additional_fields as $field_name => $field_options ) {
    			if ( ! $field_options['schema'] ) {
    				continue;
    			}

    			$schema['properties'][ $field_name ] = $field_options['schema'];
    		}

    		return $schema;
    	}

    	/**
    	 * Retrieves all of the registered additional fields for a given object-type.
    	 *
    	 * @since 4.7.0
    	 *
    	 * @global array $wp_rest_additional_fields Holds registered fields, organized by object type.
    	 *
    	 * @param string $object_type Optional. The object type.
    	 * @return array Registered additional fields (if any), empty array if none or if the object type
    	 *               could not be inferred.
    	 */
    	protected function get_additional_fields( $object_type = null ) {
    		global $wp_rest_additional_fields;

    		if ( ! $object_type ) {
    			$object_type = $this->get_object_type();
    		}

    		if ( ! $object_type ) {
    			return array();
    		}

    		if ( ! $wp_rest_additional_fields || ! isset( $wp_rest_additional_fields[ $object_type ] ) ) {
    			return array();
    		}

    		return $wp_rest_additional_fields[ $object_type ];
    	}

    	/**
    	 * Retrieves the object type this controller is responsible for managing.
    	 *
    	 * @since 4.7.0
    	 *
    	 * @return string Object type for the controller.
    	 */
    	protected function get_object_type() {
    		$schema = $this->get_item_schema();

    		if ( ! $schema || ! isset( $schema['title'] ) ) {
    			return null;
    		}

    		return $schema['title'];
    	}

    	/**
    	 * Gets an array of fields to be included on the response.
    	 *
    	 * Included fields are based on item schema and `_fields=` request argument.
    	 *
    	 * @since 4.9.6
    	 *
    	 * @param WP_REST_Request $request Full details about the request.
    	 * @return string[] Fields to be included in the response.
    	 */
    	public function get_fields_for_response( $request ) {
    		$schema     = $this->get_item_schema();
    		$properties = $schema['properties'] ?? array();

    		$additional_fields = $this->get_additional_fields();

    		foreach ( $additional_fields as $field_name => $field_options ) {
    			/*
    			 * For back-compat, include any field with an empty schema
    			 * because it won't be present in $this->get_item_schema().
    			 */
    			if ( is_null( $field_options['schema'] ) ) {
    				$properties[ $field_name ] = $field_options;
    			}
    		}

    		// Exclude fields that specify a different context than the request context.
    		$context = $request['context'];
    		if ( $context ) {
    			foreach ( $properties as $name => $options ) {
    				if ( ! empty( $options['context'] ) && ! in_array( $context, $options['context'], true ) ) {
    					unset( $properties[ $name ] );
    				}
    			}
    		}

    		$fields = array_keys( $properties );

    		/*
    		 * '_links' and '_embedded' are not typically part of the item schema,
    		 * but they can be specified in '_fields', so they are added here as a
    		 * convenience for checking with rest_is_field_included().
    		 */
    		$fields[] = '_links';
    		if ( $request->has_param( '_embed' ) ) {
    			$fields[] = '_embedded';
    		}

    		$fields = array_unique( $fields );

    		if ( ! isset( $request['_fields'] ) ) {
    			return $fields;
    		}
    		$requested_fields = wp_parse_list( $request['_fields'] );
    		if ( 0 === count( $requested_fields ) ) {
    			return $fields;
    		}
    		// Trim off outside whitespace from the comma delimited list.
    		$requested_fields = array_map( 'trim', $requested_fields );
    		// Always persist 'id', because it can be needed for add_additional_fields_to_object().
    		if ( in_array( 'id', $fields, true ) ) {
    			$requested_fields[] = 'id';
    		}
    		// Return the list of all requested fields which appear in the schema.
    		return array_reduce(
    			$requested_fields,
    			static function ( $response_fields, $field ) use ( $fields ) {
    				if ( in_array( $field, $fields, true ) ) {
    					$response_fields[] = $field;
    					return $response_fields;
    				}
    				// Check for nested fields if $field is not a direct match.
    				$nested_fields = explode( '.', $field );
    				/*
    				 * A nested field is included so long as its top-level property
    				 * is present in the schema.
    				 */
    				if ( in_array( $nested_fields[0], $fields, true ) ) {
    					$response_fields[] = $field;
    				}
    				return $response_fields;
    			},
    			array()
    		);
    	}

    	/**
    	 * Retrieves an array of endpoint arguments from the item schema for the controller.
    	 *
    	 * @since 4.7.0
    	 *
    	 * @param string $method Optional. HTTP method of the request. The arguments for `CREATABLE` requests are
    	 *                       checked for required values and may fall-back to a given default, this is not done
    	 *                       on `EDITABLE` requests. Default WP_REST_Server::CREATABLE.
    	 * @return array Endpoint arguments.
    	 */
    	public function get_endpoint_args_for_item_schema( $method = WP_REST_Server::CREATABLE ) {
    		return rest_get_endpoint_args_for_schema( $this->get_item_schema(), $method );
    	}

    	/**
    	 * Sanitizes the slug value.
    	 *
    	 * {@internal We can't use sanitize_title() directly, as the second
    	 * parameter is the fallback title, which would end up being set to the
    	 * request object.}
    	 *
    	 * @since 4.7.0
    	 *
    	 * @link https://github.com/WP-API/WP-API/issues/1585
    	 *
    	 * @todo Remove this in favour of https://core.trac.wordpress.org/ticket/34659
    	 *
    	 * @param string $slug Slug value passed in request.
    	 * @return string Sanitized value for the slug.
    	 */
    	public function sanitize_slug( $slug ) {
    		return sanitize_title( $slug );
    	}
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-controller.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/rest-api/endpoints/class-wp-rest-controller.php#L15)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/rest-api/endpoints/class-wp-rest-controller.php#L15-L681)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_rest_controller/?output_format=md#related)󠁿

| Used by | Description | 
| [WP_REST_Icons_Controller](https://developer.wordpress.org/reference/classes/wp_rest_icons_controller/)`wp-includes/rest-api/endpoints/class-wp-rest-icons-controller.php` |

Controller which provides a REST endpoint for the editor to read registered icons. For the time being, only core icons are available, which are defined in a single manifest file (wp-includes/assets/icon-library-manifest.php).

  | 
| [WP_REST_Abilities_V1_Categories_Controller](https://developer.wordpress.org/reference/classes/wp_rest_abilities_v1_categories_controller/)`wp-includes/rest-api/endpoints/class-wp-rest-abilities-v1-categories-controller.php` |

Core controller used to access ability categories via the REST API.

  | 
| [WP_REST_Abilities_V1_Run_Controller](https://developer.wordpress.org/reference/classes/wp_rest_abilities_v1_run_controller/)`wp-includes/rest-api/endpoints/class-wp-rest-abilities-v1-run-controller.php` |

Core controller used to execute abilities via the REST API.

  | 
| [WP_REST_Abilities_V1_List_Controller](https://developer.wordpress.org/reference/classes/wp_rest_abilities_v1_list_controller/)`wp-includes/rest-api/endpoints/class-wp-rest-abilities-v1-list-controller.php` |

Core controller used to access abilities via the REST API.

  | 
| [WP_REST_Font_Collections_Controller](https://developer.wordpress.org/reference/classes/wp_rest_font_collections_controller/)`wp-includes/rest-api/endpoints/class-wp-rest-font-collections-controller.php` |

Font Library Controller class.

  | 
| [WP_REST_Navigation_Fallback_Controller](https://developer.wordpress.org/reference/classes/wp_rest_navigation_fallback_controller/)`wp-includes/rest-api/endpoints/class-wp-rest-navigation-fallback-controller.php` |

REST Controller to fetch a fallback Navigation Block Menu. If needed it creates one.

  | 
| [WP_REST_Block_Patterns_Controller](https://developer.wordpress.org/reference/classes/wp_rest_block_patterns_controller/)`wp-includes/rest-api/endpoints/class-wp-rest-block-patterns-controller.php` |

Core class used to access block patterns via the REST API.

  | 
| [WP_REST_Block_Pattern_Categories_Controller](https://developer.wordpress.org/reference/classes/wp_rest_block_pattern_categories_controller/)`wp-includes/rest-api/endpoints/class-wp-rest-block-pattern-categories-controller.php` |

Core class used to access block pattern categories via the REST API.

  | 
| [WP_REST_URL_Details_Controller](https://developer.wordpress.org/reference/classes/wp_rest_url_details_controller/)`wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php` |

Controller which provides REST endpoint for retrieving information from a remote site’s HTML response.

  | 
| [WP_REST_Menu_Locations_Controller](https://developer.wordpress.org/reference/classes/wp_rest_menu_locations_controller/)`wp-includes/rest-api/endpoints/class-wp-rest-menu-locations-controller.php` |

Core class used to access menu locations via the REST API.

  | 
| [WP_REST_Edit_Site_Export_Controller](https://developer.wordpress.org/reference/classes/wp_rest_edit_site_export_controller/)`wp-includes/rest-api/endpoints/class-wp-rest-edit-site-export-controller.php` |

Controller which provides REST endpoint for exporting current templates and template parts.

  | 
| [WP_REST_Widgets_Controller](https://developer.wordpress.org/reference/classes/wp_rest_widgets_controller/)`wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php` |

Core class to access widgets via the REST API.

  | 
| [WP_REST_Sidebars_Controller](https://developer.wordpress.org/reference/classes/wp_rest_sidebars_controller/)`wp-includes/rest-api/endpoints/class-wp-rest-sidebars-controller.php` |

Core class used to manage a site’s sidebars.

  | 
| [WP_REST_Templates_Controller](https://developer.wordpress.org/reference/classes/wp_rest_templates_controller/)`wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php` |

Base Templates REST API Controller.

  | 
| [WP_REST_Pattern_Directory_Controller](https://developer.wordpress.org/reference/classes/wp_rest_pattern_directory_controller/)`wp-includes/rest-api/endpoints/class-wp-rest-pattern-directory-controller.php` |

Controller which provides REST endpoint for block patterns.

  | 
| [WP_REST_Widget_Types_Controller](https://developer.wordpress.org/reference/classes/wp_rest_widget_types_controller/)`wp-includes/rest-api/endpoints/class-wp-rest-widget-types-controller.php` |

Core class to access widget types via the REST API.

  | 
| [WP_REST_Site_Health_Controller](https://developer.wordpress.org/reference/classes/wp_rest_site_health_controller/)`wp-includes/rest-api/endpoints/class-wp-rest-site-health-controller.php` |

Core class for interacting with Site Health tests.

  | 
| [WP_REST_Application_Passwords_Controller](https://developer.wordpress.org/reference/classes/wp_rest_application_passwords_controller/)`wp-includes/rest-api/endpoints/class-wp-rest-application-passwords-controller.php` |

Core class to access a user’s application passwords via the REST API.

  | 
| [WP_REST_Block_Directory_Controller](https://developer.wordpress.org/reference/classes/wp_rest_block_directory_controller/)`wp-includes/rest-api/endpoints/class-wp-rest-block-directory-controller.php` |

Controller which provides REST endpoint for the blocks.

  | 
| [WP_REST_Plugins_Controller](https://developer.wordpress.org/reference/classes/wp_rest_plugins_controller/)`wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php` |

Core class to access plugins via the REST API.

  | 
| [WP_REST_Block_Types_Controller](https://developer.wordpress.org/reference/classes/wp_rest_block_types_controller/)`wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php` |

Core class used to access block types via the REST API.

  | 
| [WP_REST_Search_Controller](https://developer.wordpress.org/reference/classes/wp_rest_search_controller/)`wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php` |

Core class to search through all WordPress content via the REST API.

  | 
| [WP_REST_Themes_Controller](https://developer.wordpress.org/reference/classes/wp_rest_themes_controller/)`wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php` |

Core class used to manage themes via the REST API.

  | 
| [WP_REST_Block_Renderer_Controller](https://developer.wordpress.org/reference/classes/wp_rest_block_renderer_controller/)`wp-includes/rest-api/endpoints/class-wp-rest-block-renderer-controller.php` |

Controller which provides REST endpoint for rendering a block.

  | 
| [WP_REST_Users_Controller](https://developer.wordpress.org/reference/classes/wp_rest_users_controller/)`wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php` |

Core class used to manage users via the REST API.

  | 
| [WP_REST_Revisions_Controller](https://developer.wordpress.org/reference/classes/wp_rest_revisions_controller/)`wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php` |

Core class used to access revisions via the REST API.

  | 
| [WP_REST_Post_Statuses_Controller](https://developer.wordpress.org/reference/classes/wp_rest_post_statuses_controller/)`wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php` |

Core class used to access post statuses via the REST API.

  | 
| [WP_REST_Settings_Controller](https://developer.wordpress.org/reference/classes/wp_rest_settings_controller/)`wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php` |

Core class used to manage a site’s settings via the REST API.

  | 
| [WP_REST_Terms_Controller](https://developer.wordpress.org/reference/classes/wp_rest_terms_controller/)`wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php` |

Core class used to managed terms associated with a taxonomy via the REST API.

  | 
| [WP_REST_Posts_Controller](https://developer.wordpress.org/reference/classes/wp_rest_posts_controller/)`wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php` |

Core class to access posts via the REST API.

  |

[Show 25 more](https://developer.wordpress.org/reference/classes/wp_rest_controller/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/classes/wp_rest_controller/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_rest_controller/?output_format=md#changelog)󠁿

| Version | Description | 
| [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_rest_controller%2F)
before being able to contribute a note or feedback.