PluginProbe
ElasticPress / 5.3.5
ElasticPress v5.3.5
5.3.5 5.3.4 3.6.5 3.6.6 4.0.0 4.0.1 4.1.0 4.2.0 4.2.1 4.2.2 4.3.0 4.3.1 4.4.0 4.4.1 4.5.0 4.5.1 4.5.2 4.6.0 4.6.1 4.7.0 4.7.1 4.7.2 5.0.0 5.0.1 5.0.2 All 108 releases
← All changes | includes/classes/Indexable/Term/QueryIntegration.php +24 -2 4.7.25.3.5 View file →
@@ -7,9 +7,9 @@
7 7 */
8 8
9 9 namespace ElasticPress\Indexable\Term;
10 10
11 -use \WP_Term_Query;
11 +use WP_Term_Query;
12 12 use ElasticPress\Indexables;
13 13 use ElasticPress\Utils;
14 14
15 15 if ( ! defined( 'ABSPATH' ) ) {
@@ -52,8 +52,10 @@
52 52 add_action( 'pre_get_terms', array( $this, 'action_pre_get_terms' ), 5 );
53 53
54 54 // Filter term query
55 55 add_filter( 'terms_pre_query', [ $this, 'maybe_filter_query' ], 10, 2 );
56 +
57 + add_filter( 'rest_post_tag_query', [ $this, 'maybe_set_search_fields' ], 10, 2 );
56 58 }
57 59
58 60 /**
59 61 * Add EP header
@@ -241,8 +243,29 @@
241 243 return $new_terms;
242 244 }
243 245
244 246 /**
247 + * Conditionally set search fields for term queries in REST API requests.
248 + *
249 + * If in an REST API request that came from WordPress edit screen, do not search for term description.
250 + *
251 + * @param array $prepared_args Array of arguments for get_terms().
252 + * @param WP_REST_Request $request The REST API request.
253 + * @return array
254 + */
255 + public function maybe_set_search_fields( $prepared_args, $request ) {
256 + $referer = $request->get_header( 'referer' );
257 +
258 + if ( empty( $referer ) || ! preg_match( '/post\.php\?post=([0-9]*)&action=edit/', $referer ) ) {
259 + return $prepared_args;
260 + }
261 +
262 + $prepared_args['search_fields'] = [ 'name', 'slug' ];
263 +
264 + return $prepared_args;
265 + }
266 +
267 + /**
245 268 * Format the ES hits/results as term objects.
246 269 *
247 270 * @param array $terms The terms that should be formatted.
248 271 * @param array $new_terms Array of terms from cache.
@@ -395,6 +418,5 @@
395 418
396 419 $indexable_taxonomies = Indexables::factory()->get( 'term' )->get_indexable_taxonomies();
397 420 return empty( array_diff( $taxonomies, $indexable_taxonomies ) );
398 421 }
399 -
400 422 }