Repository navigation
Guidelines REST: Require read access for standard route #77843
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
gziolo
merged 3 commits into
WordPress:trunk
from
artpi:codex/guidelines-rest-read-permissions
May 5, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
lib/experimental/guidelines/class-gutenberg-guidelines-rest-controller.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| <?php | ||
| /** | ||
| * Guidelines REST API Controller. | ||
| * | ||
| * @package gutenberg | ||
| */ | ||
|
|
||
| if ( ! defined( 'ABSPATH' ) ) { | ||
| exit; | ||
| } | ||
|
|
||
| /** | ||
| * REST API controller for guideline posts. | ||
| */ | ||
| class Gutenberg_Guidelines_REST_Controller extends WP_REST_Posts_Controller { | ||
|
|
||
| /** | ||
| * Checks if a given request has access to read guideline posts. | ||
| * | ||
| * @param WP_REST_Request $request Full details about the request. | ||
| * @return true|WP_Error True if the request has read access, WP_Error object otherwise. | ||
| */ | ||
| public function get_items_permissions_check( $request ) { | ||
| $post_type = get_post_type_object( $this->post_type ); | ||
| if ( ! current_user_can( $post_type->cap->read ) ) { | ||
| return new WP_Error( | ||
| 'rest_forbidden', | ||
| __( 'Sorry, you are not allowed to view guidelines.', 'gutenberg' ), | ||
| array( 'status' => rest_authorization_required_code() ) | ||
| ); | ||
| } | ||
|
|
||
| return parent::get_items_permissions_check( $request ); | ||
| } | ||
|
|
||
| /** | ||
| * Checks if a given request has access to read a guideline post. | ||
| * | ||
| * Guidelines are not public content, so every direct item read must pass | ||
| * the post-specific read capability before falling through to the standard | ||
| * post checks. | ||
| * | ||
| * @param WP_Post $post Post object. | ||
| * @return bool Whether the post can be read. | ||
| */ | ||
| public function check_read_permission( $post ) { | ||
| if ( ! current_user_can( 'read_post', $post->ID ) ) { | ||
| return false; | ||
| } | ||
|
|
||
| return parent::check_read_permission( $post ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.