Make WordPress Core


Ignore:
Timestamp:
09/20/2022 03:14:54 PM (3 years ago)
Author:
gziolo
Message:

Editor: Sync changes from the Gutenberg plugin 14.1 release

Updated WordPress packages necessary for releasing WordPress 6.1 Beta 1:

  • @wordpress/a11y@3.17.1
    • @wordpress/annotations@2.17.2
    • @wordpress/api-fetch@6.14.1
    • @wordpress/autop@3.17.1
    • @wordpress/babel-plugin-import-jsx-pragma@4.0.1
    • @wordpress/babel-plugin-makepot@5.1.1
    • @wordpress/babel-preset-default@7.1.1
    • @wordpress/base-styles@4.8.1
    • @wordpress/blob@3.17.1
    • @wordpress/block-directory@3.15.2
    • @wordpress/block-editor@10.0.2
    • @wordpress/block-library@7.14.2
    • @wordpress/block-serialization-default-parser@4.17.1
    • @wordpress/block-serialization-spec-parser@4.17.1
    • @wordpress/blocks@11.16.2
    • @wordpress/browserslist-config@5.0.1
    • @wordpress/components@21.0.2
    • @wordpress/compose@5.15.2
    • @wordpress/core-data@5.0.2
    • @wordpress/create-block-tutorial-template@2.5.1
    • @wordpress/create-block@4.1.1
    • @wordpress/custom-templated-path-webpack-plugin@2.1.3
    • @wordpress/customize-widgets@3.14.2
    • @wordpress/data-controls@2.17.2
    • @wordpress/data@7.1.2
    • @wordpress/date@4.17.1
    • @wordpress/dependency-extraction-webpack-plugin@4.0.2
    • @wordpress/deprecated@3.17.1
    • @wordpress/docgen@1.26.1
    • @wordpress/dom-ready@3.17.1
    • @wordpress/dom@3.17.2
    • @wordpress/e2e-test-utils@8.1.1
    • @wordpress/e2e-tests@5.1.2
    • @wordpress/edit-post@6.14.2
    • @wordpress/edit-site@4.14.2
    • @wordpress/edit-widgets@4.14.2
    • @wordpress/editor@12.16.2
    • @wordpress/element@4.15.1
    • @wordpress/env@5.2.1
    • @wordpress/escape-html@2.17.1
    • @wordpress/eslint-plugin@13.1.1
    • @wordpress/format-library@3.15.2
    • @wordpress/hooks@3.17.1
    • @wordpress/html-entities@3.17.1
    • @wordpress/i18n@4.17.1
    • @wordpress/icons@9.8.1
    • @wordpress/interface@4.16.2
    • @wordpress/is-shallow-equal@4.17.1
    • @wordpress/jest-console@6.0.1
    • @wordpress/jest-preset-default@9.0.1
    • @wordpress/jest-puppeteer-axe@5.0.1
    • @wordpress/keyboard-shortcuts@3.15.2
    • @wordpress/keycodes@3.17.1
    • @wordpress/lazy-import@1.4.3
    • @wordpress/library-export-default-webpack-plugin@2.3.3
    • @wordpress/list-reusable-blocks@3.15.2
    • @wordpress/media-utils@4.8.1
    • @wordpress/notices@3.17.2
    • @wordpress/npm-package-json-lint-config@4.2.1
    • @wordpress/nux@5.15.2
    • @wordpress/plugins@4.15.2
    • @wordpress/postcss-plugins-preset@4.1.1
    • @wordpress/postcss-themes@5.0.1
    • @wordpress/preferences-persistence@1.9.1
    • @wordpress/preferences@2.9.2
    • @wordpress/prettier-config@2.0.1
    • @wordpress/primitives@3.15.1
    • @wordpress/priority-queue@2.17.2
    • @wordpress/project-management-automation@1.16.1
    • @wordpress/react-i18n@3.15.1
    • @wordpress/readable-js-assets-webpack-plugin@2.0.1
    • @wordpress/redux-routine@4.17.1
    • @wordpress/reusable-blocks@3.15.2
    • @wordpress/rich-text@5.15.2
    • @wordpress/scripts@24.1.2
    • @wordpress/server-side-render@3.15.2
    • @wordpress/shortcode@3.17.1
    • @wordpress/style-engine@1.0.1
    • @wordpress/stylelint-config@21.0.1
    • @wordpress/token-list@2.17.1
    • @wordpress/url@3.18.1
    • @wordpress/viewport@4.15.2
    • @wordpress/warning@2.17.1
    • @wordpress/widgets@2.15.2
    • @wordpress/wordcount@3.17.1

Props bernhard-reiter, cbravobernal, czapla, oandregal, isabel_brison, andrewserong, mciampini.
See #56467.

File:
1 edited

