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
- __construct()Constructor.
- register_routes()Registers the routes for the controller.
- get_items_permissions_check()Checks if a given request has access to read view config.
- get_required_capability()Resolves the capability required to read the view config for an entity.
- get_items()Returns the default view configuration for the given entity type.
- cast_empty_objects()Recursively casts empty arrays to objects where the schema types them as objects.
- get_item_schema()Retrieves the item's schema, conforming to JSON Schema.
- get_view_base_schema()Returns the schema properties shared by all view types (ViewBase), excluding 'type'.
- get_column_style_schema()Returns the schema for the ColumnStyle type.
- get_table_layout_schema()Returns the layout schema for table-type views (ViewTable, ViewPickerTable).
- get_list_layout_schema()Returns the layout schema for list-type views (ViewList, ViewActivity).
- get_combined_layout_schema()Returns a combined layout schema that accepts properties from all view types.
- get_grid_layout_schema()Returns the layout schema for grid-type views (ViewGrid, ViewPickerGrid).
- get_form_layout_schema()Returns the schema for a form layout object as a discriminated union.
- get_form_field_schema()Returns the schema for a form field item (string or object).
- get_form_schema()Returns the schema for the form configuration object.
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.