Title: WP_REST_Block_Types_Controller::check_read_permission
Published: August 11, 2020
Last modified: August 20, 2026

---

# WP_REST_Block_Types_Controller::check_read_permission(): true|󠀁[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)󠁿

## In this article

 * [Return](https://developer.wordpress.org/reference/classes/wp_rest_block_types_controller/check_read_permission/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_rest_block_types_controller/check_read_permission/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_rest_block_types_controller/check_read_permission/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_rest_block_types_controller/check_read_permission/?output_format=md#changelog)

Checks whether a given block type should be visible.

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_rest_block_types_controller/check_read_permission/?output_format=md#return)󠁿

 true|[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/) True
if the block type is visible, [WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)
otherwise.

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

    ```php
    protected function check_read_permission() {
    	if ( current_user_can( 'edit_posts' ) ) {
    		return true;
    	}
    	foreach ( get_post_types( array( 'show_in_rest' => true ), 'objects' ) as $post_type ) {
    		if ( current_user_can( $post_type->cap->edit_posts ) ) {
    			return true;
    		}
    	}

    	return new WP_Error( 'rest_block_type_cannot_view', __( 'Sorry, you are not allowed to manage block types.' ), array( 'status' => rest_authorization_required_code() ) );
    }
    ```

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

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

| Uses | Description | 
| [rest_authorization_required_code()](https://developer.wordpress.org/reference/functions/rest_authorization_required_code/)`wp-includes/rest-api.php` |

Returns a contextual HTTP error code for authorization failure.

  | 
| [current_user_can()](https://developer.wordpress.org/reference/functions/current_user_can/)`wp-includes/capabilities.php` |

Returns whether the current user has the specified capability.

  | 
| [__()](https://developer.wordpress.org/reference/functions/__/)`wp-includes/l10n.php` |

Retrieves the translation of $text.

  | 
| [get_post_types()](https://developer.wordpress.org/reference/functions/get_post_types/)`wp-includes/post.php` |

Gets a list of all registered post type objects.

  | 
| [WP_Error::__construct()](https://developer.wordpress.org/reference/classes/wp_error/__construct/)`wp-includes/class-wp-error.php` |

Initializes the error.

  |

[Show 3 more](https://developer.wordpress.org/reference/classes/wp_rest_block_types_controller/check_read_permission/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/classes/wp_rest_block_types_controller/check_read_permission/?output_format=md#)

| Used by | Description | 
| [WP_REST_Block_Types_Controller::get_items_permissions_check()](https://developer.wordpress.org/reference/classes/wp_rest_block_types_controller/get_items_permissions_check/)`wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php` |

Checks whether a given request has permission to read post block types.

  | 
| [WP_REST_Block_Types_Controller::get_item_permissions_check()](https://developer.wordpress.org/reference/classes/wp_rest_block_types_controller/get_item_permissions_check/)`wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php` |

Checks if a given request has access to read a block type.

  |

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

| Version | Description | 
| [5.5.0](https://developer.wordpress.org/reference/since/5.5.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_block_types_controller%2Fcheck_read_permission%2F)
before being able to contribute a note or feedback.