PluginProbe
Gutenberg / 23.2.0
Gutenberg v23.2.0
24.0.0 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 All 403 releases
gutenberg / lib / experimental / guidelines / class-gutenberg-guidelines-rest-controller.php
lib/experimental/guidelines
class-gutenberg-content-guidelines-rest-controller.php 24.3 KB 4 months ago class-gutenberg-content-guidelines-revisions-controller.php 10.3 KB 4 months ago class-gutenberg-guidelines-post-type.php 12.1 KB 3 months ago class-gutenberg-guidelines-rest-controller.php 1.4 KB 3 months ago guidelines.php 3.6 KB 4 months ago index.php 2.1 KB 3 months ago load.php 1.2 KB 4 months ago

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

54 lines 1.4 KB 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