| 1 |
<?php |
| 2 |
/** |
| 3 |
* Shared helper function for checking if navigation items should render. |
| 4 |
* |
| 5 |
* @package WordPress |
| 6 |
*/ |
| 7 |
|
| 8 |
/** |
| 9 |
* Checks if a navigation item should render based on post status. |
| 10 |
* |
| 11 |
* @since 7.0.0 |
| 12 |
* |
| 13 |
* @param array $attributes The block attributes. |
| 14 |
* @param WP_Block $block The parsed block. |
| 15 |
* @return bool True if the item should render, false otherwise. |
| 16 |
*/ |
| 17 |
function gutenberg_block_core_shared_navigation_item_should_render( $attributes, $block ) { |
| 18 |
$navigation_link_has_id = isset( $attributes['id'] ) && is_numeric( $attributes['id'] ); |
| 19 |
$is_post_type = isset( $attributes['kind'] ) && 'post-type' === $attributes['kind']; |
| 20 |
$is_post_type = $is_post_type || isset( $attributes['type'] ) && ( 'post' === $attributes['type'] || 'page' === $attributes['type'] ); |
| 21 |
|
| 22 |
// Don't render the block's subtree if it is a draft or if the ID does not exist. |
| 23 |
if ( $is_post_type && $navigation_link_has_id ) { |
| 24 |
$post = get_post( $attributes['id'] ); |
| 25 |
/** |
| 26 |
* Filter allowed post_status for navigation link block to render. |
| 27 |
* |
| 28 |
* @since 6.8.0 |
| 29 |
* |
| 30 |
* @param array $post_status Array of allowed post statuses. |
| 31 |
* @param array $attributes Block attributes. |
| 32 |
* @param WP_Block $block The parsed block. |
| 33 |
*/ |
| 34 |
$allowed_post_status = (array) apply_filters( |
| 35 |
'render_block_core_navigation_link_allowed_post_status', |
| 36 |
array( 'publish' ), |
| 37 |
$attributes, |
| 38 |
$block |
| 39 |
); |
| 40 |
if ( ! $post || ! in_array( $post->post_status, $allowed_post_status, true ) ) { |
| 41 |
return false; |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
return true; |
| 46 |
} |
| 47 |
|