Making WordPress.org

Changeset 13654

Timestamp:
05/02/2024 07:59:36 AM (2 months ago)
Author:
dd32
Message:

Plugin Directory: Search: Properly limit block searches to the Block directory. Take two.

The root-cause here is that the plugin_section needs to be limited by slug, rather than name.
Otherwise, { name:'Block-Enabled plugins', slug:'blocks'} matches a name = block query.

See [13648].
See https://wordpress.slack.com/archives/C1LBM36LC/p1714627935853749
See https://wordpress.slack.com/archives/C02QB8GMM/p1714634228857259

File:
1 edited

Legend:

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

    r13652 r13654  
    217217        // These are the things that jetpack_search_es_wp_query_args doesn't let us change, so we need to filter the es_query_args late in the code path to add more custom stuff.
    218218
    219         $es_query_args['filter']['and'] ??= [];
    220 
    221         // Exclude disabled plugins.
     219        // Replace any existing filter with an AND for our custom filters.
     220        if ( ! isset( $es_query_args['filter']['and'] ) ) {
     221            // 'filter' will either be an `and` or term we need to wrap in an `and`.
     222            $es_query_args['filter'] = [
     223                'and' => $es_query_args['filter'] ? [ $es_query_args['filter'] ] : [],
     224            ];
     225        }
     226
     227        // Exclude 'disabled' plugins. This is separate from the 'status' field, which is used for the plugin status.
    222228        $es_query_args['filter']['and'][] = [
    223229            'term' => [
    224                 'disabled' => [
    225                     'value' => false,
    226                 ],
     230                'disabled' => false,
    227231            ]
    228232        ];
    229233
     234
    230235        if ( $this->is_block_search ) {
    231             // Limit to the Block Tax.
    232236            $es_query_args['filter']['and'][] = [
    233237                'term' => [
    234                     'taxonomy.plugin_section.name' => [
    235                         'value' => 'block'
    236                     ]
     238                    'taxonomy.plugin_section.slug' => 'block',
    237239                ]
    238240            ];
Note: See TracChangeset for help on using the changeset viewer.