PluginProbe
Gutenberg / 23.2.2
Gutenberg v23.2.2
23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 7.4.0 All 402 releases
gutenberg / build / scripts / block-library / navigation-link / shared / item-should-render.php

item-should-render.php in Gutenberg 23.2.2, at build/scripts/block-library/navigation-link/shared/item-should-render.php

47 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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