mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-07-01 15:50:09 +00:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@49624 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -605,6 +605,11 @@ class WP_Customize_Nav_Menu_Item_Setting extends WP_Customize_Setting {
|
||||
$item->post_title = $item->title;
|
||||
}
|
||||
|
||||
// 'classes' should be an array, as in wp_setup_nav_menu_item().
|
||||
if ( isset( $item->classes ) && is_scalar( $item->classes ) ) {
|
||||
$item->classes = explode( ' ', $item->classes );
|
||||
}
|
||||
|
||||
$item->ID = $this->post_id;
|
||||
$item->db_id = $this->post_id;
|
||||
$post = new WP_Post( (object) $item );
|
||||
|
||||
@@ -906,7 +906,7 @@ class Test_WP_Customize_Nav_Menu_Item_Setting extends WP_UnitTestCase {
|
||||
'target' => '',
|
||||
'attr_title' => '">att \o/ o\'o empted <b>baddie</b>',
|
||||
'description' => 'Attempted \o/ o\'o <b>markup</b>',
|
||||
'classes' => '',
|
||||
'classes' => 'class-1 class-2',
|
||||
'xfn' => '',
|
||||
'status' => 'publish',
|
||||
'original_title' => '',
|
||||
@@ -940,6 +940,7 @@ class Test_WP_Customize_Nav_Menu_Item_Setting extends WP_UnitTestCase {
|
||||
$expected = apply_filters( 'nav_menu_attr_title', wp_unslash( apply_filters( 'excerpt_save_pre', wp_slash( $post_value['attr_title'] ) ) ) );
|
||||
$this->assertSame( $expected, $nav_menu_item->attr_title );
|
||||
$this->assertSame( 'Attempted \o/ o’o markup', $nav_menu_item->description );
|
||||
$this->assertSame( array( 'class-1', 'class-2' ), $nav_menu_item->classes );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user