Legend:

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

    r53377 r54257  
    251251
    252252/**
    253  * Finds the first non-empty `wp_navigation` Post.
     253 * Finds the most recently published `wp_navigation` Post.
    254254 *
    255255 * @return WP_Post|null the first non-empty Navigation or null.
    256256 */
    257 function block_core_navigation_get_first_non_empty_navigation() {
    258     // Order and orderby args set to mirror those in `wp_get_nav_menus`
    259     // see:
    260     // - https://github.com/WordPress/wordpress-develop/blob/ba943e113d3b31b121f77a2d30aebe14b047c69d/src/wp-includes/nav-menu.php#L613-L619.
    261     // - https://developer.wordpress.org/reference/classes/wp_query/#order-orderby-parameters.
     257function block_core_navigation_get_most_recently_published_navigation() {
     258    // We default to the most recently created menu.
    262259    $parsed_args = array(
    263260        'post_type'      => 'wp_navigation',
    264261        'no_found_rows'  => true,
    265         'order'          => 'ASC',
    266         'orderby'        => 'name',
     262        'order'          => 'DESC',
     263        'orderby'        => 'date',
    267264        'post_status'    => 'publish',
    268         'posts_per_page' => 20, // Try the first 20 posts.
    269     );
    270 
    271     $navigation_posts = new WP_Query( $parsed_args );
    272     foreach ( $navigation_posts->posts as $navigation_post ) {
    273         if ( has_blocks( $navigation_post ) ) {
    274             return $navigation_post;
    275         }
     265        'posts_per_page' => 1, // get only the most recent.
     266    );
     267
     268    $navigation_post = new WP_Query( $parsed_args );
     269    if ( count( $navigation_post->posts ) > 0 ) {
     270        return $navigation_post->posts[0];
    276271    }
    277272
     
    326321    // Default to a list of Pages.
    327322
    328     $navigation_post = block_core_navigation_get_first_non_empty_navigation();
     323    $navigation_post = block_core_navigation_get_most_recently_published_navigation();
    329324
    330325    // Prefer using the first non-empty Navigation as fallback if available.
     
    378373
    379374    if ( 'core/navigation-link' === $block->name || 'core/navigation-submenu' === $block->name ) {
    380         if ( $block->attributes && isset( $block->attributes['kind'] ) && 'post-type' === $block->attributes['kind'] ) {
     375        if ( $block->attributes && isset( $block->attributes['kind'] ) && 'post-type' === $block->attributes['kind'] && isset( $block->attributes['id'] ) ) {
    381376            $post_ids[] = $block->attributes['id'];
    382377        }
     
    430425    if ( $should_load_view_script ) {
    431426        wp_enqueue_script( 'wp-block-navigation-view' );
     427    }
     428
     429    $should_load_modal_view_script = isset( $attributes['overlayMenu'] ) && 'never' !== $attributes['overlayMenu'];
     430    if ( $should_load_modal_view_script ) {
     431        wp_enqueue_script( 'wp-block-navigation-view-modal' );
    432432    }
    433433
     
    468468        }
    469469
    470         $nav_menu_name = $navigation_post->post_title;
    471 
    472         if ( isset( $seen_menu_names[ $nav_menu_name ] ) ) {
    473             ++$seen_menu_names[ $nav_menu_name ];
    474         } else {
    475             $seen_menu_names[ $nav_menu_name ] = 1;
    476         }
    477 
    478         $parsed_blocks = parse_blocks( $navigation_post->post_content );
    479 
    480         // 'parse_blocks' includes a null block with '\n\n' as the content when
    481         // it encounters whitespace. This code strips it.
    482         $compacted_blocks = block_core_navigation_filter_out_empty_blocks( $parsed_blocks );
    483 
    484         // TODO - this uses the full navigation block attributes for the
    485         // context which could be refined.
    486         $inner_blocks = new WP_Block_List( $compacted_blocks, $attributes );
     470        // Only published posts are valid. If this is changed then a corresponding change
     471        // must also be implemented in `use-navigation-menu.js`.
     472        if ( 'publish' === $navigation_post->post_status ) {
     473            $nav_menu_name = $navigation_post->post_title;
     474
     475            if ( isset( $seen_menu_names[ $nav_menu_name ] ) ) {
     476                ++$seen_menu_names[ $nav_menu_name ];
     477            } else {
     478                $seen_menu_names[ $nav_menu_name ] = 1;
     479            }
     480
     481            $parsed_blocks = parse_blocks( $navigation_post->post_content );
     482
     483            // 'parse_blocks' includes a null block with '\n\n' as the content when
     484            // it encounters whitespace. This code strips it.
     485            $compacted_blocks = block_core_navigation_filter_out_empty_blocks( $parsed_blocks );
     486
     487            // TODO - this uses the full navigation block attributes for the
     488            // context which could be refined.
     489            $inner_blocks = new WP_Block_List( $compacted_blocks, $attributes );
     490        }
    487491    }
    488492
     
    499503
    500504        $inner_blocks = new WP_Block_List( $fallback_blocks, $attributes );
    501 
    502     }
     505    }
     506
     507    /**
     508     * Filter navigation block $inner_blocks.
     509     * Allows modification of a navigation block menu items.
     510     *
     511     * @since 6.1.0
     512     *
     513     * @param \WP_Block_List $inner_blocks
     514     */
     515    $inner_blocks = apply_filters( 'block_core_navigation_render_inner_blocks', $inner_blocks );
    503516
    504517    $layout_justification = array(
     
    553566            $inner_blocks_html .= '</ul>';
    554567        }
    555         if ( 'core/site-title' === $inner_block->name || 'core/site-logo' === $inner_block->name ) {
    556             $inner_blocks_html .= '<li class="wp-block-navigation-item">' . $inner_block->render() . '</li>';
     568        $inner_block_content = $inner_block->render();
     569        if ( 'core/site-title' === $inner_block->name || ( 'core/site-logo' === $inner_block->name && $inner_block_content ) ) {
     570            $inner_blocks_html .= '<li class="wp-block-navigation-item">' . $inner_block_content . '</li>';
    557571        } else {
    558             $inner_blocks_html .= $inner_block->render();
     572            $inner_blocks_html .= $inner_block_content;
    559573        }
    560574    }
     
    605619    );
    606620
     621    $should_display_icon_label = isset( $attributes['hasIcon'] ) && true === $attributes['hasIcon'];
    607622    $toggle_button_icon        = '<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><rect x="4" y="7.5" width="16" height="1.5" /><rect x="4" y="15" width="16" height="1.5" /></svg>';
    608     $should_display_icon_label = isset( $attributes['hasIcon'] ) && true === $attributes['hasIcon'];
    609     $toggle_button_content     = $should_display_icon_label ? $toggle_button_icon : 'Menu';
     623    if ( isset( $attributes['icon'] ) ) {
     624        if ( 'menu' === $attributes['icon'] ) {
     625            $toggle_button_icon = '<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M5 5v1.5h14V5H5zm0 7.8h14v-1.5H5v1.5zM5 19h14v-1.5H5V19z" /></svg>';
     626        }
     627    }
     628    $toggle_button_content       = $should_display_icon_label ? $toggle_button_icon : __( 'Menu' );
     629    $toggle_close_button_icon    = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" aria-hidden="true" focusable="false"><path d="M13 11.8l6.1-6.3-1-1-6.1 6.2-6.1-6.2-1 1 6.1 6.3-6.5 6.7 1 1 6.5-6.6 6.5 6.6 1-1z"></path></svg>';
     630    $toggle_close_button_content = $should_display_icon_label ? $toggle_close_button_icon : __( 'Close' );
     631    $toggle_aria_label_open      = $should_display_icon_label ? 'aria-label="' . __( 'Open menu' ) . '"' : ''; // Open button label.
     632    $toggle_aria_label_close     = $should_display_icon_label ? 'aria-label="' . __( 'Close menu' ) . '"' : ''; // Close button label.
    610633
    611634    $responsive_container_markup = sprintf(
    612         '<button aria-haspopup="true" aria-label="%3$s" class="%6$s" data-micromodal-trigger="%1$s">%9$s</button>
     635        '<button aria-haspopup="true" %3$s class="%6$s" data-micromodal-trigger="%1$s">%9$s</button>
    613636            <div class="%5$s" style="%7$s" id="%1$s">
    614637                <div class="wp-block-navigation__responsive-close" tabindex="-1" data-micromodal-close>
    615638                    <div class="wp-block-navigation__responsive-dialog" aria-label="%8$s">
    616                             <button aria-label="%4$s" data-micromodal-close class="wp-block-navigation__responsive-container-close"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" aria-hidden="true" focusable="false"><path d="M13 11.8l6.1-6.3-1-1-6.1 6.2-6.1-6.2-1 1 6.1 6.3-6.5 6.7 1 1 6.5-6.6 6.5 6.6 1-1z"></path></svg></button>
     639                            <button %4$s data-micromodal-close class="wp-block-navigation__responsive-container-close">%10$s</button>
    617640                        <div class="wp-block-navigation__responsive-container-content" id="%1$s-content">
    618641                            %2$s
     
    623646        esc_attr( $modal_unique_id ),
    624647        $inner_blocks_html,
    625         __( 'Open menu' ), // Open button label.
    626         __( 'Close menu' ), // Close button label.
     648        $toggle_aria_label_open,
     649        $toggle_aria_label_close,
    627650        esc_attr( implode( ' ', $responsive_container_classes ) ),
    628651        esc_attr( implode( ' ', $open_button_classes ) ),
    629652        safecss_filter_attr( $colors['overlay_inline_styles'] ),
    630653        __( 'Menu' ),
    631         $toggle_button_content
     654        $toggle_button_content,
     655        $toggle_close_button_content
    632656    );
    633657
Note: See TracChangeset for help on using the changeset viewer.