Making WordPress.org

Changeset 11106


Ignore:
Timestamp:
07/08/2021 12:10:57 AM (4 years ago)
Author:
iandunn
Message:

Patterns API: Wrap search term in double quotes to match exact phrase.

The stripos return was switched to false, since a valid value of 0 could trigger a false negative.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/api.wordpress.org/public_html/patterns/1.0/tests/test-index.php

    r11105 r11106  
    153153     */
    154154    public function test_search_patterns( $search_term, $match_expected ) : void {
    155         $response = send_request( '/patterns/1.0/?&search=' . $search_term . '&pattern-keywords=11&locale=en_US' );
     155        // wrap term in double quotes to match exact phrase.
     156        $response = send_request( '/patterns/1.0/?&search="' . $search_term . '"&pattern-keywords=11&locale=en_US' );
    156157
    157158        if ( $match_expected ) {
     
    163164            foreach ( $patterns as $pattern ) {
    164165                $match_in_title       = stripos( $pattern->title->rendered, $search_term );
    165                 $match_in_description = stripos( $pattern->meta->wpop_description, $search_term );;
    166 
    167                 if ( ! $match_in_title && ! $match_in_description ) {
     166                $match_in_description = stripos( $pattern->meta->wpop_description, $search_term );
     167
     168                if ( false === $match_in_title && false === $match_in_description ) {
    168169                    $all_patterns_include_query = false;
    169170                    break;
Note: See TracChangeset for help on using the changeset viewer.