From 8359290d8f7378d25b538e0880b36573abe955d2 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 10 May 2016 06:40:48 +0000 Subject: [PATCH] Customize: Ensure that `wp_setup_nav_menu_item` filter applies consistently on `nav_menu_item` setting values. The filter was being applied in `WP_Customize_Nav_Menu_Item_Setting::value()` but not in `WP_Customize_Nav_Menu_Item_Setting::value_as_wp_post_nav_menu_item()`. Props celloexpressions, westonruter. Fixes #35203. git-svn-id: https://develop.svn.wordpress.org/trunk@37405 602fd350-edb4-49c9-b593-d223f7449a82 --- .../customize/class-wp-customize-nav-menu-item-setting.php | 3 +++ tests/phpunit/tests/customize/nav-menu-item-setting.php | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/customize/class-wp-customize-nav-menu-item-setting.php b/src/wp-includes/customize/class-wp-customize-nav-menu-item-setting.php index 0bbee67e2f..3aecaa24a2 100644 --- a/src/wp-includes/customize/class-wp-customize-nav-menu-item-setting.php +++ b/src/wp-includes/customize/class-wp-customize-nav-menu-item-setting.php @@ -570,6 +570,9 @@ class WP_Customize_Nav_Menu_Item_Setting extends WP_Customize_Setting { /** This filter is documented in wp-includes/nav-menu.php */ $post->description = apply_filters( 'nav_menu_description', wp_trim_words( $post->description, 200 ) ); + /** This filter is documented in wp-includes/nav-menu.php */ + $post = apply_filters( 'wp_setup_nav_menu_item', $post ); + return $post; } diff --git a/tests/phpunit/tests/customize/nav-menu-item-setting.php b/tests/phpunit/tests/customize/nav-menu-item-setting.php index 718903d6db..56f75a380b 100644 --- a/tests/phpunit/tests/customize/nav-menu-item-setting.php +++ b/tests/phpunit/tests/customize/nav-menu-item-setting.php @@ -766,7 +766,7 @@ class Test_WP_Customize_Nav_Menu_Item_Setting extends WP_UnitTestCase { 'object' => 'post', 'menu_item_parent' => 0, 'position' => 2, - 'type' => 'post_type', + 'type' => 'custom_type', 'title' => 'Hello \o/ o\'o World', 'url' => '', 'target' => '', @@ -782,7 +782,12 @@ class Test_WP_Customize_Nav_Menu_Item_Setting extends WP_UnitTestCase { $this->wp_customize->set_post_value( $setting->id, $post_value ); $setting->preview(); + $nav_menu_item = $setting->value_as_wp_post_nav_menu_item(); + $this->assertEquals( 'Custom Link', $nav_menu_item->type_label ); + add_filter( 'wp_setup_nav_menu_item', array( $this, 'filter_type_label' ) ); + $nav_menu_item = $setting->value_as_wp_post_nav_menu_item(); + $this->assertEquals( 'Custom Label', $nav_menu_item->type_label ); $this->assertObjectNotHasAttribute( 'nav_menu_term_id', $nav_menu_item ); $this->assertObjectNotHasAttribute( 'status', $nav_menu_item );