Make WordPress Core

Changeset 42611


Ignore:
Timestamp:
01/29/2018 10:09:55 PM (9 years ago)
Author:
westonruter
Message:

Customize: Include nav menu item for Home custom link in search results for "Home".

Props audrasjb, westonruter.
Fixes #42991.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-customize-nav-menus.php

    r42343 r42611  
    382382                                        'object_id'  => intval( $term->term_id ),
    383383                                        'url'        => get_term_link( intval( $term->term_id ), $term->taxonomy ),
     384                                );
     385                        }
     386                }
     387
     388                // Add "Home" link if search term matches. Treat as a page, but switch to custom on add.
     389                if ( isset( $args['s'] ) ) {
     390                        $title = _x( 'Home', 'nav menu home label' );
     391                        $matches = function_exists( 'mb_stripos' ) ? false !== mb_stripos( $title, $args['s'] ) : false !== stripos( $title, $args['s'] );
     392                        if ( $matches ) {
     393                                $items[] = array(
     394                                        'id'         => 'home',
     395                                        'title'      => $title,
     396                                        'type'       => 'custom',
     397                                        'type_label' => __( 'Custom Link' ),
     398                                        'object'     => '',
     399                                        'url'        => home_url(),
    384400                                );
    385401                        }
  • trunk/tests/phpunit/tests/customize/nav-menus.php

    r42343 r42611  
    384384                $this->assertEquals( 2, count( $results ) );
    385385                remove_filter( 'customize_nav_menu_searched_items', array( $this, 'filter_search' ), 10 );
     386
     387                // Test home.
     388                $title   = _x( 'Home', 'nav menu home label' );
     389                $results = $menus->search_available_items_query(
     390                        array(
     391                                'pagenum' => 1,
     392                                's'       => $title,
     393                        )
     394                );
     395                $this->assertCount( 1, $results );
     396                $this->assertEquals( 'home', $results[0]['id'] );
     397                $this->assertEquals( 'custom', $results[0]['type'] );
    386398        }
    387399
Note: See TracChangeset for help on using the changeset viewer.