Conversation
class.json-api-endpoints.php
Outdated
|
|
||
| if ( $post_type_object = get_post_type_object( $post_type ) ) { | ||
| if ( ! empty( $post_type_object->show_in_rest ) ) { | ||
| return true; |
There was a problem hiding this comment.
This should return $post_type_object->show_in_rest in case it's explicitly set to false
class.json-api-endpoints.php
Outdated
| return true; | ||
| } | ||
| if ( ! empty( $post_type_object->publicly_queryable ) ) { | ||
| return true; |
There was a problem hiding this comment.
This should return $post_type_object->publicly_queryable in case it's explicitly set to false
class.json-api-endpoints.php
Outdated
| } | ||
|
|
||
| // check for allowed types | ||
| if ( in_array( $post_type, $this->_get_whitelisted_post_types() ) ) |
There was a problem hiding this comment.
Should we run whitelist check first before testing the post type object?
There was a problem hiding this comment.
good call, I am going to change the order
| if ( ! empty( $post_type_object->show_in_rest ) ) { | ||
| return $post_type_object->show_in_rest; | ||
| } | ||
| if ( ! empty( $post_type_object->publicly_queryable ) ) { |
There was a problem hiding this comment.
We should double check that the post type object always includes the publicly_queryable flag, since the effect we're after is to fall back to the public value if publicly_queryable is not explicitly set.
If no value is specified for
exclude_from_search,publicly_queryable,show_in_nav_menus, orshow_ui, they inherit their values frompublic.
https://codex.wordpress.org/Function_Reference/register_post_type
|
Fixes #5102 |
|
@lezama How do I test this PR? |
|
@lezama Would you mind updating the PR description so we have a better idea of what exactly this PR does? From what I can tell, we're wanting to only sync public post types and ones that are shown in the API or UI. But, perhaps there are some other things I missed? |
|
The expected changes from this pull request are:
By "administered from the REST API", I mean listed, created, deleted, etc. The last of these bullet points is rather controversial as I see it, but is also most enabling for UIs to build on the REST API. It now opts in many more post types without explicitly being whitelisted merely by being public (previously requiring filter). |
| 'map_meta_cap' => 'map_meta_cap', | ||
| 'cap' => 'capabilities', | ||
| 'hierarchical' => 'hierarchical', | ||
| 'show_in_ui' => 'show_in_ui', |
|
I'm getting this notice when testing: |
|
@ebinnion Good find. Looks like it should be https://codex.wordpress.org/Function_Reference/register_post_type#show_ui |
|
Here are my results of testing with a CPT and a few variations: With function wporg_custom_post_type()
{
register_post_type('wporg_product',
[
'labels' => [
'name' => __('Products'),
'singular_name' => __('Product'),
],
'public' => true,
'has_archive' => true,
]
);
}
add_action('init', 'wporg_custom_post_type');When function wporg_custom_post_type()
{
register_post_type('wporg_product',
[
'labels' => [
'name' => __('Products'),
'singular_name' => __('Product'),
],
'has_archive' => true,
'show_in_rest' => true,
]
);
}
add_action('init', 'wporg_custom_post_type');When function wporg_custom_post_type()
{
register_post_type('wporg_product',
[
'labels' => [
'name' => __('Products'),
'singular_name' => __('Product'),
],
'has_archive' => true,
'publicly_queryable' => true,
]
);
}
add_action('init', 'wporg_custom_post_type'); |
|
Thanks for testing @ebinnion! just addressed your feedback. |
|
With the latest changes, this tests well for me now. I used the code examples from my last comment, and the product CPT showed up when the CPT had I did notice that revisions were showing, even though they aren't 🚢 |
There was a problem hiding this comment.
Very minor, but maybe we can add space between the key and value here so that => aligns with the ones above it.
|
I did a quick pass through the API where I saw |
|
We should probably rebase this against master before merging since the PR was started in early November. Update: I went ahead and rebased. |
…queryable` is `true`
41b291f to
1f7eb99
Compare
|
merged to 4.5 fc6aa76 |
CHangelog: add #5457 Changelog: add #5487 Changelog: add #5708 Changelog: add #5879 Changelog: add #5932 Changelog: add #5963 Changelog: add #5968 Changelog: add #5996 Changelog: add #5998 Changelog: add #5999 Changelog: add #6012 Changelog: add #6013 Changelog: add #6014 Changelog: add #6015 Changelog: add #6023 Changelog: add #6024 Changelog: add #6030 Changelog: add #5465 CHangelog: add #6063 Changelog: add #6025 Changelog: add #5974 Changelog: add #6059 Changelog: add #6046 Changelog: add #5418 Changelog: move things around and add missing information. Changelog: add #5565 Changelog: add #6087 Changelog: add #6095
Changelog: add #5867 Changelog: add #5874 Changelog: add #5905 Changelog: add #5906 Changelog: add #5931 Changelog: add #5933 Changelog: add #5934 Bring over 4.4.2 changelog from branch-4.4 @see 18012a3 Changelog: add #5976, #5978, #5983 Changelog: add #5917 Changelog: add #5832 Changelog: add 4.4.2 release post link. CHangelog: add #5457 Changelog: add #5487 Changelog: add #5708 Changelog: add #5879 Changelog: add #5932 Changelog: add #5963 Changelog: add #5968 Changelog: add #5996 Changelog: add #5998 Changelog: add #5999 Changelog: add #6012 Changelog: add #6013 Changelog: add #6014 Changelog: add #6015 Changelog: add #6023 Changelog: add #6024 Changelog: add #6030 Changelog: add #5465 CHangelog: add #6063 Changelog: add #6025 Changelog: add #5974 Changelog: add #6059 Changelog: add #6046 Changelog: add #5418 Changelog: move things around and add missing information. Changelog: add #5565 Changelog: add #6087 Changelog: add #6095 Readme: add @tyxla to the list of contributors. Improved changelog for your readability and enjoyment updated the release date finalizing the changelog with a few more edits
…d method. This commits D5712. This is part of the synchronization of code between Jetpack and WordPress.com, see more here: #5487 Merges r156753-wpcom.
…d method. This commits D5712. This is part of the synchronization of code between Jetpack and WordPress.com, see more here: #5487 Merges r156753-wpcom.

cc @aduth @jeherve @mtias
This PR aims to accomplish #5487 (comment)