From b31563e561c99189677bad96785853c40e523466 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Mon, 29 Jan 2018 22:09:55 +0000 Subject: [PATCH] Customize: Include nav menu item for Home custom link in search results for "Home". Props audrasjb, westonruter. Fixes #42991. git-svn-id: https://develop.svn.wordpress.org/trunk@42611 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-wp-customize-nav-menus.php | 16 ++++++++++++++++ tests/phpunit/tests/customize/nav-menus.php | 12 ++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/wp-includes/class-wp-customize-nav-menus.php b/src/wp-includes/class-wp-customize-nav-menus.php index 9529ce78a3..9ad9421c09 100644 --- a/src/wp-includes/class-wp-customize-nav-menus.php +++ b/src/wp-includes/class-wp-customize-nav-menus.php @@ -385,6 +385,22 @@ final class WP_Customize_Nav_Menus { } } + // Add "Home" link if search term matches. Treat as a page, but switch to custom on add. + if ( isset( $args['s'] ) ) { + $title = _x( 'Home', 'nav menu home label' ); + $matches = function_exists( 'mb_stripos' ) ? false !== mb_stripos( $title, $args['s'] ) : false !== stripos( $title, $args['s'] ); + if ( $matches ) { + $items[] = array( + 'id' => 'home', + 'title' => $title, + 'type' => 'custom', + 'type_label' => __( 'Custom Link' ), + 'object' => '', + 'url' => home_url(), + ); + } + } + /** * Filters the available menu items during a search request. * diff --git a/tests/phpunit/tests/customize/nav-menus.php b/tests/phpunit/tests/customize/nav-menus.php index 489a2122a2..e37b94b09f 100644 --- a/tests/phpunit/tests/customize/nav-menus.php +++ b/tests/phpunit/tests/customize/nav-menus.php @@ -383,6 +383,18 @@ class Test_WP_Customize_Nav_Menus extends WP_UnitTestCase { $this->assertInternalType( 'array', $results ); $this->assertEquals( 2, count( $results ) ); remove_filter( 'customize_nav_menu_searched_items', array( $this, 'filter_search' ), 10 ); + + // Test home. + $title = _x( 'Home', 'nav menu home label' ); + $results = $menus->search_available_items_query( + array( + 'pagenum' => 1, + 's' => $title, + ) + ); + $this->assertCount( 1, $results ); + $this->assertEquals( 'home', $results[0]['id'] ); + $this->assertEquals( 'custom', $results[0]['type'] ); } /**