Skip to content

Commit

Permalink
Introduce new filter "render_block_core_navigation_link_allowed_post_…
Browse files Browse the repository at this point in the history
…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]>
  • Loading branch information
4 people authored Dec 12, 2024
1 parent 7eba688 commit 29978b7
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion packages/block-library/src/navigation-link/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,22 @@ function render_block_core_navigation_link( $attributes, $content, $block ) {
// Don't render the block's subtree if it is a draft or if the ID does not exist.
if ( $is_post_type && $navigation_link_has_id ) {
$post = get_post( $attributes['id'] );
if ( ! $post || 'publish' !== $post->post_status ) {
/**
* Filter allowed post_status for navigation link block to render.
*
* @since 6.8.0
*
* @param array $post_status
* @param array $attributes
* @param WP_Block $block
*/
$allowed_post_status = (array) apply_filters(
'render_block_core_navigation_link_allowed_post_status',
array( 'publish' ),
$attributes,
$block
);
if ( ! $post || ! in_array( $post->post_status, $allowed_post_status, true ) ) {
return '';
}
}
Expand Down

0 comments on commit 29978b7

Please sign in to comment.