WordPress.org

Make WordPress Core

Changeset 49624


Ignore:
Timestamp:
11/17/2020 04:29:02 AM (7 months ago)
Author:
noisysocks
Message:

Customize: Ensure multiple CSS classes are passed to nav_menu_link_attributes as an array

When multiple CSS classes are added to a menu item, the nav_menu_link_attributes
filter should be called with $item->classes set to an array of CSS class names.

When previewing in the Customizer, however, a single string was being passed to
$item->classes because WP_Customize_Nav_Menu_Item_Setting::preview() bypasses
wp_update_nav_menu_item() and instead uses filter_wp_get_nav_menu_items().

The fix is to make filter_wp_get_nav_menu_items() match what
wp_update_nav_menu_item() does and split the string into an array.

Fixes #43113.
Props dlh.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/customize/class-wp-customize-nav-menu-item-setting.php

    r49108 r49624  
    606606        }
    607607
     608        // 'classes' should be an array, as in wp_setup_nav_menu_item().
     609        if ( isset( $item->classes ) && is_scalar( $item->classes ) ) {
     610            $item->classes = explode( ' ', $item->classes );
     611        }
     612
    608613        $item->ID    = $this->post_id;
    609614        $item->db_id = $this->post_id;
  • trunk/tests/phpunit/tests/customize/nav-menu-item-setting.php

    r49055 r49624  
    907907            'attr_title'       => '">att \o/ o\'o empted <b>baddie</b>',
    908908            'description'      => 'Attempted \o/ o\'o <b>markup</b>',
    909             'classes'          => '',
     909            'classes'          => 'class-1 class-2',
    910910            'xfn'              => '',
    911911            'status'           => 'publish',
     
    941941        $this->assertSame( $expected, $nav_menu_item->attr_title );
    942942        $this->assertSame( 'Attempted \o/ o&#8217;o markup', $nav_menu_item->description );
     943        $this->assertSame( array( 'class-1', 'class-2' ), $nav_menu_item->classes );
    943944    }
    944945
Note: See TracChangeset for help on using the changeset viewer.