| 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 |
|