diff -r 7b1b88e27a20 -r 48c4eec2b7e6 wp/wp-includes/blocks/page-list.php --- a/wp/wp-includes/blocks/page-list.php Thu Sep 29 08:06:27 2022 +0200 +++ b/wp/wp-includes/blocks/page-list.php Fri Sep 05 18:40:08 2025 +0200 @@ -9,6 +9,8 @@ * Build an array with CSS classes and inline styles defining the colors * which will be applied to the pages markup in the front-end when it is a descendant of navigation. * + * @since 5.8.0 + * * @param array $attributes Block attributes. * @param array $context Navigation block context. * @return array Colors CSS classes and inline styles. @@ -101,6 +103,8 @@ * Build an array with CSS classes and inline styles defining the font sizes * which will be applied to the pages markup in the front-end when it is a descendant of navigation. * + * @since 5.8.0 + * * @param array $context Navigation block context. * @return array Font size CSS classes and inline styles. */ @@ -119,7 +123,14 @@ $font_sizes['css_classes'][] = sprintf( 'has-%s-font-size', $context['fontSize'] ); } elseif ( $has_custom_font_size ) { // Add the custom font size inline style. - $font_sizes['inline_styles'] = sprintf( 'font-size: %s;', $context['style']['typography']['fontSize'] ); + $font_sizes['inline_styles'] = sprintf( + 'font-size: %s;', + wp_get_typography_font_size_value( + array( + 'size' => $context['style']['typography']['fontSize'], + ) + ) + ); } return $font_sizes; @@ -128,21 +139,25 @@ /** * Outputs Page list markup from an array of pages with nested children. * + * @since 5.8.0 + * * @param boolean $open_submenus_on_click Whether to open submenus on click instead of hover. * @param boolean $show_submenu_icons Whether to show submenu indicator icons. * @param boolean $is_navigation_child If block is a child of Navigation block. * @param array $nested_pages The array of nested pages. + * @param boolean $is_nested Whether the submenu is nested or not. * @param array $active_page_ancestor_ids An array of ancestor ids for active page. * @param array $colors Color information for overlay styles. * @param integer $depth The nesting depth. * * @return string List markup. */ -function block_core_page_list_render_nested_page_list( $open_submenus_on_click, $show_submenu_icons, $is_navigation_child, $nested_pages, $active_page_ancestor_ids = array(), $colors = array(), $depth = 0 ) { +function block_core_page_list_render_nested_page_list( $open_submenus_on_click, $show_submenu_icons, $is_navigation_child, $nested_pages, $is_nested, $active_page_ancestor_ids = array(), $colors = array(), $depth = 0 ) { if ( empty( $nested_pages ) ) { return; } - $markup = ''; + $front_page_id = (int) get_option( 'page_on_front' ); + $markup = ''; foreach ( (array) $nested_pages as $page ) { $css_class = $page['is_active'] ? ' current-menu-item' : ''; $aria_current = $page['is_active'] ? ' aria-current="page"' : ''; @@ -166,14 +181,13 @@ $navigation_child_content_class = $is_navigation_child ? ' wp-block-navigation-item__content' : ''; // If this is the first level of submenus, include the overlay colors. - if ( 1 === $depth && isset( $colors['overlay_css_classes'], $colors['overlay_inline_styles'] ) ) { + if ( ( ( 0 < $depth && ! $is_nested ) || $is_nested ) && isset( $colors['overlay_css_classes'], $colors['overlay_inline_styles'] ) ) { $css_class .= ' ' . trim( implode( ' ', $colors['overlay_css_classes'] ) ); if ( '' !== $colors['overlay_inline_styles'] ) { $style_attribute = sprintf( ' style="%s"', esc_attr( $colors['overlay_inline_styles'] ) ); } } - $front_page_id = (int) get_option( 'page_on_front' ); if ( (int) $page['page_id'] === $front_page_id ) { $css_class .= ' menu-item-home'; } @@ -189,7 +203,7 @@ if ( isset( $page['children'] ) && $is_navigation_child && $open_submenus_on_click ) { $markup .= '' . ''; + ''; } else { $markup .= '' . $title . ''; } @@ -200,12 +214,9 @@ $markup .= ''; $markup .= ''; } - $markup .= '
'; + $markup .= ' '; } $markup .= ''; } @@ -215,6 +226,8 @@ /** * Outputs nested array of pages * + * @since 5.8.0 + * * @param array $current_level The level being iterated through. * @param array $children The children grouped by parent post ID. * @@ -235,6 +248,8 @@ /** * Renders the `core/page-list` block on server. * + * @since 5.8.0 + * * @param array $attributes The block attributes. * @param string $content The saved content. * @param WP_Block $block The parsed block. @@ -243,7 +258,10 @@ */ function render_block_core_page_list( $attributes, $content, $block ) { static $block_id = 0; - $block_id++; + ++$block_id; + + $parent_page_id = $attributes['parentPageID']; + $is_nested = $attributes['isNested']; $all_pages = get_pages( array( @@ -264,7 +282,7 @@ $active_page_ancestor_ids = array(); foreach ( (array) $all_pages as $page ) { - $is_active = ! empty( $page->ID ) && ( get_the_ID() === $page->ID ); + $is_active = ! empty( $page->ID ) && ( get_queried_object_id() === $page->ID ); if ( $is_active ) { $active_page_ancestor_ids = get_post_ancestors( $page->ID ); @@ -274,14 +292,14 @@ $pages_with_children[ $page->post_parent ][ $page->ID ] = array( 'page_id' => $page->ID, 'title' => $page->post_title, - 'link' => get_permalink( $page->ID ), + 'link' => get_permalink( $page ), 'is_active' => $is_active, ); } else { $top_level_pages[ $page->ID ] = array( 'page_id' => $page->ID, 'title' => $page->post_title, - 'link' => get_permalink( $page->ID ), + 'link' => get_permalink( $page ), 'is_active' => $is_active, ); @@ -299,9 +317,16 @@ $nested_pages = block_core_page_list_nest_pages( $top_level_pages, $pages_with_children ); - // Limit the number of items to be visually displayed. - if ( ! empty( $attributes['__unstableMaxPages'] ) ) { - $nested_pages = array_slice( $nested_pages, 0, $attributes['__unstableMaxPages'] ); + if ( 0 !== $parent_page_id ) { + // If the parent page has no child pages, there is nothing to show. + if ( ! array_key_exists( $parent_page_id, $pages_with_children ) ) { + return; + } + + $nested_pages = block_core_page_list_nest_pages( + $pages_with_children[ $parent_page_id ], + $pages_with_children + ); } $is_navigation_child = array_key_exists( 'showSubmenuIcon', $block->context ); @@ -310,9 +335,9 @@ $show_submenu_icons = array_key_exists( 'showSubmenuIcon', $block->context ) ? $block->context['showSubmenuIcon'] : false; - $wrapper_markup = '