From 29978b7c3e68f14ec62bf985e7e59ef61b9be0d1 Mon Sep 17 00:00:00 2001 From: Christian Leucht Date: Thu, 12 Dec 2024 10:28:14 +0100 Subject: [PATCH] Introduce new filter "render_block_core_navigation_link_allowed_post_status" (#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 Co-authored-by: getdave Co-authored-by: draganescu --- .../block-library/src/navigation-link/index.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/block-library/src/navigation-link/index.php b/packages/block-library/src/navigation-link/index.php index 5653e04fca88a3..81df2099dfc188 100644 --- a/packages/block-library/src/navigation-link/index.php +++ b/packages/block-library/src/navigation-link/index.php @@ -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 ''; } }