-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Introduce new filter "render_block_core_navigation_link_allowed_post_status" #63181
Conversation
…_link_allowed_post_status" to align with WP_Query whitelisting post_status in frontend.
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Apologies I missed this ping. I'll add this to my list of things to test. Seems reasonable to bring this in. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this PR.
I tested it and it works as described.
I had to adjust the testing instructions to account for post status being a string and I also included "Draft" posts so I could check it worked for more statuses:
add_filter(
'rest_post_search_query',
static function( array $queryArgs ): array {
$postStatus = $queryArgs['post_status'] ?? array();
if ( is_string( $postStatus ) ) {
$postStatus = array( $postStatus );
}
$postStatus[] = 'private';
$postStatus[] = 'draft';
$queryArgs['post_status'] = $postStatus;
return $queryArgs;
}
);
Overall I'd say it's useful to open up this flexibility for developers.
@draganescu How do you feel about this one?
Added the "Needs Dev Note" label as when it comes to WP 6.8 it will be useful to highlight this in the miscellaneous section. |
@getdave any action from my end needed to complete this? :-) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me as well and is in line with where the discussion ended 👏🏻 well done.
@draganescu This appears to be stalling on the 8.3 check. I think that check was probably added after the PR was created or something. I don't think that should block this PR. Are you ok to green light me force merging this one? |
@Chrico I wonder if you be able to rebase this PR branch against upstream |
All the tests are passing here with the exception of React Native tests which I know to be currently problematic and have been disabled on |
Dev NoteThe Navigation block now supports filtering of the post statuses of Posts shown in the Navigation on the front of the site. The new filter add_filter(
'render_block_core_navigation_link_allowed_post_status',
static function(array $postStatus): array {
$postStatus[] = 'private'; // append statuses to the array of default statuses.
return $postStatus;
} ); |
…status" (WordPress#63181) * navigation-link // introduce new filter "render_block_core_navigation_link_allowed_post_status" to align with WP_Query whitelisting post_status in frontend. * navigation-link // add $attributes and $block as filter params. * Update @SInCE comment --------- Co-authored-by: Chrico <[email protected]> Co-authored-by: getdave <[email protected]> Co-authored-by: draganescu <[email protected]>
This PR introduces a new Filter for rendering the "Navigation Link"-Block to whitelist post_status to not restrict the output to only "public" post_status.
See more information in: #33215
Why?
Since Gutenberg 9.8.0 (see commit: 1936a04 | issue: #27207) the "Navigation Link"-Block limits the output to only "public" post_status.
While it is possible to hook into
WP_Query
and theWP_REST_Post_Search_Handler
viarest_post_search_query
to extend the$query_args
with custompost_status
in the REST Response, the rendering part will still limit topost_status = "publish
.With this new filter
render_block_core_navigation_link_allowed_post_status
it is now possible to also whitelist multiple post_status for rendering in frontend.Testing Instructions
post_status = "private"
.post_status = "private"
and insert