Skip to content
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

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from

Conversation

Chrico
Copy link
Contributor

@Chrico Chrico commented Jul 5, 2024

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 the WP_REST_Post_Search_Handler via rest_post_search_query to extend the $query_args with custom post_status in the REST Response, the rendering part will still limit to post_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

  1. You need to have at least 1 Post which is post_status = "private".
  2. Add a new mu-plugin which hooks into following:
add_filter( 
    'render_block_core_navigation_link_allowed_post_status', 
    static function(array $postStatus): array {
        $postStatus[] = 'private';

        return $postStatus;
} );

add_filter( 
    'rest_post_search_query', 
    static function( array $queryArgs): array {
        $postStatus = $queryArgs['post_status'] ?? [];
        $postStatus[] = 'private';

        $queryArgs['post_status'] = $postStatus;

        return $queryArgs;
} );
  1. Create a new Page with "Navigation Block" and search for 0. the Post with post_status = "private" and insert
  2. Save Page and go to frontend -> "private Post"-link is rendered.

@Chrico Chrico requested a review from ajitbohra as a code owner July 5, 2024 10:27
Copy link

github-actions bot commented Jul 5, 2024

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: Chrico <chrico@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@akasunil akasunil added [Type] Enhancement A suggestion for improvement. [Block] Navigation Link Affects the Navigation Link Block labels Jul 5, 2024
@ndiego ndiego requested a review from getdave July 13, 2024 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Navigation Link Affects the Navigation Link Block [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants