Repository navigation
Honor WPGraphQL permissions to post content - #122
Merged
Merged
Conversation
alecgeatches
commented
Oct 16, 2026
| // WPGraphQL withholds the content field for password-protected posts. Since this | ||
| // resolver parses raw post_content, require edit access before returning that content. | ||
| // This matches the REST endpoint's password-protected post handling. | ||
| if ( ! empty( $post->post_password ) && ! current_user_can( 'edit_post', $post->ID ) ) { |
Contributor
Author
There was a problem hiding this comment.
This check (and the one in v2 below) isn't necessary for this fix, because isRestricted from WPGraphQL earlier in the function should return false for this case already. This is just an extra sanity check.
chriszarate
approved these changes
Oct 16, 2026
Merged
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
When WPGraphQL is active, a request for a password-protected published post or page could read content. #118 fixed the same class of problem on the REST route but did not touch the GraphQL resolvers.
The REST approach to rely directly on controller permissions in #118 doesn't transfer to WPGraphQL directly. That fix uses post type's REST controller, but post types can be exposed to GraphQL without
show_in_rest, and the REST permission check still permits password-protected posts because core only blanks their content in the response. For GraphQL, the controller is WPGraphQL's own permissions, which decides access before any resolver runs.Both resolvers (
blockData,blockDataV2) now share aget_readable_post()helper that returnsnullwhen the model is restricted, when the model has no post ID, or when the post is protected and the current user cannot edit it. The last check is a bit redundant and mirrors the REST rule and core's own logic, and acts as defense-in-depth should the resolver ever be reached with an unrestricted model for a protected post. Private and draft posts were already correctly handled by WPGraphQL returning no model, and that behavior is unchanged.I have verified this works manually (with the WPGraphQL plugin activated) and a query on a password-protected post:
{ post(id: <password protected post ID>, idType: DATABASE_ID) { databaseId hasPassword isRestricted content blocksDataV2 { blocks { name attributes { name value } } } blocksData { blocks { name attributes { name value } } } } }On
trunk:On
fix/wpgraphql-access: