Making WordPress.org

Changeset 9980


Ignore:
Timestamp:
06/24/2020 07:56:37 AM (5 years ago)
Author:
tellyworth
Message:

Plugin dir: only return search results with known block assets.

This affects the block directory search API only.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-query-plugins.php

    r9311 r9980  
    6666
    6767        // Temporary hacky block search
    68         if ( $request->get_param( 'block' ) ) {
     68        $block_search = trim( strtolower( $request->get_param( 'block' ) ) );
     69        if ( $block_search ) {
    6970            global $wpdb;
    70             $block_search = $request->get_param( 'block' );
    7171            $meta_query = array(
    72                 'relation' => 'OR',
     72                'relation' => 'AND',
    7373                array(
    74                     'key' => 'block_name',
    75                     'value' => '^' . $block_search,
    76                     'compare' => 'RLIKE',
     74                    'key' => 'block_files',
     75                    'compare' => 'EXISTS',
    7776                ),
    7877                array(
    79                     'key' => 'block_name',
    80                     'value' => '/' . $block_search, // search following the slash
    81                     'compare' => 'RLIKE',
    82                 ),
    83                 array(
    84                     'key' => 'block_title',
    85                     'value' => $block_search, // search in title
    86                     'compare' => 'RLIKE',
    87                 ),
     78                    'relation' => 'OR',
     79                    array(
     80                        'key' => 'block_name',
     81                        'value' => '^' . $block_search,
     82                        'compare' => 'RLIKE',
     83                    ),
     84                    array(
     85                        'key' => 'block_name',
     86                        'value' => '/' . $block_search, // search following the slash
     87                        'compare' => 'RLIKE',
     88                    ),
     89                    array(
     90                        'key' => 'block_title',
     91                        'value' => $block_search, // search in title
     92                        'compare' => 'RLIKE',
     93                    ),
     94                )
    8895            );
    8996
Note: See TracChangeset for help on using the changeset viewer.