WP_Navigation_Block_Renderer
- Since
- 6.5.0
- Source
wp-includes/blocks/navigation.php:87
Helper functions used to render the navigation block.
Compatibility
- WordPress
- since 6.5.0
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0).
Hooks and filters fired · 2
Every hook that fires from inside WP_Navigation_Block_Renderer, in the order it appears in the class, grouped by the method that fires it.
Properties · 3
$needs_list_item_wrapperarrayprivate static- Used to determine which blocks need an
- wrapper.
Methods · 25
- is_responsive()Returns whether or not this is responsive navigation.
- has_submenus()Returns whether or not a navigation has a submenu.
- is_interactive()Determine whether the navigation blocks is interactive.
- does_block_need_a_list_item_wrapper()Returns whether or not a block needs a list item wrapper.
- get_markup_for_inner_block()Returns the markup for a single inner block.
- get_template_part_blocks_html()Returns the html for blocks from a template part (without navigation container wrapper).
- get_inner_blocks_html()Returns the html for the inner blocks of the navigation block.
- get_inner_blocks_from_navigation_post()Gets the inner blocks for the navigation block from the navigation post.
- get_inner_blocks_from_fallback()Gets the inner blocks for the navigation block from the fallback.
- disable_overlay_menu_for_nested_navigation_blocks()Recursively disables overlay menu for navigation blocks within overlay blocks.
- get_overlay_blocks_from_template_part()Gets the inner blocks for the navigation block from an overlay template part.
- get_inner_blocks()Gets the inner blocks for the navigation block.
- get_navigation_name()Gets the name of the current navigation, if it has one.
- get_layout_class()Returns the layout class for the navigation block.
- get_classes()Return classes for the navigation block.
- get_styles()Get styles for the navigation block.
- get_responsive_container_classes()Get responsive container classes for the navigation block.
- get_overlay_inline_styles()Get overlay inline styles for the navigation block.
- get_responsive_container_markup()Get the responsive container markup
- get_nav_attributes()Get the wrapper attributes
- get_nav_element_directives()Gets the nav element directives.
- handle_view_script_module_loading()Handle view script module loading.
- get_inner_block_markup()Returns the markup for the navigation block.
- get_unique_navigation_name()Returns a unique name for the navigation.
- render()Renders the navigation block.
Source code
class WP_Navigation_Block_Renderer { /** * Used to determine whether or not a navigation has submenus. * * @since 6.5.0 */ private static $has_submenus = false; /** * Used to determine which blocks need an <li> wrapper. * * @since 6.5.0 * * @var array */ private static $needs_list_item_wrapper = array( 'core/site-title', 'core/site-logo', 'core/social-links', ); /** * Keeps track of all the navigation names that have been seen. * * @since 6.5.0 * * @var array */ private static $seen_menu_names = array(); /** * Returns whether or not this is responsive navigation. * * @since 6.5.0 * * @param array $attributes The block attributes. * @return bool Returns whether or not this is responsive navigation. */ private static function is_responsive( $attributes ) { /** * This is for backwards compatibility after the `isResponsive` attribute was been removed. */ $has_old_responsive_attribute = ! empty( $attributes['isResponsive'] ) && $attributes['isResponsive']; return isset( $attributes['overlayMenu'] ) && 'never' !== $attributes['overlayMenu'] || $has_old_responsive_attribute; } /** * Returns whether or not a navigation has a submenu. * * @since 6.5.0 * * @param WP_Block_List $inner_blocks The list of inner blocks. * @return bool Returns whether or not a navigation has a submenu and also sets the member variable. */ private static function has_submenus( $inner_blocks ) { if ( true === static::$has_submenus ) { return static::$has_submenus; } foreach ( $inner_blocks as $inner_block ) { // If this is a page list then work out if any of the pages have children. if ( 'core/page-list' === $inner_block->name ) { $all_pages = get_pages( array( 'sort_column' => 'menu_order,post_title', 'order' => 'asc', ) ); foreach ( (array) $all_pages as $page ) { if ( $page->post_parent ) { static::$has_submenus = true; break; } } } // If this is a navigation submenu then we know we have submenus. if ( 'core/navigation-submenu' === $inner_block->name ) {Changelog
Introduced in 6.5.0. 9 changes between 6.7.7 and 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
7.0.4
Method
get_template_part_blocks_html() added.verified against source7.0.4
Method
disable_overlay_menu_for_nested_navigation_blocks() added.verified against source7.0.4
Method
get_overlay_blocks_from_template_part() added.verified against source7.0.4
Method
get_responsive_container_classes() added.verified against source7.0.4
Method
get_overlay_inline_styles() added.verified against source7.0.4
Method
get_nav_attributes() added.verified against source7.0.4
Method
get_inner_block_markup() added.verified against source7.0.4
Method
get_nav_wrapper_attributes() removed.verified against source7.0.4
Method
get_wrapper_markup() removed.verified against source6.5.0
Introduced.from the docblock
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/blocks/navigation.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.