Make WordPress Core


Ignore:
Timestamp:
02/09/2024 06:20:12 PM (9 months ago)
Author:
youknowriad
Message:

Editor: Update the WordPress packages to Gutenberg 17.7RC1.

This brings the latest and greatest from Gutenberg.
The full changelog is available here
https://github.com/WordPress/gutenberg/releases/tag/v17.7.0-rc.1

Props youknowriad, get_dave.
See #60315.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/blocks/navigation.php

    r57499 r57578  
    1010 */
    1111class WP_Navigation_Block_Renderer {
    12     /**
    13      * Used to determine which blocks are wrapped in an <li>.
    14      *
    15      * @var array
    16      */
    17     private static $nav_blocks_wrapped_in_list_item = array(
    18         'core/navigation-link',
    19         'core/home-link',
    20         'core/site-title',
    21         'core/site-logo',
    22         'core/navigation-submenu',
    23     );
     12
     13    /**
     14     * Used to determine whether or not a navigation has submenus.
     15     */
     16    private static $has_submenus = false;
    2417
    2518    /**
     
    5952     *
    6053     * @param WP_Block_List $inner_blocks The list of inner blocks.
    61      * @return bool Returns whether or not a navigation has a submenu.
     54     * @return bool Returns whether or not a navigation has a submenu and also sets the member variable.
    6255     */
    6356    private static function has_submenus( $inner_blocks ) {
     57        if ( true === static::$has_submenus ) {
     58            return static::$has_submenus;
     59        }
     60
    6461        foreach ( $inner_blocks as $inner_block ) {
    65             $inner_block_content = $inner_block->render();
    66             $p                   = new WP_HTML_Tag_Processor( $inner_block_content );
    67             if ( $p->next_tag(
    68                 array(
    69                     'name'       => 'LI',
    70                     'class_name' => 'has-child',
    71                 )
    72             ) ) {
    73                 return true;
     62            // If this is a page list then work out if any of the pages have children.
     63            if ( 'core/page-list' === $inner_block->name ) {
     64                $all_pages = get_pages(
     65                    array(
     66                        'sort_column' => 'menu_order,post_title',
     67                        'order'       => 'asc',
     68                    )
     69                );
     70                foreach ( (array) $all_pages as $page ) {
     71                    if ( $page->post_parent ) {
     72                        static::$has_submenus = true;
     73                        break;
     74                    }
     75                }
    7476            }
    75         }
    76         return false;
     77            // If this is a navigation submenu then we know we have submenus.
     78            if ( 'core/navigation-submenu' === $inner_block->name ) {
     79                static::$has_submenus = true;
     80                break;
     81            }
     82        }
     83
     84        return static::$has_submenus;
    7785    }
    7886
     
    97105     */
    98106    private static function does_block_need_a_list_item_wrapper( $block ) {
    99         return in_array( $block->name, static::$needs_list_item_wrapper, true );
     107
     108        /**
     109         * Filter the list of blocks that need a list item wrapper.
     110         *
     111         * Affords the ability to customize which blocks need a list item wrapper when rendered
     112         * within a core/navigation block.
     113         * This is useful for blocks that are not list items but should be wrapped in a list
     114         * item when used as a child of a navigation block.
     115         *
     116         * @since 6.5.0
     117         *
     118         * @param array $needs_list_item_wrapper The list of blocks that need a list item wrapper.
     119         * @return array The list of blocks that need a list item wrapper.
     120         */
     121        $needs_list_item_wrapper = apply_filters( 'block_core_navigation_listable_blocks', static::$needs_list_item_wrapper );
     122
     123        return in_array( $block->name, $needs_list_item_wrapper, true );
    100124    }
    101125
     
    141165
    142166        foreach ( $inner_blocks as $inner_block ) {
    143             $is_list_item = in_array( $inner_block->name, static::$nav_blocks_wrapped_in_list_item, true );
     167            $inner_block_markup = static::get_markup_for_inner_block( $inner_block );
     168            $p                  = new WP_HTML_Tag_Processor( $inner_block_markup );
     169            $is_list_item       = $p->next_tag( 'LI' );
    144170
    145171            if ( $is_list_item && ! $is_list_open ) {
     
    156182            }
    157183
    158             $inner_blocks_html .= static::get_markup_for_inner_block( $inner_block );
     184            $inner_blocks_html .= $inner_block_markup;
    159185        }
    160186
     
    568594    private static function handle_view_script_module_loading( $attributes, $block, $inner_blocks ) {
    569595        if ( static::is_interactive( $attributes, $inner_blocks ) ) {
     596            $suffix = wp_scripts_get_suffix();
     597            if ( defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN ) {
     598                $module_url = gutenberg_url( '/build/interactivity/navigation.min.js' );
     599            }
     600
     601            wp_register_script_module(
     602                '@wordpress/block-library/navigation',
     603                isset( $module_url ) ? $module_url : includes_url( "blocks/navigation/view{$suffix}.js" ),
     604                array( '@wordpress/interactivity' ),
     605                defined( 'GUTENBERG_VERSION' ) ? GUTENBERG_VERSION : get_bloginfo( 'version' )
     606            );
    570607            wp_enqueue_script_module( '@wordpress/block-library/navigation' );
    571608        }
     
    9691006    $page_list_fallback = array(
    9701007        array(
    971             'blockName' => 'core/page-list',
     1008            'blockName'    => 'core/page-list',
     1009            'innerContent' => array(),
     1010            'attrs'        => array(),
    9721011        ),
    9731012    );
     
    9771016    // If `core/page-list` is not registered then return empty blocks.
    9781017    $fallback_blocks = $registry->is_registered( 'core/page-list' ) ? $page_list_fallback : array();
    979 
    980     if ( class_exists( 'WP_Navigation_Fallback' ) ) {
    981         $navigation_post = WP_Navigation_Fallback::get_fallback();
    982     } else {
    983         $navigation_post = Gutenberg_Navigation_Fallback::get_fallback();
    984     }
     1018    $navigation_post = WP_Navigation_Fallback::get_fallback();
    9851019
    9861020    // Use the first non-empty Navigation as fallback if available.
     
    10791113            'render_callback' => 'render_block_core_navigation',
    10801114        )
    1081     );
    1082 
    1083     wp_register_script_module(
    1084         '@wordpress/block-library/navigation',
    1085         defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN ? gutenberg_url( '/build/interactivity/navigation.min.js' ) : includes_url( 'blocks/navigation/view.min.js' ),
    1086         array( '@wordpress/interactivity' ),
    1087         defined( 'GUTENBERG_VERSION' ) ? GUTENBERG_VERSION : get_bloginfo( 'version' )
    10881115    );
    10891116}
     
    14191446}
    14201447
     1448// Before adding our filter, we verify if it's already added in Core.
     1449// However, during the build process, Gutenberg automatically prefixes our functions with "gutenberg_".
     1450// Therefore, we concatenate the Core's function name to circumvent this prefix for our check.
     1451$rest_insert_wp_navigation_core_callback = 'block_core_navigation_' . 'update_ignore_hooked_blocks_meta';
     1452
    14211453// Injection of hooked blocks into the Navigation block relies on some functions present in WP >= 6.5
    14221454// that are not present in Gutenberg's WP 6.5 compatibility layer.
    1423 if ( function_exists( 'get_hooked_block_markup' ) ) {
     1455if ( function_exists( 'get_hooked_block_markup' ) && ! has_filter( 'rest_insert_wp_navigation', $rest_insert_wp_navigation_core_callback ) ) {
    14241456    add_action( 'rest_insert_wp_navigation', 'block_core_navigation_update_ignore_hooked_blocks_meta', 10, 3 );
    14251457}
     
    14511483}
    14521484
     1485// Before adding our filter, we verify if it's already added in Core.
     1486// However, during the build process, Gutenberg automatically prefixes our functions with "gutenberg_".
     1487// Therefore, we concatenate the Core's function name to circumvent this prefix for our check.
     1488$rest_prepare_wp_navigation_core_callback = 'block_core_navigation_' . 'insert_hooked_blocks_into_rest_response';
     1489
    14531490// Injection of hooked blocks into the Navigation block relies on some functions present in WP >= 6.5
    14541491// that are not present in Gutenberg's WP 6.5 compatibility layer.
    1455 if ( function_exists( 'get_hooked_block_markup' ) ) {
     1492if ( function_exists( 'get_hooked_block_markup' ) && ! has_filter( 'rest_prepare_wp_navigation', $rest_prepare_wp_navigation_core_callback ) ) {
    14561493    add_filter( 'rest_prepare_wp_navigation', 'block_core_navigation_insert_hooked_blocks_into_rest_response', 10, 3 );
    14571494}
Note: See TracChangeset for help on using the changeset viewer.