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 +40 -6 4.5.15.3.5 View file →
@@ -7,11 +7,11 @@
7 7 */
8 8
9 9 namespace ElasticPress\Indexable\Term;
10 10
11 -use ElasticPress\Indexables as Indexables;
12 -use \WP_Term_Query as WP_Term_Query;
13 -use ElasticPress\Utils as Utils;
11 +use WP_Term_Query;
12 +use ElasticPress\Indexables;
13 +use ElasticPress\Utils;
14 14
15 15 if ( ! defined( 'ABSPATH' ) ) {
16 16 exit; // Exit if accessed directly.
17 17 }
@@ -29,11 +29,23 @@
29 29 * @since 3.1
30 30 * @since 3.6.0 Added $indexable_slug
31 31 */
32 32 public function __construct( $indexable_slug = 'term' ) {
33 + /**
34 + * Filter whether to enable query integration during indexing
35 + *
36 + * @since 4.5.2
37 + * @hook ep_enable_query_integration_during_indexing
38 + *
39 + * @param {bool} $enable To allow query integration during indexing
40 + * @param {string} $indexable_slug Indexable slug
41 + * @return {bool} New value
42 + */
43 + $allow_query_integration_during_indexing = apply_filters( 'ep_enable_query_integration_during_indexing', false, $indexable_slug );
44 +
33 45 // Ensure that we are currently allowing ElasticPress to override the normal WP_Query
34 46 // Indexable->is_full_reindexing() is not available at this point yet, so using the IndexHelper version of it.
35 - if ( \ElasticPress\IndexHelper::factory()->is_full_reindexing( $indexable_slug, get_current_blog_id() ) ) {
47 + if ( \ElasticPress\IndexHelper::factory()->is_full_reindexing( $indexable_slug, get_current_blog_id() ) && ! $allow_query_integration_during_indexing ) {
36 48 return;
37 49 }
38 50
39 51 // Add header
@@ -40,8 +52,10 @@
40 52 add_action( 'pre_get_terms', array( $this, 'action_pre_get_terms' ), 5 );
41 53
42 54 // Filter term query
43 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 );
44 58 }
45 59
46 60 /**
47 61 * Add EP header
@@ -138,9 +152,9 @@
138 152
139 153 $index = implode( ',', $index );
140 154 } elseif ( ! empty( $site__not_in ) ) {
141 155
142 - $sites = get_sites(
156 + $sites = \get_sites(
143 157 array(
144 158 'fields' => 'ids',
145 159 'site__not_in' => $site__not_in,
146 160 )
@@ -229,8 +243,29 @@
229 243 return $new_terms;
230 244 }
231 245
232 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 + /**
233 268 * Format the ES hits/results as term objects.
234 269 *
235 270 * @param array $terms The terms that should be formatted.
236 271 * @param array $new_terms Array of terms from cache.
@@ -383,6 +418,5 @@
383 418
384 419 $indexable_taxonomies = Indexables::factory()->get( 'term' )->get_indexable_taxonomies();
385 420 return empty( array_diff( $taxonomies, $indexable_taxonomies ) );
386 421 }
387 -
388 422 }