Making WordPress.org


Ignore:
Timestamp:
07/17/2019 07:14:19 AM (6 years ago)
Author:
tellyworth
Message:

Plugin dir: add an endpoint to search by block name.

The implementation is temporary, will be replaced with ElasticSearch. This should work as a temporary measure while developing the block install code.

File:
1 edited

Legend:

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

    r6287 r9051  
    6060        }
    6161
     62        // Temporary hacky block search
     63        if ( $request->get_param( 'block' ) ) {
     64            global $wpdb;
     65            $block_search = $request->get_param( 'block' );
     66            $meta_query = array(
     67                'relation' => 'OR',
     68                array(
     69                    'key' => 'block_name',
     70                    'value' => '^' . $block_search,
     71                    'compare' => 'RLIKE',
     72                ),
     73                array(
     74                    'key' => 'block_name',
     75                    'value' => '/' . $block_search, // search following the slash
     76                    'compare' => 'RLIKE',
     77                ),
     78            );
     79
     80            // Limit the search to the Block section
     81            $query[ 'meta_query' ] = $meta_query;
     82            $query[ 'tax_query' ] = array(
     83                array(
     84                    'taxonomy' => 'plugin_section',
     85                    'field' => 'slug',
     86                    'terms' => 'block',
     87                )
     88            );
     89        }
     90
    6291        if ( ! $query ) {
    6392            return $response;
Note: See TracChangeset for help on using the changeset viewer.