Make WordPress Core

Changeset 56426

Timestamp:
08/22/2023 08:57:47 PM (12 months ago)
Author:
audrasjb
Message:

Editor: Fix error handling of converting classic to block menus.

Fixes the error handling for when WP_Classic_To_Block_Menu_Converter::convert() returns an instance of WP_Error.
WP_Navigation_Fallback::create_classic_menu_fallback() now checks for is_wp_error() and if true, returns the error. And the @return type is updated to
string|WP_Error.

Also includes a fix in the return type in WP_Classic_To_Block_Menu_Converter::convert() to return an empty string instead of an array instead, i.e. when bailing
out for no menu items returned by wp_get_nav_menu_items(). The return type is clearly documented as a string.

Follow-up to [56052].

Props dlh, get_dave, antonvlasenko, hellofromTonya.
Reviewed by azaozz, audrasjb.
Merges [56422] to the 6.3 branch.
Fixes #58823.

--Cette ligne, et les suivantes ci-dessous, seront

ignorées--

_M .
M src/wp-includes/class-wp-classic-to-block-menu-converter.php
M src/wp-includes/class-wp-navigation-fallback.php
M tests/phpunit/tests/editor/classic-to-block-menu-converter.php

Location:
branches/6.3
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/6.3

  • branches/6.3/src/wp-includes/class-wp-classic-to-block-menu-converter.php

    r56257 r56426  
    2121     *
    2222     * @param WP_Term $menu The Menu term object of the menu to convert.
    23      * @return string the serialized and normalized parsed blocks.
     23     * @return string|WP_Error The serialized and normalized parsed blocks on success,
     24     *                         an empty string when there are no menus to convert,
     25     *                         or WP_Error on invalid menu.
    2426     */
    2527    public static function convert( $menu ) {
     
    3537
    3638        if ( empty( $menu_items ) ) {
    37             return array();
     39            return ;
    3840        }
    3941
  • branches/6.3/src/wp-includes/class-wp-navigation-fallback.php

    r56257 r56426  
    106106        $classic_nav_menu_blocks = WP_Classic_To_Block_Menu_Converter::convert( $classic_nav_menu );
    107107
     108
     109
     110
     111
    108112        if ( empty( $classic_nav_menu_blocks ) ) {
    109113            return new WP_Error( 'cannot_convert_classic_menu', __( 'Unable to convert Classic Menu to blocks.' ) );
  • branches/6.3/tests/phpunit/tests/editor/classic-to-block-menu-converter.php

    r56052 r56426  
    206206     * @covers WP_Classic_To_Block_Menu_Converter::convert
    207207     */
    208     public function test_returns_empty_array_for_menus_with_no_items() {
     208    public function test_returns_empty__for_menus_with_no_items() {
    209209        $menu_id = wp_create_nav_menu( 'Empty Menu' );
    210210
     
    213213        $blocks = WP_Classic_To_Block_Menu_Converter::convert( $classic_nav_menu );
    214214
    215         $this->assertEmpty( $blocks, 'Result should be empty.' );
    216 
    217         $this->assertIsArray( $blocks, 'Result should be empty array.' );
     215        $this->assertSame( '', $blocks, 'Result should be empty string.' );
    218216
    219217        wp_delete_nav_menu( $menu_id );
Note: See TracChangeset for help on using the changeset viewer.