Make WordPress Core


Ignore:
Timestamp:
08/21/2023 05:49:09 PM (16 months ago)
Author:
hellofromTonya
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.
Fixes #58823.

File:
1 edited

Legend:

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

    r56414 r56422  
    106106        $classic_nav_menu_blocks = WP_Classic_To_Block_Menu_Converter::convert( $classic_nav_menu );
    107107
     108        if ( is_wp_error( $classic_nav_menu_blocks ) ) {
     109            return $classic_nav_menu_blocks;
     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.' ) );
Note: See TracChangeset for help on using the changeset viewer.