Respect 'publicly_queryable' post type setting.#2135
Conversation
… that only authenticated users with the required capability can access it
|
This line of code could have alternatively been written as: I think doing |
src/Model/Post.php
Outdated
| * Published content is public, not private | ||
| */ | ||
| if ( 'publish' === $this->data->post_status ) { | ||
| if ( 'publish' === $this->data->post_status && $this->post_type_object && $this->post_type_object->publicly_queryable ) { |
There was a problem hiding this comment.
@kellenmace this is interesting.
I think if public is true, we need to respect it first.
Because post types can be public => true, publicly_queryable => false, such as the page post_type: https://github.com/WordPress/WordPress/blob/8447683474ebdee773fc4fca7b3e44dea45060f4/wp-includes/post.php#L45-L68, which appears to be breaking a lot of tests right now 🤔
There was a problem hiding this comment.
@kellenmace I pushed up a change so it's now:
if ( 'publish' === $this->data->post_status && $this->post_type_object && ( true === $this->post_type_object->public || true === $this->post_type_object->publicly_queryable ) ) {
return false;
}This means that if either public or publicly_queryable are true, then WPGraphQL should treat the entries as public.
This would allow for "utility" post_types, such as a Slideshow post_type or an FAQ post_type, etc to be registered as public=>false, publicly_queryable=>true and the entries would not get a public url, but would be queryable in WPGraphQL, so they could still be used to compose public facing pages, even without having their own public urls.
…raphql#2134-respect-publicly-queryable-post-type-setting
|
Code Climate has analyzed commit e849fc5 and detected 0 issues on this pull request. View more on Code Climate. |
Fixes #2134.
What does this implement/fix? Explain your changes.
Consider a post as private if 'publicly_queryable' is set to false so that only authenticated users with the required capability can access it.
Does this close any currently open issues?
Yes, #2134.
Any other comments?
Please test this to double-check that it results in the intended behavior.
I also updated the paragraph at the top of the https://www.wpgraphql.com/docs/custom-post-types/#public-vs-private-data section of the docs to reflect this change (wp-admin edit page is here: https://content.wpgraphql.com/wp-admin/post.php?post=5116&action=edit).