Checks whether a given request has permission to read a type.
Description
See also
Parameters
- $request
-
(WP_REST_Request) (Required) Full details about the request.
Return
(WP_Error|true) True if the request has read access, WP_Error object otherwise.
Source
File: src/db-objects/elements/element-types/rest-element-types-controller.php
public function get_item_permissions_check( $request ) { $capabilities = $this->manager->capabilities(); if ( 'edit' === $request['context'] && ( ! $capabilities || ! $capabilities->user_can_edit() ) ) { return new WP_Error( 'rest_cannot_edit_type', __( 'Sorry, you are not allowed to edit elements of this type.', 'torro-forms' ), array( 'status' => rest_authorization_required_code() ) ); } $obj = $this->manager->types()->get( $request['slug'] ); if ( is_wp_error( $obj ) ) { return new WP_Error( 'rest_invalid_type_slug', __( 'Invalid element type slug.', 'torro-forms' ), array( 'status' => 404 ) ); } if ( ! $this->manager->is_public() && ( ! $capabilities || ! $capabilities->user_can_read() ) ) { return new WP_Error( 'rest_cannot_read_type', __( 'Sorry, you are not allowed to view elements of this type.', 'torro-forms' ), array( 'status' => rest_authorization_required_code() ) ); } return true; }
Changelog
Version | Description |
---|---|
1.0.0 | Introduced. |