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/AdminNotices.php +273 -130 4.2.05.3.5 View file →
@@ -35,8 +35,9 @@
35 35 protected $notice_keys = [
36 36 'host_error',
37 37 'es_below_compat',
38 38 'es_above_compat',
39 + 'different_server_type',
39 40 'need_setup',
40 41 'no_sync',
41 42 'upgrade_sync',
42 43 'auto_activate_sync',
@@ -42,8 +43,9 @@
42 43 'auto_activate_sync',
43 44 'using_autosuggest_defaults',
44 45 'maybe_wrong_mapping',
45 46 'yellow_health',
47 + 'too_many_fields',
46 48 ];
47 49
48 50 /**
49 51 * Notices that should be shown on a screen
@@ -89,13 +91,9 @@
89 91 if ( ! $feature->is_active() ) {
90 92 return false;
91 93 }
92 94
93 - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
94 - $last_sync = get_site_option( 'ep_last_sync', false );
95 - } else {
96 - $last_sync = get_option( 'ep_last_sync', false );
97 - }
95 + $last_sync = Utils\get_option( 'ep_last_sync', false );
98 96
99 97 if ( empty( $last_sync ) ) {
100 98 return false;
101 99 }
@@ -105,13 +103,9 @@
105 103 if ( empty( $host ) ) {
106 104 return false;
107 105 }
108 106
109 - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
110 - $dismiss = get_site_option( 'ep_hide_using_autosuggest_defaults_notice', false );
111 - } else {
112 - $dismiss = get_option( 'ep_hide_using_autosuggest_defaults_notice', false );
113 - }
107 + $dismiss = Utils\get_option( 'ep_hide_using_autosuggest_defaults_notice', false );
114 108
115 109 if ( $dismiss ) {
116 110 return false;
117 111 }
@@ -121,14 +115,8 @@
121 115 if ( ! in_array( $screen, [ 'dashboard', 'settings' ], true ) ) {
122 116 return false;
123 117 }
124 118
125 - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
126 - $url = admin_url( 'network/admin.php?page=elasticpress&do_sync' );
127 - } else {
128 - $url = admin_url( 'admin.php?page=elasticpress&do_sync' );
129 - }
130 -
131 119 return [
132 120 'html' => sprintf( esc_html__( 'Autosuggest feature is enabled. If documents feature is enabled, your media will also become searchable in the frontend.', 'elasticpress' ) ),
133 121 'type' => 'info',
134 122 'dismiss' => true,
@@ -145,13 +133,9 @@
145 133 * @since 3.0
146 134 * @return array|bool
147 135 */
148 136 protected function process_auto_activate_sync_notice() {
149 - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
150 - $need_upgrade_sync = get_site_option( 'ep_need_upgrade_sync', false );
151 - } else {
152 - $need_upgrade_sync = get_option( 'ep_need_upgrade_sync', false );
153 - }
137 + $need_upgrade_sync = Utils\get_option( 'ep_need_upgrade_sync', false );
154 138
155 139 // need_upgrade_sync takes priority over this notice
156 140 if ( $need_upgrade_sync ) {
157 141 return false;
@@ -156,23 +140,15 @@
156 140 if ( $need_upgrade_sync ) {
157 141 return false;
158 142 }
159 143
160 - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
161 - $auto_activate_sync = get_site_option( 'ep_feature_auto_activated_sync', false );
162 - } else {
163 - $auto_activate_sync = get_option( 'ep_feature_auto_activated_sync', false );
164 - }
144 + $auto_activate_sync = Utils\get_option( 'ep_feature_auto_activated_sync', false );
165 145
166 146 if ( ! $auto_activate_sync ) {
167 147 return false;
168 148 }
169 149
170 - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
171 - $last_sync = get_site_option( 'ep_last_sync', false );
172 - } else {
173 - $last_sync = get_option( 'ep_last_sync', false );
174 - }
150 + $last_sync = Utils\get_option( 'ep_last_sync', false );
175 151
176 152 if ( empty( $last_sync ) ) {
177 153 return false;
178 154 }
@@ -182,13 +158,9 @@
182 158 if ( empty( $host ) ) {
183 159 return false;
184 160 }
185 161
186 - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
187 - $dismiss = get_site_option( 'ep_hide_auto_activate_sync_notice', false );
188 - } else {
189 - $dismiss = get_option( 'ep_hide_auto_activate_sync_notice', false );
190 - }
162 + $dismiss = Utils\get_option( 'ep_hide_auto_activate_sync_notice', false );
191 163
192 164 $screen = Screen::factory()->get_current_screen();
193 165
194 166 if ( 'install' === $screen ) {
@@ -198,24 +170,29 @@
198 170 if ( $dismiss && ! in_array( $screen, [ 'dashboard', 'settings' ], true ) ) {
199 171 return false;
200 172 }
201 173
202 - if ( isset( $_GET['do_sync'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
174 + if ( Utils\isset_do_sync_parameter() ) {
203 175 return false;
204 176 }
205 177
206 - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
207 - $url = admin_url( 'network/admin.php?page=elasticpress-sync&do_sync' );
208 - } else {
209 - $url = admin_url( 'admin.php?page=elasticpress-sync&do_sync' );
210 - }
178 + $url = Utils\get_sync_url( 'features' );
211 179
212 180 $feature = Features::factory()->get_registered_feature( $auto_activate_sync );
213 181
214 182 if ( defined( 'EP_DASHBOARD_SYNC' ) && ! EP_DASHBOARD_SYNC ) {
215 - $html = sprintf( esc_html__( 'Dashboard sync is disabled. The ElasticPress %s feature has been auto-activated! You will need to reindex using WP-CLI for it to work.', 'elasticpress' ), esc_html( is_object( $feature ) ? $feature->title : '' ) );
183 + $html = sprintf(
184 + /* translators: Feature name */
185 + esc_html__( 'Dashboard sync is disabled. The ElasticPress %s feature has been auto-activated! You will need to reindex using WP-CLI for it to work.', 'elasticpress' ),
186 + esc_html( is_object( $feature ) ? $feature->get_short_title() : '' )
187 + );
216 188 } else {
217 - $html = sprintf( __( 'The ElasticPress %1$s feature has been auto-activated! You will need to <a href="%2$s">run a sync</a> for it to work.', 'elasticpress' ), esc_html( is_object( $feature ) ? $feature->title : '' ), esc_url( $url ) );
189 + $html = sprintf(
190 + /* translators: 1. Feature name; 2: Sync page URL */
191 + __( 'The ElasticPress %1$s feature has been auto-activated! You will need to <a href="%2$s">run a sync</a> for it to work.', 'elasticpress' ),
192 + esc_html( is_object( $feature ) ? $feature->get_short_title() : '' ),
193 + esc_url( $url )
194 + );
218 195 }
219 196
220 197 return [
221 198 'html' => $html,
@@ -234,23 +211,15 @@
234 211 * @since 3.0
235 212 * @return array|bool
236 213 */
237 214 protected function process_upgrade_sync_notice() {
238 - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
239 - $need_upgrade_sync = get_site_option( 'ep_need_upgrade_sync', false );
240 - } else {
241 - $need_upgrade_sync = get_option( 'ep_need_upgrade_sync', false );
242 - }
215 + $need_upgrade_sync = Utils\get_option( 'ep_need_upgrade_sync', false );
243 216
244 217 if ( ! $need_upgrade_sync ) {
245 218 return false;
246 219 }
247 220
248 - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
249 - $last_sync = get_site_option( 'ep_last_sync', false );
250 - } else {
251 - $last_sync = get_option( 'ep_last_sync', false );
252 - }
221 + $last_sync = Utils\get_option( 'ep_last_sync', false );
253 222
254 223 if ( empty( $last_sync ) ) {
255 224 return false;
256 225 }
@@ -260,13 +229,9 @@
260 229 if ( empty( $host ) ) {
261 230 return false;
262 231 }
263 232
264 - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
265 - $dismiss = get_site_option( 'ep_hide_upgrade_sync_notice', false );
266 - } else {
267 - $dismiss = get_option( 'ep_hide_upgrade_sync_notice', false );
268 - }
233 + $dismiss = Utils\get_option( 'ep_hide_upgrade_sync_notice', false );
269 234
270 235 $screen = Screen::factory()->get_current_screen();
271 236
272 237 if ( 'install' === $screen ) {
@@ -276,22 +241,22 @@
276 241 if ( $dismiss && ! in_array( $screen, [ 'dashboard', 'settings' ], true ) ) {
277 242 return false;
278 243 }
279 244
280 - if ( isset( $_GET['do_sync'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
245 + if ( Utils\isset_do_sync_parameter() ) {
281 246 return false;
282 247 }
283 248
284 - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
285 - $url = admin_url( 'network/admin.php?page=elasticpress-sync&do_sync' );
286 - } else {
287 - $url = admin_url( 'admin.php?page=elasticpress-sync&do_sync' );
288 - }
249 + $url = Utils\get_sync_url( 'upgrade' );
289 250
290 251 if ( defined( 'EP_DASHBOARD_SYNC' ) && ! EP_DASHBOARD_SYNC ) {
291 252 $html = esc_html__( 'Dashboard sync is disabled. The new version of ElasticPress requires that you delete all data and start a fresh sync using WP-CLI.', 'elasticpress' );
292 253 } else {
293 - $html = sprintf( __( 'The new version of ElasticPress requires that you <a href="%s">delete all data and start a fresh sync</a>.', 'elasticpress' ), esc_url( $url ) );
254 + $html = sprintf(
255 + /* translators: Sync Page URL */
256 + __( 'The new version of ElasticPress requires that you <a href="%s">delete all data and start a fresh sync</a>.', 'elasticpress' ),
257 + esc_url( $url )
258 + );
294 259 }
295 260
296 261 $notice = esc_html__( 'Please note that some ElasticPress functionality may be impaired and/or content may not be searchable until the full sync has been performed.', 'elasticpress' );
297 262
@@ -312,13 +277,9 @@
312 277 * @since 3.0
313 278 * @return array|bool
314 279 */
315 280 protected function process_no_sync_notice() {
316 - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
317 - $last_sync = get_site_option( 'ep_last_sync', false );
318 - } else {
319 - $last_sync = get_option( 'ep_last_sync', false );
320 - }
281 + $last_sync = Utils\get_option( 'ep_last_sync', false );
321 282
322 283 if ( ! empty( $last_sync ) ) {
323 284 return false;
324 285 }
@@ -328,13 +289,9 @@
328 289 if ( empty( $host ) ) {
329 290 return false;
330 291 }
331 292
332 - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
333 - $dismiss = get_site_option( 'ep_hide_no_sync_notice', false );
334 - } else {
335 - $dismiss = get_option( 'ep_hide_no_sync_notice', false );
336 - }
293 + $dismiss = Utils\get_option( 'ep_hide_no_sync_notice', false );
337 294
338 295 $screen = Screen::factory()->get_current_screen();
339 296
340 297 if ( 'install' === $screen ) {
@@ -344,9 +301,9 @@
344 301 if ( $dismiss && ! in_array( $screen, [ 'dashboard', 'settings' ], true ) ) {
345 302 return false;
346 303 }
347 304
348 - if ( isset( $_GET['do_sync'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
305 + if ( Utils\isset_do_sync_parameter() ) {
349 306 return false;
350 307 }
351 308
352 309 if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
@@ -357,9 +314,13 @@
357 314
358 315 if ( defined( 'EP_DASHBOARD_SYNC' ) && ! EP_DASHBOARD_SYNC ) {
359 316 $html = esc_html__( 'Dashboard sync is disabled, but ElasticPress is almost ready to go. Trigger a sync from WP-CLI.', 'elasticpress' );
360 317 } else {
361 - $html = sprintf( __( 'ElasticPress is almost ready to go. You just need to <a href="%s">sync your content</a>.', 'elasticpress' ), esc_url( $url ) );
318 + $html = sprintf(
319 + /* translators: Sync Page URL */
320 + __( 'ElasticPress is almost ready to go. You just need to <a href="%s">sync your content</a>.', 'elasticpress' ),
321 + esc_url( $url )
322 + );
362 323 }
363 324
364 325 return [
365 326 'html' => $html,
@@ -384,13 +345,9 @@
384 345 if ( ! empty( $host ) ) {
385 346 return false;
386 347 }
387 348
388 - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
389 - $dismiss = get_site_option( 'ep_hide_need_setup_notice', false );
390 - } else {
391 - $dismiss = get_option( 'ep_hide_need_setup_notice', false );
392 - }
349 + $dismiss = Utils\get_option( 'ep_hide_need_setup_notice', false );
393 350
394 351 $screen = Screen::factory()->get_current_screen();
395 352
396 353 if ( in_array( $screen, [ 'settings', 'install' ], true ) ) {
@@ -407,11 +364,15 @@
407 364 $url = admin_url( 'admin.php?page=elasticpress-settings' );
408 365 }
409 366
410 367 return [
411 - 'html' => sprintf( __( 'ElasticPress is almost ready to go. You just need to <a href="%s">enter your settings</a>.', 'elasticpress' ), esc_url( $url ) ),
412 368 'type' => 'info',
413 369 'dismiss' => 'dashboard' !== $screen,
370 + 'html' => sprintf(
371 + /* translators: Sync Page URL */
372 + __( 'ElasticPress is almost ready to go. You just need to <a href="%s">enter your settings</a>.', 'elasticpress' ),
373 + esc_url( $url )
374 + ),
414 375 ];
415 376 }
416 377
417 378 /**
@@ -440,13 +401,9 @@
440 401 if ( false === $es_version ) {
441 402 return false;
442 403 }
443 404
444 - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
445 - $dismiss = get_site_option( 'ep_hide_es_below_compat_notice', false );
446 - } else {
447 - $dismiss = get_option( 'ep_hide_es_below_compat_notice', false );
448 - }
405 + $dismiss = Utils\get_option( 'ep_hide_es_below_compat_notice', false );
449 406
450 407 if ( $dismiss ) {
451 408 return false;
452 409 }
@@ -464,11 +421,16 @@
464 421 $major_es_version = implode( '.', $parts );
465 422
466 423 if ( 1 === version_compare( EP_ES_VERSION_MIN, $major_es_version ) ) {
467 424 return [
468 - 'html' => sprintf( __( 'Your Elasticsearch version %1$s is below the minimum required Elasticsearch version %2$s. ElasticPress may or may not work properly.', 'elasticpress' ), esc_html( $es_version ), esc_html( EP_ES_VERSION_MIN ) ),
469 425 'type' => 'error',
470 426 'dismiss' => true,
427 + 'html' => sprintf(
428 + /* translators: 1. Current Elasticsearch version; 2. Minimum required ES version */
429 + __( 'Your Elasticsearch version %1$s is below the minimum required Elasticsearch version %2$s. ElasticPress may or may not work properly.', 'elasticpress' ),
430 + esc_html( $es_version ),
431 + esc_html( EP_ES_VERSION_MIN )
432 + ),
471 433 ];
472 434 }
473 435
474 436 return false;
@@ -500,13 +462,9 @@
500 462 if ( false === $es_version ) {
501 463 return false;
502 464 }
503 465
504 - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
505 - $dismiss = get_site_option( 'ep_hide_es_above_compat_notice', false );
506 - } else {
507 - $dismiss = get_option( 'ep_hide_es_above_compat_notice', false );
508 - }
466 + $dismiss = Utils\get_option( 'ep_hide_es_above_compat_notice', false );
509 467
510 468 if ( $dismiss ) {
511 469 return false;
512 470 }
@@ -515,16 +473,68 @@
515 473 $major_es_version = preg_replace( '#^([0-9]+\.[0-9]+).*#', '$1', $es_version );
516 474
517 475 if ( -1 === version_compare( EP_ES_VERSION_MAX, $major_es_version ) ) {
518 476 return [
519 - 'html' => sprintf( __( 'Your Elasticsearch version %1$s is above the maximum required Elasticsearch version %2$s. ElasticPress may or may not work properly.', 'elasticpress' ), esc_html( $es_version ), esc_html( EP_ES_VERSION_MAX ) ),
520 477 'type' => 'warning',
521 478 'dismiss' => true,
479 + 'html' => sprintf(
480 + /* translators: 1. Current Elasticsearch version; 2. Maximum supported ES version */
481 + __( 'Your Elasticsearch version %1$s is above the maximum required Elasticsearch version %2$s. ElasticPress may or may not work properly.', 'elasticpress' ),
482 + esc_html( $es_version ),
483 + esc_html( EP_ES_VERSION_MAX )
484 + ),
522 485 ];
523 486 }
524 487 }
525 488
526 489 /**
490 + * Server software different from Elasticsearch warning.
491 + *
492 + * Type: warning
493 + * Dismiss: Anywhere
494 + * Show: All screens
495 + *
496 + * @since 4.2.1
497 + * @return array|bool
498 + */
499 + protected function process_different_server_type_notice() {
500 + if ( Utils\is_epio() ) {
501 + return false;
502 + }
503 +
504 + $host = Utils\get_host();
505 +
506 + if ( empty( $host ) ) {
507 + return false;
508 + }
509 +
510 + $server_type = Elasticsearch::factory()->get_server_type();
511 +
512 + if ( false === $server_type || 'elasticsearch' === $server_type ) {
513 + return false;
514 + }
515 +
516 + $dismiss = Utils\get_option( 'ep_hide_different_server_type_notice', false );
517 +
518 + if ( $dismiss ) {
519 + return false;
520 + }
521 +
522 + $doc_url = 'https://www.elasticpress.io/resources/articles/compatibility/';
523 + $html = sprintf(
524 + /* translators: Document page URL */
525 + __( 'Your server software is not supported. To learn more about server compatibility please <a href="%s">visit our documentation</a>.', 'elasticpress' ),
526 + esc_url( $doc_url )
527 + );
528 +
529 + return [
530 + 'html' => $html,
531 + 'type' => 'warning',
532 + 'dismiss' => true,
533 + ];
534 + }
535 +
536 + /**
527 537 * Host error notification. Shows when EP can't reach ES host.
528 538 *
529 539 * Type: error
530 540 * Dismiss: Only on non-EP screens
@@ -553,13 +563,9 @@
553 563 }
554 564
555 565 // Only dismissable on non-EP screens
556 566 if ( ! in_array( $screen, [ 'settings', 'dashboard' ], true ) ) {
557 - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
558 - $dismiss = get_site_option( 'ep_hide_host_error_notice', false );
559 - } else {
560 - $dismiss = get_option( 'ep_hide_host_error_notice', false );
561 - }
567 + $dismiss = Utils\get_option( 'ep_hide_host_error_notice', false );
562 568
563 569 if ( $dismiss ) {
564 570 return false;
565 571 }
@@ -574,16 +580,30 @@
574 580 $response_code = get_transient( 'ep_es_info_response_code' );
575 581 $response_error = get_transient( 'ep_es_info_response_error' );
576 582 }
577 583
578 - $html = sprintf( __( 'There is a problem with connecting to your Elasticsearch host. ElasticPress can <a href="%1$s">try your host again</a>, or you may need to <a href="%2$s">change your settings</a>.', 'elasticpress' ), esc_url( add_query_arg( 'ep-retry', 1 ) ), esc_url( $url ) );
584 + $retry_url = add_query_arg(
585 + [
586 + 'ep-retry' => 1,
587 + 'ep_retry_nonce' => wp_create_nonce( 'ep_retry_nonce' ),
588 + ]
589 + );
579 590
591 + $html = sprintf(
592 + /* translators: 1. Current URL with retry parameter; 2. Settings Page URL */
593 + __( 'There is a problem with connecting to your Elasticsearch host. ElasticPress can <a href="%1$s">try your host again</a>, or you may need to <a href="%2$s">change your settings</a>.', 'elasticpress' ),
594 + esc_url( $retry_url ),
595 + esc_url( $url )
596 + );
597 +
580 598 if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
581 599 if ( ! empty( $response_code ) ) {
600 + /* translators: Response Code Number */
582 601 $html .= '<span class="notice-error-es-response-code"> ' . sprintf( __( 'Response Code: %s', 'elasticpress' ), esc_html( $response_code ) ) . '</span>';
583 602 }
584 603
585 604 if ( ! empty( $response_error ) ) {
605 + /* translators: Response Code Message */
586 606 $html .= '<span class="notice-error-es-response-error"> ' . sprintf( __( 'Response error: %s', 'elasticpress' ), esc_html( $response_error ) ) . '</span>';
587 607 }
588 608 }
589 609
@@ -611,13 +631,9 @@
611 631 return false;
612 632 }
613 633
614 634 // we might have this dismissed
615 - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
616 - $dismiss = get_site_option( 'ep_hide_maybe_wrong_mapping_notice', false );
617 - } else {
618 - $dismiss = get_option( 'ep_hide_maybe_wrong_mapping_notice', false );
619 - }
635 + $dismiss = Utils\get_option( 'ep_hide_maybe_wrong_mapping_notice', false );
620 636
621 637 // we need a host
622 638 $host = Utils\get_host();
623 639 if ( empty( $host ) ) {
@@ -631,13 +647,9 @@
631 647 return false;
632 648 }
633 649
634 650 // we also likely need a sync to have a mapping
635 - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
636 - $last_sync = get_site_option( 'ep_last_sync', false );
637 - } else {
638 - $last_sync = get_option( 'ep_last_sync', false );
639 - }
651 + $last_sync = Utils\get_option( 'ep_last_sync', false );
640 652
641 653 if ( empty( $last_sync ) ) {
642 654 return false;
643 655 }
@@ -658,8 +670,9 @@
658 670 '</em>'
659 671 );
660 672
661 673 if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
674 + /* translators: 1. Current mapping file; 2. Mapping file that should be used */
662 675 $html .= '<span class="notice-error-es-response-code"> ' . sprintf( esc_html__( 'Current mapping: %1$s. Expected mapping: %2$s', 'elasticpress' ), esc_html( $mapping_file_current ), esc_html( $mapping_file_wanted ) ) . '</span>';
663 676 }
664 677
665 678 return [
@@ -668,9 +681,8 @@
668 681 'dismiss' => true,
669 682 ];
670 683
671 684 }
672 -
673 685 }
674 686
675 687 /**
676 688 * Single node notification. Shows when index health is yellow.
@@ -688,23 +700,15 @@
688 700 if ( empty( $host ) ) {
689 701 return false;
690 702 }
691 703
692 - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
693 - $last_sync = get_site_option( 'ep_last_sync', false );
694 - } else {
695 - $last_sync = get_option( 'ep_last_sync', false );
696 - }
704 + $last_sync = Utils\get_option( 'ep_last_sync', false );
697 705
698 706 if ( empty( $last_sync ) ) {
699 707 return false;
700 708 }
701 709
702 - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
703 - $dismiss = get_site_option( 'ep_hide_yellow_health_notice', false );
704 - } else {
705 - $dismiss = get_option( 'ep_hide_yellow_health_notice', false );
706 - }
710 + $dismiss = Utils\get_option( 'ep_hide_yellow_health_notice', false );
707 711
708 712 $screen = Screen::factory()->get_current_screen();
709 713
710 714 if ( ! in_array( $screen, [ 'dashboard', 'settings' ], true ) || $dismiss ) {
@@ -720,16 +724,101 @@
720 724 $url = admin_url( 'admin.php?page=elasticpress-health' );
721 725 }
722 726
723 727 return [
724 - 'html' => sprintf( __( 'It looks like one or more of your indices are running on a single node. While this won\'t prevent you from using ElasticPress, depending on your site\'s specific needs this can represent a performance issue. Please check the <a href="%1$s">Index Health</a> page where you can check the health of all of your indices.', 'elasticpress' ), $url ),
725 728 'type' => 'warning',
726 729 'dismiss' => true,
730 + 'html' => sprintf(
731 + /* translators: Index Health URL */
732 + __( 'It looks like one or more of your indices are running on a single node. While this won\'t prevent you from using ElasticPress, depending on your site\'s specific needs this can represent a performance issue. Please check the <a href="%s">Index Health</a> page where you can check the health of all of your indices.', 'elasticpress' ),
733 + $url
734 + ),
727 735 ];
728 736 }
729 737 }
730 738
731 739 /**
740 + * Too many fields notification. Shows when the site has potentially more fields than ES could handle.
741 + *
742 + * Type: warning|error
743 + * Dismiss: Anywhere
744 + * Show: Sync and Install page
745 + *
746 + * @since 4.4.0
747 + * @return array|bool
748 + */
749 + protected function process_too_many_fields_notice() {
750 + $host = Utils\get_host();
751 +
752 + if ( empty( $host ) ) {
753 + return false;
754 + }
755 +
756 + $dismiss = Utils\get_option( 'ep_hide_too_many_fields_notice', false );
757 +
758 + $screen = Screen::factory()->get_current_screen();
759 +
760 + if ( ! in_array( $screen, [ 'install', 'sync' ], true ) || $dismiss ) {
761 + return false;
762 + }
763 +
764 + $has_error = false;
765 + $has_warning = false;
766 +
767 + if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
768 + $sites = Utils\get_sites( 0, true );
769 + foreach ( $sites as $site ) {
770 + switch_to_blog( $site['blog_id'] );
771 +
772 + list( $has_error, $site_has_warning ) = $this->check_field_count();
773 +
774 + restore_current_blog();
775 +
776 + $has_warning = $has_warning || $site_has_warning;
777 + if ( $has_error ) {
778 + break;
779 + }
780 + }
781 + } else {
782 + list( $has_error, $has_warning ) = $this->check_field_count();
783 + }
784 +
785 + if ( $has_error ) {
786 + $message = sprintf(
787 + /* translators: Elasticsearch or ElasticPress.io; 2. Link to article; 3. Link to article */
788 + __( 'Your website content has more public custom fields than %1$s is able to store. Check our articles about <a href="%2$s">Elasticsearch field limitations</a> and <a href="%3$s">how to index just the custom fields you need</a> before trying to sync.', 'elasticpress' ),
789 + Utils\is_epio() ? __( 'ElasticPress.io', 'elasticpress' ) : __( 'Elasticsearch', 'elasticpress' ),
790 + 'https://www.elasticpress.io/resources/articles/i-get-the-error-limit-of-total-fields-in-index-has-been-exceeded/',
791 + 'https://www.elasticpress.io/resources/articles/how-to-exclude-metadata-from-indexing/'
792 + );
793 +
794 + return [
795 + 'type' => 'error',
796 + 'dismiss' => true,
797 + 'html' => $message,
798 + ];
799 + }
800 +
801 + if ( $has_warning ) {
802 + $message = sprintf(
803 + /* translators: Elasticsearch or ElasticPress.io; 2. Link to article; 3. Link to article */
804 + __( 'Your website content seems to have more public custom fields than %1$s is able to store. Check our articles about <a href="%2$s">Elasticsearch field limitations</a> and <a href="%3$s">how to index just the custom fields you need</a> if you receive any errors while syncing.', 'elasticpress' ),
805 + Utils\is_epio() ? __( 'ElasticPress.io', 'elasticpress' ) : __( 'Elasticsearch', 'elasticpress' ),
806 + 'https://www.elasticpress.io/resources/articles/i-get-the-error-limit-of-total-fields-in-index-has-been-exceeded/',
807 + 'https://www.elasticpress.io/resources/articles/how-to-exclude-metadata-from-indexing/'
808 + );
809 +
810 + return [
811 + 'type' => 'warning',
812 + 'dismiss' => true,
813 + 'html' => $message,
814 + ];
815 + }
816 +
817 + return false;
818 + }
819 +
820 + /**
732 821 * Get notices that should be displayed
733 822 *
734 823 * @since 3.0
735 824 * @return array
@@ -741,9 +830,35 @@
741 830 * @hook ep_admin_notices
742 831 * @param {array} $notices Admin notices
743 832 * @return {array} New notices
744 833 */
745 - return apply_filters( 'ep_admin_notices', $this->notices );
834 + $notices = apply_filters( 'ep_admin_notices', $this->notices );
835 +
836 + if ( ! is_array( $notices ) ) {
837 + _doing_it_wrong(
838 + __METHOD__,
839 + sprintf(
840 + /* translators: %s: Detected variable type. */
841 + esc_html__( 'Callbacks of filter hook `ep_admin_notices` must return a value of type array, %s detected.', 'elasticpress' ),
842 + esc_html( gettype( $notices ) )
843 + ),
844 + 'ElasticPress 5.3.3'
845 + );
846 +
847 + $notices = [];
848 + }
849 +
850 + // If the plugin is network-activated and not in the network admin, return the notices whose scope is site.
851 + if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK && ! is_network_admin() ) {
852 + $notices = array_filter(
853 + $notices,
854 + function ( $notice ) {
855 + return isset( $notice['scope'] ) && 'site' === $notice['scope'];
856 + }
857 + );
858 + }
859 +
860 + return $notices;
746 861 }
747 862
748 863 /**
749 864 * Dismiss a notice given a notice key.
@@ -756,13 +871,10 @@
756 871 // allow version dependent dismissal
757 872 if ( in_array( $notice, [ 'maybe_wrong_mapping' ], true ) ) {
758 873 $value = Elasticsearch::factory()->get_elasticsearch_version( false );
759 874 }
760 - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
761 - update_site_option( 'ep_hide_' . $notice . '_notice', $value );
762 - } else {
763 - update_option( 'ep_hide_' . $notice . '_notice', $value );
764 - }
875 +
876 + Utils\update_option( 'ep_hide_' . $notice . '_notice', $value );
765 877 }
766 878
767 879 /**
768 880 * Return singleton instance of class
@@ -777,6 +889,37 @@
777 889 $instance = new self();
778 890 }
779 891
780 892 return $instance;
893 + }
894 +
895 + /**
896 + * Compare the number of fields in the site and the number of allowed fields in ES
897 + *
898 + * @since 4.4.0
899 + * @return array
900 + */
901 + protected function check_field_count() {
902 + $post_indexable = Indexables::factory()->get( 'post' );
903 +
904 + $search = Features::factory()->get_registered_feature( 'search' );
905 + if ( $search && ! empty( $search->weighting ) && 'manual' === $search->weighting->get_meta_mode() ) {
906 + $indexable_fields = $post_indexable->get_all_allowed_metas_manual();
907 + $count_fields_db = count( $indexable_fields );
908 + } else {
909 + $indexable_fields = $post_indexable->get_predicted_indexable_meta_keys();
910 + $count_fields_db = count( $indexable_fields );
911 + }
912 +
913 + $index_name = $post_indexable->get_index_name();
914 + $es_field_limit = Elasticsearch::factory()->get_index_total_fields_limit( $index_name );
915 + $es_field_limit = $es_field_limit ? $es_field_limit : 5000;
916 + $es_field_limit = apply_filters( 'ep_total_field_limit', $es_field_limit );
917 +
918 + $predicted_es_field_count = $count_fields_db * 8;
919 +
920 + return [
921 + $predicted_es_field_count > $es_field_limit,
922 + $predicted_es_field_count * 1.2 > $es_field_limit,
923 + ];
781 924 }
782 925 }