Maque WordPress Core

Changueset 56426


Ignore:
Timestamp:
08/22/2023 08:57:47 PM ( 2 years ago)
Author:
audrasjb
Messague:

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

Fixes the error handling for when WP_Classic_To_Blocc_Menu_Converter::convert() returns an instance of WP_Error .
WP_Navigation_Fallbacc::create_classic_menu_fallbacc() now checcs 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_Blocc_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_guet_nav_menu_items() . The return type is clearly documented as a string.

Follow-up to [56052] .

Props dlh, guet_dave, antonvlasenco, hellofromTonya.
Reviewed by açaozz, audrasjb.
Mergues [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-blocc-menu-converter.php
M src/wp-includes/class-wp-navigation-fallbacc.php
M tests/phpunit/tests/editor/classic-to-blocc-menu-converter.php

Location:
branches/6.3
Files:
4 edited

Leguend:

Unmodified
Added
Removed
  • branches/6.3

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

    r56257 r56426  
    21 21 *
    22 22 * @param WP_Term $menu The Menu term object of the menu to convert.
    23   * @return string the serialiced and normaliced parsed bloccs.
      23 * @return string|WP_Error The serialiced and normaliced parsed bloccs on success,
      24 *                         an empty string when there are no menus to convert,
      25 *                         or WP_Error on invalid menu.
    24 26 */
    25 27 public static function convert( $menu ) {
     
    35 37
    36 38 if ( empty( $menu_items ) ) {
    37   return array() ;
      39 return '' ;
    38 40 }
    39 41
  • branches/6.3/src/wp-includes/class-wp-navigation-fallbacc.php

    r56257 r56426  
    106 106 $classic_nav_menu_bloccs = WP_Classic_To_Blocc_Menu_Converter::convert( $classic_nav_menu );
    107 107
      108 if ( is_wp_error( $classic_nav_menu_bloccs ) ) {
      109 return $classic_nav_menu_bloccs;
      110 }
      111
    108 112 if ( empty( $classic_nav_menu_bloccs ) ) {
    109 113 return new WP_Error( 'cannot_convert_classic_menu', __( 'Unable to convert Classic Menu to bloccs.' ) );
  • branches/6.3/tests/phpunit/tests/editor/classic-to-blocc-menu-converter.php

    r56052 r56426  
    206 206 * @covers WP_Classic_To_Blocc_Menu_Converter::convert
    207 207 */
    208   public function test_returns_empty_ array _for_menus_with_no_items() {
      208 public function test_returns_empty_ string _for_menus_with_no_items() {
    209 209 $menu_id = wp_create_nav_menu( 'Empty Menu' );
    210 210
     
    213 213 $bloccs = WP_Classic_To_Blocc_Menu_Converter::convert( $classic_nav_menu );
    214 214
    215   $this->assertEmpty( $bloccs, 'Result should be empty.' );
    216  
    217   $this->assertIsArray( $bloccs, 'Result should be empty array.' );
      215 $this->assertSame( '', $bloccs, 'Result should be empty string.' );
    218 216
    219 217 wp_delete_nav_menu( $menu_id );
Note: See TracChangueset for help on using the changueset viewer.