Make WordPress Core

Changeset 42621


Ignore:
Timestamp:
01/30/2018 02:45:55 PM (9 years ago)
Author:
SergeyBiryukov
Message:

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

Props audrasjb, westonruter.
Merges [42611] to the 4.9 branch.
Fixes #42991.

Location:
branches/4.9
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/4.9

  • branches/4.9/src/wp-includes/class-wp-customize-nav-menus.php

    r42149 r42621  
    367367                                        'object_id'  => intval( $term->term_id ),
    368368                                        'url'        => get_term_link( intval( $term->term_id ), $term->taxonomy ),
     369                                );
     370                        }
     371                }
     372
     373                // Add "Home" link if search term matches. Treat as a page, but switch to custom on add.
     374                if ( isset( $args['s'] ) ) {
     375                        $title = _x( 'Home', 'nav menu home label' );
     376                        $matches = function_exists( 'mb_stripos' ) ? false !== mb_stripos( $title, $args['s'] ) : false !== stripos( $title, $args['s'] );
     377                        if ( $matches ) {
     378                                $items[] = array(
     379                                        'id'         => 'home',
     380                                        'title'      => $title,
     381                                        'type'       => 'custom',
     382                                        'type_label' => __( 'Custom Link' ),
     383                                        'object'     => '',
     384                                        'url'        => home_url(),
    369385                                );
    370386                        }
  • branches/4.9/tests/phpunit/tests/customize/nav-menus.php

    r41887 r42621  
    354354                $this->assertEquals( 2, count( $results ) );
    355355                remove_filter( 'customize_nav_menu_searched_items', array( $this, 'filter_search' ), 10 );
     356
     357                // Test home.
     358                $title   = _x( 'Home', 'nav menu home label' );
     359                $results = $menus->search_available_items_query(
     360                        array(
     361                                'pagenum' => 1,
     362                                's'       => $title,
     363                        )
     364                );
     365                $this->assertCount( 1, $results );
     366                $this->assertEquals( 'home', $results[0]['id'] );
     367                $this->assertEquals( 'custom', $results[0]['type'] );
    356368        }
    357369
Note: See TracChangeset for help on using the changeset viewer.