wppaste
WordPress

WP_REST_View_Config_Controller

Since
7.1.0
Source
wp-includes/rest-api/endpoints/class-wp-rest-view-config-controller.php:18
Controller which provides a REST endpoint for retrieving the default view configuration for a given entity type.

Compatibility

WordPress
since 7.1.0
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in 1 of the 5 tracked releases, added in 7.1.0.

Methods · 16

Source code

class WP_REST_View_Config_Controller extends WP_REST_Controller { 	/**	 * Constructor.	 *	 * @since 7.1.0	 */	public function __construct() {		$this->namespace = 'wp/v2';		$this->rest_base = 'view-config';	} 	/**	 * Registers the routes for the controller.	 *	 * @since 7.1.0	 */	public function register_routes() {		register_rest_route(			$this->namespace,			'/' . $this->rest_base,			array(				array(					'methods'             => WP_REST_Server::READABLE,					'callback'            => array( $this, 'get_items' ),					'permission_callback' => array( $this, 'get_items_permissions_check' ),					'args'                => array(						'kind' => array(							'description' => __( 'Entity kind.' ),							'type'        => 'string',							'required'    => true,						),						'name' => array(							'description' => __( 'Entity name.' ),							'type'        => 'string',							'required'    => true,						),					),				),				'schema' => array( $this, 'get_public_item_schema' ),			)		);	} 	/**	 * Checks if a given request has access to read view config.	 *	 * @since 7.1.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 ) {		$kind = $request->get_param( 'kind' );		$name = $request->get_param( 'name' ); 		$capability = $this->get_required_capability( $kind, $name ); 		if ( null === $capability ) {			return new WP_Error(				'rest_view_config_invalid_entity',				__( 'Invalid entity kind or name.' ),				array( 'status' => 404 )			);		} 		if ( ! current_user_can( $capability ) ) {			return new WP_Error(				'rest_cannot_read',				__( 'Sorry, you are not allowed to read view config.' ),				array( 'status' => rest_authorization_required_code() )			);		} 		return true;	} 	/**	 * Resolves the capability required to read the view config for an entity.	 *

Changelog

Introduced in 7.1.0.

Signature, return type and hooks compared across 1 parsed release.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/rest-api/endpoints/class-wp-rest-view-config-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.