Skip to content

Commit

Permalink
Reinstate default context for globalStyles in entities.js
Browse files Browse the repository at this point in the history
Check read caps on all CPTs
  • Loading branch information
ramonjd committed Sep 5, 2024
1 parent 05e31e6 commit 02950de
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
25 changes: 16 additions & 9 deletions lib/class-wp-rest-global-styles-controller-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@ public function get_item_schema() {
* Checks if a given request has access to read a single theme global styles config.
*
* @since 5.9.0
* @since 6.7.0 Allow users with edit post capabilities to view theme global styles.
*
* @param WP_REST_Request $request Full details about the request.
* @return true|WP_Error True if the request has read access for the item, WP_Error object otherwise.
Expand All @@ -590,17 +591,23 @@ public function get_theme_item_permissions_check( $request ) { // phpcs:ignore V
* Verify if the current user has edit_posts capability.
* This capability is required to view global styles.
*/
if ( ! current_user_can( 'edit_posts' ) ) {
return new WP_Error(
'rest_cannot_manage_global_styles',
__( 'Sorry, you are not allowed to access the global styles on this site.', 'gutenberg' ),
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_cannot_manage_global_styles',
__( 'Sorry, you are not allowed to access the global styles on this site.', 'gutenberg' ),
array(
'status' => rest_authorization_required_code(),
)
);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/core-data/src/entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export const rootEntitiesConfig = [
name: 'globalStyles',
kind: 'root',
baseURL: '/wp/v2/global-styles',
baseURLParams: {},
baseURLParams: { context: 'edit' },
plural: 'globalStylesVariations', // Should be different from name.
getTitle: ( record ) => record?.title?.rendered || record?.title,
getRevisionsUrl: ( parentId, revisionId ) =>
Expand Down

0 comments on commit 02950de

Please sign in to comment.