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
This commit is contained in:
parent
afb4f45e62
commit
b31563e561
@ -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.
|
||||
*
|
||||
|
@ -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'] );
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user