Skip to content

Commit

Permalink
fix use tag processor instead of hardcoded list of list item blocks i…
Browse files Browse the repository at this point in the history
…n navigation block render callback

fix phpcs issue
  • Loading branch information
fabiankaegy committed Nov 22, 2023
1 parent 3861da9 commit 1c598d8
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions lib/compat/wordpress-6.5/class-wp-navigation-block-renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,6 @@
* Helper functions used to render the navigation block.
*/
class WP_Navigation_Block_Renderer {
/**
* Used to determine which blocks are wrapped in an <li>.
*
* @var array
*/
private static $nav_blocks_wrapped_in_list_item = array(
'core/navigation-link',
'core/home-link',
'core/site-title',
'core/site-logo',
'core/navigation-submenu',
);

/**
* Used to determine which blocks need an <li> wrapper.
Expand Down Expand Up @@ -145,7 +133,9 @@ private static function get_inner_blocks_html( $attributes, $inner_blocks ) {
$is_list_open = false;

foreach ( $inner_blocks as $inner_block ) {
$is_list_item = in_array( $inner_block->name, static::$nav_blocks_wrapped_in_list_item, true );
$inner_block_markup = static::get_markup_for_inner_block( $inner_block );
$p = new WP_HTML_Tag_Processor( $inner_block_markup );
$is_list_item = $p->next_tag( 'LI' );

if ( $is_list_item && ! $is_list_open ) {
$is_list_open = true;
Expand All @@ -160,7 +150,7 @@ private static function get_inner_blocks_html( $attributes, $inner_blocks ) {
$inner_blocks_html .= '</ul>';
}

$inner_blocks_html .= static::get_markup_for_inner_block( $inner_block );
$inner_blocks_html .= $inner_block_markup;
}

if ( $is_list_open ) {
Expand Down

0 comments on commit 1c598d8

Please sign in to comment.