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/Comment/QueryIntegration.php +60 -12 4.3.05.3.5 View file →
@@ -7,11 +7,11 @@
7 7 */
8 8
9 9 namespace ElasticPress\Indexable\Comment;
10 10
11 -use ElasticPress\Indexables as Indexables;
12 -use \WP_Comment_Query as WP_Comment_Query;
13 -use ElasticPress\Utils as Utils;
11 +use WP_Comment_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 }
@@ -37,13 +37,27 @@
37 37
38 38 /**
39 39 * Sets up the appropriate actions and filters.
40 40 *
41 + * @param string $indexable_slug Indexable slug. Optional.
42 + *
41 43 * @since 3.6.0
42 44 */
43 - public function __construct() {
45 + public function __construct( $indexable_slug = 'comment' ) {
46 + /**
47 + * Filter whether to enable query integration during indexing
48 + *
49 + * @since 4.5.2
50 + * @hook ep_enable_query_integration_during_indexing
51 + *
52 + * @param {bool} $enable To allow query integration during indexing
53 + * @param {string} $indexable_slug Indexable slug
54 + * @return {bool} New value
55 + */
56 + $allow_query_integration_during_indexing = apply_filters( 'ep_enable_query_integration_during_indexing', false, $indexable_slug );
57 +
44 58 // Check if we are currently indexing
45 - if ( Utils\is_indexing() ) {
59 + if ( Utils\is_indexing() && ! $allow_query_integration_during_indexing ) {
46 60 return;
47 61 }
48 62
49 63 // Add header
@@ -112,15 +126,35 @@
112 126 if ( null !== $new_comments ) {
113 127 return $new_comments;
114 128 }
115 129
130 + $new_comments = [];
131 +
116 132 $formatted_args = $this->indexable->format_args( $query->query_vars );
117 133
118 134 $scope = 'current';
135 +
136 + $site__in = [];
137 + $site__not_in = [];
138 +
119 139 if ( ! empty( $query->query_vars['sites'] ) ) {
120 - $scope = $query->query_vars['sites'];
140 + _deprecated_argument( __FUNCTION__, '4.4.0', esc_html__( 'sites is deprecated. Use site__in instead.', 'elasticpress' ) );
121 141 }
122 142
143 + if ( ! empty( $query->query_vars['site__in'] ) || ! empty( $query->query_vars['sites'] ) ) {
144 + $site__in = ! empty( $query->query_vars['site__in'] ) ? (array) $query->query_vars['site__in'] : (array) $query->query_vars['sites'];
145 +
146 + if ( in_array( 'all', $site__in, true ) ) {
147 + $scope = 'all';
148 + } elseif ( in_array( 'current', $site__in, true ) ) {
149 + $site__in = (array) get_current_blog_id();
150 + }
151 + }
152 +
153 + if ( ! empty( $query->query_vars['site__not_in'] ) ) {
154 + $site__not_in = (array) $query->query_vars['site__not_in'];
155 + }
156 +
123 157 /**
124 158 * Filter search scope
125 159 *
126 160 * @since 3.6.0
@@ -137,18 +171,33 @@
137 171 $this->index = null;
138 172
139 173 if ( 'all' === $scope ) {
140 174 $this->index = $this->indexable->get_network_alias();
141 - } elseif ( is_numeric( $scope ) ) {
142 - $this->index = $this->indexable->get_index_name( (int) $scope );
143 - } elseif ( is_array( $scope ) ) {
175 + } elseif ( ! empty( $site__in ) ) {
144 176 $this->index = [];
145 177
146 - foreach ( $scope as $site_id ) {
178 + foreach ( $site__in as $site_id ) {
147 179 $this->index[] = $this->indexable->get_index_name( $site_id );
148 180 }
149 181
150 182 $this->index = implode( ',', $this->index );
183 + } elseif ( ! empty( $site__not_in ) ) {
184 +
185 + $sites = \get_sites(
186 + array(
187 + 'fields' => 'ids',
188 + 'site__not_in' => $site__not_in,
189 + )
190 + );
191 + foreach ( $sites as $site_id ) {
192 + if ( ! Utils\is_site_indexable( $site_id ) ) {
193 + continue;
194 + }
195 + $index[] = Indexables::factory()->get( 'comment' )->get_index_name( $site_id );
196 + }
197 +
198 + $this->index = implode( ',', $index );
199 +
151 200 }
152 201
153 202 $ep_query = $this->indexable->query_es( $formatted_args, $query->query_vars, $this->index, $query );
154 203
@@ -281,9 +330,9 @@
281 330 $child_comments[] = $level_comment;
282 331 }
283 332 }
284 333
285 - $level ++;
334 + ++$level;
286 335 $levels[ $level ] = $child_comments;
287 336 } while ( $child_comments );
288 337
289 338 // Pull out just the descendant comments
@@ -322,6 +371,5 @@
322 371 }
323 372
324 373 return $comments;
325 374 }
326 -
327 375 }