PluginProbe
Gutenberg / 23.2.1
Gutenberg v23.2.1
23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 7.4.0 All 402 releases
gutenberg / lib / experimental / guidelines / class-gutenberg-guidelines-rest-controller.php

class-gutenberg-guidelines-rest-controller.php in Gutenberg 23.2.1, at lib/experimental/guidelines/class-gutenberg-guidelines-rest-controller.php

54 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Guidelines REST API Controller.
4 *
5 * @package gutenberg
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit;
10 }
11
12 /**
13 * REST API controller for guideline posts.
14 */
15 class Gutenberg_Guidelines_REST_Controller extends WP_REST_Posts_Controller {
16
17 /**
18 * Checks if a given request has access to read guideline posts.
19 *
20 * @param WP_REST_Request $request Full details about the request.
21 * @return true|WP_Error True if the request has read access, WP_Error object otherwise.
22 */
23 public function get_items_permissions_check( $request ) {
24 $post_type = get_post_type_object( $this->post_type );
25 if ( ! current_user_can( $post_type->cap->read ) ) {
26 return new WP_Error(
27 'rest_forbidden',
28 __( 'Sorry, you are not allowed to view guidelines.', 'gutenberg' ),
29 array( 'status' => rest_authorization_required_code() )
30 );
31 }
32
33 return parent::get_items_permissions_check( $request );
34 }
35
36 /**
37 * Checks if a given request has access to read a guideline post.
38 *
39 * Guidelines are not public content, so every direct item read must pass
40 * the post-specific read capability before falling through to the standard
41 * post checks.
42 *
43 * @param WP_Post $post Post object.
44 * @return bool Whether the post can be read.
45 */
46 public function check_read_permission( $post ) {
47 if ( ! current_user_can( 'read_post', $post->ID ) ) {
48 return false;
49 }
50
51 return parent::check_read_permission( $post );
52 }
53 }
54