REST API: Permit access to the themes controller if user can edit any post type.
Check a more exhaustive list of post type editing caps beyond "edit_post" to ensure custom user roles with access to to specific post types may still use block editor functionality depending on theme features. Props miyauchi, TimothyBlynJacobs. Fixes #46723. Built from https://develop.svn.wordpress.org/trunk@47361 git-svn-id: http://core.svn.wordpress.org/trunk@47148 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
8faf366ab9
commit
a5f16272dd
|
@ -58,15 +58,21 @@ class WP_REST_Themes_Controller extends WP_REST_Controller {
|
|||
* @return true|WP_Error True if the request has read access for the item, otherwise WP_Error object.
|
||||
*/
|
||||
public function get_items_permissions_check( $request ) {
|
||||
if ( ! is_user_logged_in() || ! current_user_can( 'edit_posts' ) ) {
|
||||
return new WP_Error(
|
||||
'rest_user_cannot_view',
|
||||
__( 'Sorry, you are not allowed to view themes.' ),
|
||||
array( 'status' => rest_authorization_required_code() )
|
||||
);
|
||||
if ( current_user_can( 'edit_posts' ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
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_user_cannot_view',
|
||||
__( 'Sorry, you are not allowed to view themes.' ),
|
||||
array( 'status' => rest_authorization_required_code() )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '5.4-beta2-47360';
|
||||
$wp_version = '5.4-beta2-47361';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue