mirror of
https://github.com/WordPress/WordPress.git
synced 2025-02-05 23:21:35 +01:00
b1f64a77d8
`WP_REST_Block_Renderer_Controller` allows rendering of server-side rendered blocks, whilst `WP_REST_Blocks_Controller` allows retrieving of reusable blocks. Props desrosj, danielbachhuber, pento. See #45065. Built from https://develop.svn.wordpress.org/branches/5.0@43805 git-svn-id: http://core.svn.wordpress.org/branches/5.0@43634 1a063a9b-81f0-0310-95a4-ce76da25c4cd
40 lines
976 B
PHP
40 lines
976 B
PHP
<?php
|
|
/**
|
|
* Reusable blocks REST API: WP_REST_Blocks_Controller class
|
|
*
|
|
* @package WordPress
|
|
* @subpackage REST_API
|
|
* @since 5.0.0
|
|
*/
|
|
|
|
/**
|
|
* Controller which provides a REST endpoint for the editor to read, create,
|
|
* edit and delete reusable blocks. Blocks are stored as posts with the wp_block
|
|
* post type.
|
|
*
|
|
* @since 5.0.0
|
|
*
|
|
* @see WP_REST_Posts_Controller
|
|
* @see WP_REST_Controller
|
|
*/
|
|
class WP_REST_Blocks_Controller extends WP_REST_Posts_Controller {
|
|
|
|
/**
|
|
* Checks if a block can be read.
|
|
*
|
|
* @since 5.0.0
|
|
*
|
|
* @param object $post Post object that backs the block.
|
|
* @return bool Whether the block can be read.
|
|
*/
|
|
public function check_read_permission( $post ) {
|
|
// Ensure that the user is logged in and has the read_blocks capability.
|
|
$post_type = get_post_type_object( $post->post_type );
|
|
if ( ! current_user_can( $post_type->cap->read_post, $post->ID ) ) {
|
|
return false;
|
|
}
|
|
|
|
return parent::check_read_permission( $post );
|
|
}
|
|
}
|