Title: WP_REST_Blocks_Controller
Published: December 6, 2018
Last modified: February 24, 2026

---

# class WP_REST_Blocks_Controller {}

## In this article

 * [Description](https://developer.wordpress.org/reference/classes/wp_rest_blocks_controller/?output_format=md#description)
    - [See also](https://developer.wordpress.org/reference/classes/wp_rest_blocks_controller/?output_format=md#see-also)
 * [Methods](https://developer.wordpress.org/reference/classes/wp_rest_blocks_controller/?output_format=md#methods)
 * [Source](https://developer.wordpress.org/reference/classes/wp_rest_blocks_controller/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_rest_blocks_controller/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_rest_blocks_controller/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_rest_blocks_controller/?output_format=md#wp--skip-link--target)

Controller which provides a REST endpoint for the editor to read, create, edit, 
and delete synced patterns (formerly called reusable blocks).

## 󠀁[Description](https://developer.wordpress.org/reference/classes/wp_rest_blocks_controller/?output_format=md#description)󠁿

Patterns are stored as posts with the wp_block post type.

### 󠀁[See also](https://developer.wordpress.org/reference/classes/wp_rest_blocks_controller/?output_format=md#see-also)󠁿

 * [WP_REST_Posts_Controller](https://developer.wordpress.org/reference/classes/wp_rest_posts_controller/)
 * [WP_REST_Controller](https://developer.wordpress.org/reference/classes/wp_rest_controller/)

## 󠀁[Methods](https://developer.wordpress.org/reference/classes/wp_rest_blocks_controller/?output_format=md#methods)󠁿

| Name | Description | 
| [WP_REST_Blocks_Controller::check_read_permission](https://developer.wordpress.org/reference/classes/wp_rest_blocks_controller/check_read_permission/) | Checks if a pattern can be read. | 
| [WP_REST_Blocks_Controller::filter_response_by_context](https://developer.wordpress.org/reference/classes/wp_rest_blocks_controller/filter_response_by_context/) | Filters a response based on the context defined in the schema. | 
| [WP_REST_Blocks_Controller::get_item_schema](https://developer.wordpress.org/reference/classes/wp_rest_blocks_controller/get_item_schema/) | Retrieves the pattern’s schema, conforming to JSON Schema. |

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_rest_blocks_controller/?output_format=md#source)󠁿

    ```php
    class WP_REST_Blocks_Controller extends WP_REST_Posts_Controller {

    	/**
    	 * Checks if a pattern can be read.
    	 *
    	 * @since 5.0.0
    	 *
    	 * @param WP_Post $post Post object that backs the block.
    	 * @return bool Whether the pattern can be read.
    	 */
    	public function check_read_permission( $post ) {
    		// By default the read_post capability is mapped to edit_posts.
    		if ( ! current_user_can( 'read_post', $post->ID ) ) {
    			return false;
    		}

    		return parent::check_read_permission( $post );
    	}

    	/**
    	 * Filters a response based on the context defined in the schema.
    	 *
    	 * @since 5.0.0
    	 * @since 6.3.0 Adds the `wp_pattern_sync_status` postmeta property to the top level of response.
    	 *
    	 * @param array  $data    Response data to filter.
    	 * @param string $context Context defined in the schema.
    	 * @return array Filtered response.
    	 */
    	public function filter_response_by_context( $data, $context ) {
    		$data = parent::filter_response_by_context( $data, $context );

    		/*
    		 * Remove `title.rendered` and `content.rendered` from the response.
    		 * It doesn't make sense for a pattern to have rendered content on its own,
    		 * since rendering a block requires it to be inside a post or a page.
    		 */
    		unset( $data['title']['rendered'] );
    		unset( $data['content']['rendered'] );

    		// Add the core wp_pattern_sync_status meta as top level property to the response.
    		$data['wp_pattern_sync_status'] = isset( $data['meta']['wp_pattern_sync_status'] ) ? $data['meta']['wp_pattern_sync_status'] : '';
    		unset( $data['meta']['wp_pattern_sync_status'] );
    		return $data;
    	}

    	/**
    	 * Retrieves the pattern's schema, conforming to JSON Schema.
    	 *
    	 * @since 5.0.0
    	 *
    	 * @return array Item schema data.
    	 */
    	public function get_item_schema() {
    		if ( $this->schema ) {
    			return $this->add_additional_fields_schema( $this->schema );
    		}

    		$schema = parent::get_item_schema();

    		/*
    		 * Allow all contexts to access `title.raw` and `content.raw`.
    		 * Clients always need the raw markup of a pattern to do anything useful,
    		 * e.g. parse it or display it in an editor.
    		 */
    		$schema['properties']['title']['properties']['raw']['context']   = array( 'view', 'edit' );
    		$schema['properties']['content']['properties']['raw']['context'] = array( 'view', 'edit' );

    		/*
    		 * Remove `title.rendered` and `content.rendered` from the schema.
    		 * It doesn't make sense for a pattern to have rendered content on its own,
    		 * since rendering a block requires it to be inside a post or a page.
    		 */
    		unset( $schema['properties']['title']['properties']['rendered'] );
    		unset( $schema['properties']['content']['properties']['rendered'] );

    		$this->schema = $schema;

    		return $this->add_additional_fields_schema( $this->schema );
    	}
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-blocks-controller.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/rest-api/endpoints/class-wp-rest-blocks-controller.php#L20)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/rest-api/endpoints/class-wp-rest-blocks-controller.php#L20-L100)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_rest_blocks_controller/?output_format=md#related)󠁿

| Uses | Description | 
| [WP_REST_Posts_Controller](https://developer.wordpress.org/reference/classes/wp_rest_posts_controller/)`wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php` |

Core class to access posts via the REST API.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_rest_blocks_controller/?output_format=md#changelog)󠁿

| Version | Description | 
| [5.0.0](https://developer.wordpress.org/reference/since/5.0.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_rest_blocks_controller%2F)
before being able to contribute a note or feedback.