| 1 |
<?php |
| 2 |
/** |
| 3 |
* Reusable blocks REST API: WP_REST_Blocks_Controller class |
| 4 |
* |
| 5 |
* @package gutenberg |
| 6 |
* @since 0.10.0 |
| 7 |
*/ |
| 8 |
|
| 9 |
/** |
| 10 |
* Controller which provides a REST endpoint for Gutenberg to read, create, |
| 11 |
* edit and delete reusable blocks. Blocks are stored as posts with the wp_block |
| 12 |
* post type. |
| 13 |
* |
| 14 |
* @since 0.10.0 |
| 15 |
* |
| 16 |
* @see WP_REST_Controller |
| 17 |
*/ |
| 18 |
class WP_REST_Blocks_Controller extends WP_REST_Posts_Controller { |
| 19 |
/** |
| 20 |
* Checks if a block can be read. |
| 21 |
* |
| 22 |
* @since 2.1.0 |
| 23 |
* |
| 24 |
* @param object $post Post object that backs the block. |
| 25 |
* @return bool Whether the block can be read. |
| 26 |
*/ |
| 27 |
public function check_read_permission( $post ) { |
| 28 |
// Ensure that the user is logged in and has the read_blocks capability. |
| 29 |
$post_type = get_post_type_object( $post->post_type ); |
| 30 |
if ( ! current_user_can( $post_type->cap->read_post, $post->ID ) ) { |
| 31 |
return false; |
| 32 |
} |
| 33 |
|
| 34 |
return parent::check_read_permission( $post ); |
| 35 |
} |
| 36 |
} |
| 37 |
|