| @@ -43,8 +43,9 @@ | ||
| 43 | 43 | 'auto_activate_sync', |
| 44 | 44 | 'using_autosuggest_defaults', |
| 45 | 45 | 'maybe_wrong_mapping', |
| 46 | 46 | 'yellow_health', |
| 47 | + 'too_many_fields', | |
| 47 | 48 | ]; |
| 48 | 49 | |
| 49 | 50 | /** |
| 50 | 51 | * Notices that should be shown on a screen |
| @@ -90,13 +91,9 @@ | ||
| 90 | 91 | if ( ! $feature->is_active() ) { |
| 91 | 92 | return false; |
| 92 | 93 | } |
| 93 | 94 | |
| 94 | - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) { | |
| 95 | - $last_sync = get_site_option( 'ep_last_sync', false ); | |
| 96 | - } else { | |
| 97 | - $last_sync = get_option( 'ep_last_sync', false ); | |
| 98 | - } | |
| 95 | + $last_sync = Utils\get_option( 'ep_last_sync', false ); | |
| 99 | 96 | |
| 100 | 97 | if ( empty( $last_sync ) ) { |
| 101 | 98 | return false; |
| 102 | 99 | } |
| @@ -106,13 +103,9 @@ | ||
| 106 | 103 | if ( empty( $host ) ) { |
| 107 | 104 | return false; |
| 108 | 105 | } |
| 109 | 106 | |
| 110 | - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) { | |
| 111 | - $dismiss = get_site_option( 'ep_hide_using_autosuggest_defaults_notice', false ); | |
| 112 | - } else { | |
| 113 | - $dismiss = get_option( 'ep_hide_using_autosuggest_defaults_notice', false ); | |
| 114 | - } | |
| 107 | + $dismiss = Utils\get_option( 'ep_hide_using_autosuggest_defaults_notice', false ); | |
| 115 | 108 | |
| 116 | 109 | if ( $dismiss ) { |
| 117 | 110 | return false; |
| 118 | 111 | } |
| @@ -122,14 +115,8 @@ | ||
| 122 | 115 | if ( ! in_array( $screen, [ 'dashboard', 'settings' ], true ) ) { |
| 123 | 116 | return false; |
| 124 | 117 | } |
| 125 | 118 | |
| 126 | - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) { | |
| 127 | - $url = admin_url( 'network/admin.php?page=elasticpress&do_sync' ); | |
| 128 | - } else { | |
| 129 | - $url = admin_url( 'admin.php?page=elasticpress&do_sync' ); | |
| 130 | - } | |
| 131 | - | |
| 132 | 119 | return [ |
| 133 | 120 | 'html' => sprintf( esc_html__( 'Autosuggest feature is enabled. If documents feature is enabled, your media will also become searchable in the frontend.', 'elasticpress' ) ), |
| 134 | 121 | 'type' => 'info', |
| 135 | 122 | 'dismiss' => true, |
| @@ -146,13 +133,9 @@ | ||
| 146 | 133 | * @since 3.0 |
| 147 | 134 | * @return array|bool |
| 148 | 135 | */ |
| 149 | 136 | protected function process_auto_activate_sync_notice() { |
| 150 | - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) { | |
| 151 | - $need_upgrade_sync = get_site_option( 'ep_need_upgrade_sync', false ); | |
| 152 | - } else { | |
| 153 | - $need_upgrade_sync = get_option( 'ep_need_upgrade_sync', false ); | |
| 154 | - } | |
| 137 | + $need_upgrade_sync = Utils\get_option( 'ep_need_upgrade_sync', false ); | |
| 155 | 138 | |
| 156 | 139 | // need_upgrade_sync takes priority over this notice |
| 157 | 140 | if ( $need_upgrade_sync ) { |
| 158 | 141 | return false; |
| @@ -157,23 +140,15 @@ | ||
| 157 | 140 | if ( $need_upgrade_sync ) { |
| 158 | 141 | return false; |
| 159 | 142 | } |
| 160 | 143 | |
| 161 | - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) { | |
| 162 | - $auto_activate_sync = get_site_option( 'ep_feature_auto_activated_sync', false ); | |
| 163 | - } else { | |
| 164 | - $auto_activate_sync = get_option( 'ep_feature_auto_activated_sync', false ); | |
| 165 | - } | |
| 144 | + $auto_activate_sync = Utils\get_option( 'ep_feature_auto_activated_sync', false ); | |
| 166 | 145 | |
| 167 | 146 | if ( ! $auto_activate_sync ) { |
| 168 | 147 | return false; |
| 169 | 148 | } |
| 170 | 149 | |
| 171 | - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) { | |
| 172 | - $last_sync = get_site_option( 'ep_last_sync', false ); | |
| 173 | - } else { | |
| 174 | - $last_sync = get_option( 'ep_last_sync', false ); | |
| 175 | - } | |
| 150 | + $last_sync = Utils\get_option( 'ep_last_sync', false ); | |
| 176 | 151 | |
| 177 | 152 | if ( empty( $last_sync ) ) { |
| 178 | 153 | return false; |
| 179 | 154 | } |
| @@ -183,13 +158,9 @@ | ||
| 183 | 158 | if ( empty( $host ) ) { |
| 184 | 159 | return false; |
| 185 | 160 | } |
| 186 | 161 | |
| 187 | - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) { | |
| 188 | - $dismiss = get_site_option( 'ep_hide_auto_activate_sync_notice', false ); | |
| 189 | - } else { | |
| 190 | - $dismiss = get_option( 'ep_hide_auto_activate_sync_notice', false ); | |
| 191 | - } | |
| 162 | + $dismiss = Utils\get_option( 'ep_hide_auto_activate_sync_notice', false ); | |
| 192 | 163 | |
| 193 | 164 | $screen = Screen::factory()->get_current_screen(); |
| 194 | 165 | |
| 195 | 166 | if ( 'install' === $screen ) { |
| @@ -199,24 +170,29 @@ | ||
| 199 | 170 | if ( $dismiss && ! in_array( $screen, [ 'dashboard', 'settings' ], true ) ) { |
| 200 | 171 | return false; |
| 201 | 172 | } |
| 202 | 173 | |
| 203 | - if ( isset( $_GET['do_sync'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification | |
| 174 | + if ( Utils\isset_do_sync_parameter() ) { | |
| 204 | 175 | return false; |
| 205 | 176 | } |
| 206 | 177 | |
| 207 | - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) { | |
| 208 | - $url = admin_url( 'network/admin.php?page=elasticpress-sync&do_sync' ); | |
| 209 | - } else { | |
| 210 | - $url = admin_url( 'admin.php?page=elasticpress-sync&do_sync' ); | |
| 211 | - } | |
| 178 | + $url = Utils\get_sync_url( 'features' ); | |
| 212 | 179 | |
| 213 | 180 | $feature = Features::factory()->get_registered_feature( $auto_activate_sync ); |
| 214 | 181 | |
| 215 | 182 | if ( defined( 'EP_DASHBOARD_SYNC' ) && ! EP_DASHBOARD_SYNC ) { |
| 216 | - $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 | + ); | |
| 217 | 188 | } else { |
| 218 | - $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 | + ); | |
| 219 | 195 | } |
| 220 | 196 | |
| 221 | 197 | return [ |
| 222 | 198 | 'html' => $html, |
| @@ -235,23 +211,15 @@ | ||
| 235 | 211 | * @since 3.0 |
| 236 | 212 | * @return array|bool |
| 237 | 213 | */ |
| 238 | 214 | protected function process_upgrade_sync_notice() { |
| 239 | - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) { | |
| 240 | - $need_upgrade_sync = get_site_option( 'ep_need_upgrade_sync', false ); | |
| 241 | - } else { | |
| 242 | - $need_upgrade_sync = get_option( 'ep_need_upgrade_sync', false ); | |
| 243 | - } | |
| 215 | + $need_upgrade_sync = Utils\get_option( 'ep_need_upgrade_sync', false ); | |
| 244 | 216 | |
| 245 | 217 | if ( ! $need_upgrade_sync ) { |
| 246 | 218 | return false; |
| 247 | 219 | } |
| 248 | 220 | |
| 249 | - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) { | |
| 250 | - $last_sync = get_site_option( 'ep_last_sync', false ); | |
| 251 | - } else { | |
| 252 | - $last_sync = get_option( 'ep_last_sync', false ); | |
| 253 | - } | |
| 221 | + $last_sync = Utils\get_option( 'ep_last_sync', false ); | |
| 254 | 222 | |
| 255 | 223 | if ( empty( $last_sync ) ) { |
| 256 | 224 | return false; |
| 257 | 225 | } |
| @@ -261,13 +229,9 @@ | ||
| 261 | 229 | if ( empty( $host ) ) { |
| 262 | 230 | return false; |
| 263 | 231 | } |
| 264 | 232 | |
| 265 | - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) { | |
| 266 | - $dismiss = get_site_option( 'ep_hide_upgrade_sync_notice', false ); | |
| 267 | - } else { | |
| 268 | - $dismiss = get_option( 'ep_hide_upgrade_sync_notice', false ); | |
| 269 | - } | |
| 233 | + $dismiss = Utils\get_option( 'ep_hide_upgrade_sync_notice', false ); | |
| 270 | 234 | |
| 271 | 235 | $screen = Screen::factory()->get_current_screen(); |
| 272 | 236 | |
| 273 | 237 | if ( 'install' === $screen ) { |
| @@ -277,22 +241,22 @@ | ||
| 277 | 241 | if ( $dismiss && ! in_array( $screen, [ 'dashboard', 'settings' ], true ) ) { |
| 278 | 242 | return false; |
| 279 | 243 | } |
| 280 | 244 | |
| 281 | - if ( isset( $_GET['do_sync'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification | |
| 245 | + if ( Utils\isset_do_sync_parameter() ) { | |
| 282 | 246 | return false; |
| 283 | 247 | } |
| 284 | 248 | |
| 285 | - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) { | |
| 286 | - $url = admin_url( 'network/admin.php?page=elasticpress-sync&do_sync' ); | |
| 287 | - } else { | |
| 288 | - $url = admin_url( 'admin.php?page=elasticpress-sync&do_sync' ); | |
| 289 | - } | |
| 249 | + $url = Utils\get_sync_url( 'upgrade' ); | |
| 290 | 250 | |
| 291 | 251 | if ( defined( 'EP_DASHBOARD_SYNC' ) && ! EP_DASHBOARD_SYNC ) { |
| 292 | 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' ); |
| 293 | 253 | } else { |
| 294 | - $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 | + ); | |
| 295 | 259 | } |
| 296 | 260 | |
| 297 | 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' ); |
| 298 | 262 | |
| @@ -313,13 +277,9 @@ | ||
| 313 | 277 | * @since 3.0 |
| 314 | 278 | * @return array|bool |
| 315 | 279 | */ |
| 316 | 280 | protected function process_no_sync_notice() { |
| 317 | - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) { | |
| 318 | - $last_sync = get_site_option( 'ep_last_sync', false ); | |
| 319 | - } else { | |
| 320 | - $last_sync = get_option( 'ep_last_sync', false ); | |
| 321 | - } | |
| 281 | + $last_sync = Utils\get_option( 'ep_last_sync', false ); | |
| 322 | 282 | |
| 323 | 283 | if ( ! empty( $last_sync ) ) { |
| 324 | 284 | return false; |
| 325 | 285 | } |
| @@ -329,13 +289,9 @@ | ||
| 329 | 289 | if ( empty( $host ) ) { |
| 330 | 290 | return false; |
| 331 | 291 | } |
| 332 | 292 | |
| 333 | - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) { | |
| 334 | - $dismiss = get_site_option( 'ep_hide_no_sync_notice', false ); | |
| 335 | - } else { | |
| 336 | - $dismiss = get_option( 'ep_hide_no_sync_notice', false ); | |
| 337 | - } | |
| 293 | + $dismiss = Utils\get_option( 'ep_hide_no_sync_notice', false ); | |
| 338 | 294 | |
| 339 | 295 | $screen = Screen::factory()->get_current_screen(); |
| 340 | 296 | |
| 341 | 297 | if ( 'install' === $screen ) { |
| @@ -345,9 +301,9 @@ | ||
| 345 | 301 | if ( $dismiss && ! in_array( $screen, [ 'dashboard', 'settings' ], true ) ) { |
| 346 | 302 | return false; |
| 347 | 303 | } |
| 348 | 304 | |
| 349 | - if ( isset( $_GET['do_sync'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification | |
| 305 | + if ( Utils\isset_do_sync_parameter() ) { | |
| 350 | 306 | return false; |
| 351 | 307 | } |
| 352 | 308 | |
| 353 | 309 | if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) { |
| @@ -358,9 +314,13 @@ | ||
| 358 | 314 | |
| 359 | 315 | if ( defined( 'EP_DASHBOARD_SYNC' ) && ! EP_DASHBOARD_SYNC ) { |
| 360 | 316 | $html = esc_html__( 'Dashboard sync is disabled, but ElasticPress is almost ready to go. Trigger a sync from WP-CLI.', 'elasticpress' ); |
| 361 | 317 | } else { |
| 362 | - $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 | + ); | |
| 363 | 323 | } |
| 364 | 324 | |
| 365 | 325 | return [ |
| 366 | 326 | 'html' => $html, |
| @@ -385,13 +345,9 @@ | ||
| 385 | 345 | if ( ! empty( $host ) ) { |
| 386 | 346 | return false; |
| 387 | 347 | } |
| 388 | 348 | |
| 389 | - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) { | |
| 390 | - $dismiss = get_site_option( 'ep_hide_need_setup_notice', false ); | |
| 391 | - } else { | |
| 392 | - $dismiss = get_option( 'ep_hide_need_setup_notice', false ); | |
| 393 | - } | |
| 349 | + $dismiss = Utils\get_option( 'ep_hide_need_setup_notice', false ); | |
| 394 | 350 | |
| 395 | 351 | $screen = Screen::factory()->get_current_screen(); |
| 396 | 352 | |
| 397 | 353 | if ( in_array( $screen, [ 'settings', 'install' ], true ) ) { |
| @@ -408,11 +364,15 @@ | ||
| 408 | 364 | $url = admin_url( 'admin.php?page=elasticpress-settings' ); |
| 409 | 365 | } |
| 410 | 366 | |
| 411 | 367 | return [ |
| 412 | - 'html' => sprintf( __( 'ElasticPress is almost ready to go. You just need to <a href="%s">enter your settings</a>.', 'elasticpress' ), esc_url( $url ) ), | |
| 413 | 368 | 'type' => 'info', |
| 414 | 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 | + ), | |
| 415 | 375 | ]; |
| 416 | 376 | } |
| 417 | 377 | |
| 418 | 378 | /** |
| @@ -441,13 +401,9 @@ | ||
| 441 | 401 | if ( false === $es_version ) { |
| 442 | 402 | return false; |
| 443 | 403 | } |
| 444 | 404 | |
| 445 | - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) { | |
| 446 | - $dismiss = get_site_option( 'ep_hide_es_below_compat_notice', false ); | |
| 447 | - } else { | |
| 448 | - $dismiss = get_option( 'ep_hide_es_below_compat_notice', false ); | |
| 449 | - } | |
| 405 | + $dismiss = Utils\get_option( 'ep_hide_es_below_compat_notice', false ); | |
| 450 | 406 | |
| 451 | 407 | if ( $dismiss ) { |
| 452 | 408 | return false; |
| 453 | 409 | } |
| @@ -465,11 +421,16 @@ | ||
| 465 | 421 | $major_es_version = implode( '.', $parts ); |
| 466 | 422 | |
| 467 | 423 | if ( 1 === version_compare( EP_ES_VERSION_MIN, $major_es_version ) ) { |
| 468 | 424 | return [ |
| 469 | - '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 ) ), | |
| 470 | 425 | 'type' => 'error', |
| 471 | 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 | + ), | |
| 472 | 433 | ]; |
| 473 | 434 | } |
| 474 | 435 | |
| 475 | 436 | return false; |
| @@ -501,13 +462,9 @@ | ||
| 501 | 462 | if ( false === $es_version ) { |
| 502 | 463 | return false; |
| 503 | 464 | } |
| 504 | 465 | |
| 505 | - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) { | |
| 506 | - $dismiss = get_site_option( 'ep_hide_es_above_compat_notice', false ); | |
| 507 | - } else { | |
| 508 | - $dismiss = get_option( 'ep_hide_es_above_compat_notice', false ); | |
| 509 | - } | |
| 466 | + $dismiss = Utils\get_option( 'ep_hide_es_above_compat_notice', false ); | |
| 510 | 467 | |
| 511 | 468 | if ( $dismiss ) { |
| 512 | 469 | return false; |
| 513 | 470 | } |
| @@ -516,11 +473,16 @@ | ||
| 516 | 473 | $major_es_version = preg_replace( '#^([0-9]+\.[0-9]+).*#', '$1', $es_version ); |
| 517 | 474 | |
| 518 | 475 | if ( -1 === version_compare( EP_ES_VERSION_MAX, $major_es_version ) ) { |
| 519 | 476 | return [ |
| 520 | - '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 ) ), | |
| 521 | 477 | 'type' => 'warning', |
| 522 | 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 | + ), | |
| 523 | 485 | ]; |
| 524 | 486 | } |
| 525 | 487 | } |
| 526 | 488 | |
| @@ -556,11 +518,11 @@ | ||
| 556 | 518 | if ( $dismiss ) { |
| 557 | 519 | return false; |
| 558 | 520 | } |
| 559 | 521 | |
| 560 | - $doc_url = 'https://10up.github.io/ElasticPress/tutorial-compatibility.html'; | |
| 522 | + $doc_url = 'https://www.elasticpress.io/resources/articles/compatibility/'; | |
| 561 | 523 | $html = sprintf( |
| 562 | - /* translator: Document page URL */ | |
| 524 | + /* translators: Document page URL */ | |
| 563 | 525 | __( 'Your server software is not supported. To learn more about server compatibility please <a href="%s">visit our documentation</a>.', 'elasticpress' ), |
| 564 | 526 | esc_url( $doc_url ) |
| 565 | 527 | ); |
| 566 | 528 | |
| @@ -601,13 +563,9 @@ | ||
| 601 | 563 | } |
| 602 | 564 | |
| 603 | 565 | // Only dismissable on non-EP screens |
| 604 | 566 | if ( ! in_array( $screen, [ 'settings', 'dashboard' ], true ) ) { |
| 605 | - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) { | |
| 606 | - $dismiss = get_site_option( 'ep_hide_host_error_notice', false ); | |
| 607 | - } else { | |
| 608 | - $dismiss = get_option( 'ep_hide_host_error_notice', false ); | |
| 609 | - } | |
| 567 | + $dismiss = Utils\get_option( 'ep_hide_host_error_notice', false ); | |
| 610 | 568 | |
| 611 | 569 | if ( $dismiss ) { |
| 612 | 570 | return false; |
| 613 | 571 | } |
| @@ -622,16 +580,30 @@ | ||
| 622 | 580 | $response_code = get_transient( 'ep_es_info_response_code' ); |
| 623 | 581 | $response_error = get_transient( 'ep_es_info_response_error' ); |
| 624 | 582 | } |
| 625 | 583 | |
| 626 | - $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 | + ); | |
| 627 | 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 | + | |
| 628 | 598 | if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
| 629 | 599 | if ( ! empty( $response_code ) ) { |
| 600 | + /* translators: Response Code Number */ | |
| 630 | 601 | $html .= '<span class="notice-error-es-response-code"> ' . sprintf( __( 'Response Code: %s', 'elasticpress' ), esc_html( $response_code ) ) . '</span>'; |
| 631 | 602 | } |
| 632 | 603 | |
| 633 | 604 | if ( ! empty( $response_error ) ) { |
| 605 | + /* translators: Response Code Message */ | |
| 634 | 606 | $html .= '<span class="notice-error-es-response-error"> ' . sprintf( __( 'Response error: %s', 'elasticpress' ), esc_html( $response_error ) ) . '</span>'; |
| 635 | 607 | } |
| 636 | 608 | } |
| 637 | 609 | |
| @@ -659,13 +631,9 @@ | ||
| 659 | 631 | return false; |
| 660 | 632 | } |
| 661 | 633 | |
| 662 | 634 | // we might have this dismissed |
| 663 | - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) { | |
| 664 | - $dismiss = get_site_option( 'ep_hide_maybe_wrong_mapping_notice', false ); | |
| 665 | - } else { | |
| 666 | - $dismiss = get_option( 'ep_hide_maybe_wrong_mapping_notice', false ); | |
| 667 | - } | |
| 635 | + $dismiss = Utils\get_option( 'ep_hide_maybe_wrong_mapping_notice', false ); | |
| 668 | 636 | |
| 669 | 637 | // we need a host |
| 670 | 638 | $host = Utils\get_host(); |
| 671 | 639 | if ( empty( $host ) ) { |
| @@ -679,13 +647,9 @@ | ||
| 679 | 647 | return false; |
| 680 | 648 | } |
| 681 | 649 | |
| 682 | 650 | // we also likely need a sync to have a mapping |
| 683 | - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) { | |
| 684 | - $last_sync = get_site_option( 'ep_last_sync', false ); | |
| 685 | - } else { | |
| 686 | - $last_sync = get_option( 'ep_last_sync', false ); | |
| 687 | - } | |
| 651 | + $last_sync = Utils\get_option( 'ep_last_sync', false ); | |
| 688 | 652 | |
| 689 | 653 | if ( empty( $last_sync ) ) { |
| 690 | 654 | return false; |
| 691 | 655 | } |
| @@ -706,8 +670,9 @@ | ||
| 706 | 670 | '</em>' |
| 707 | 671 | ); |
| 708 | 672 | |
| 709 | 673 | if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
| 674 | + /* translators: 1. Current mapping file; 2. Mapping file that should be used */ | |
| 710 | 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>'; |
| 711 | 676 | } |
| 712 | 677 | |
| 713 | 678 | return [ |
| @@ -716,9 +681,8 @@ | ||
| 716 | 681 | 'dismiss' => true, |
| 717 | 682 | ]; |
| 718 | 683 | |
| 719 | 684 | } |
| 720 | - | |
| 721 | 685 | } |
| 722 | 686 | |
| 723 | 687 | /** |
| 724 | 688 | * Single node notification. Shows when index health is yellow. |
| @@ -736,23 +700,15 @@ | ||
| 736 | 700 | if ( empty( $host ) ) { |
| 737 | 701 | return false; |
| 738 | 702 | } |
| 739 | 703 | |
| 740 | - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) { | |
| 741 | - $last_sync = get_site_option( 'ep_last_sync', false ); | |
| 742 | - } else { | |
| 743 | - $last_sync = get_option( 'ep_last_sync', false ); | |
| 744 | - } | |
| 704 | + $last_sync = Utils\get_option( 'ep_last_sync', false ); | |
| 745 | 705 | |
| 746 | 706 | if ( empty( $last_sync ) ) { |
| 747 | 707 | return false; |
| 748 | 708 | } |
| 749 | 709 | |
| 750 | - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) { | |
| 751 | - $dismiss = get_site_option( 'ep_hide_yellow_health_notice', false ); | |
| 752 | - } else { | |
| 753 | - $dismiss = get_option( 'ep_hide_yellow_health_notice', false ); | |
| 754 | - } | |
| 710 | + $dismiss = Utils\get_option( 'ep_hide_yellow_health_notice', false ); | |
| 755 | 711 | |
| 756 | 712 | $screen = Screen::factory()->get_current_screen(); |
| 757 | 713 | |
| 758 | 714 | if ( ! in_array( $screen, [ 'dashboard', 'settings' ], true ) || $dismiss ) { |
| @@ -768,16 +724,101 @@ | ||
| 768 | 724 | $url = admin_url( 'admin.php?page=elasticpress-health' ); |
| 769 | 725 | } |
| 770 | 726 | |
| 771 | 727 | return [ |
| 772 | - '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 ), | |
| 773 | 728 | 'type' => 'warning', |
| 774 | 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 | + ), | |
| 775 | 735 | ]; |
| 776 | 736 | } |
| 777 | 737 | } |
| 778 | 738 | |
| 779 | 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 | + /** | |
| 780 | 821 | * Get notices that should be displayed |
| 781 | 822 | * |
| 782 | 823 | * @since 3.0 |
| 783 | 824 | * @return array |
| @@ -789,9 +830,35 @@ | ||
| 789 | 830 | * @hook ep_admin_notices |
| 790 | 831 | * @param {array} $notices Admin notices |
| 791 | 832 | * @return {array} New notices |
| 792 | 833 | */ |
| 793 | - 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; | |
| 794 | 861 | } |
| 795 | 862 | |
| 796 | 863 | /** |
| 797 | 864 | * Dismiss a notice given a notice key. |
| @@ -804,13 +871,10 @@ | ||
| 804 | 871 | // allow version dependent dismissal |
| 805 | 872 | if ( in_array( $notice, [ 'maybe_wrong_mapping' ], true ) ) { |
| 806 | 873 | $value = Elasticsearch::factory()->get_elasticsearch_version( false ); |
| 807 | 874 | } |
| 808 | - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) { | |
| 809 | - update_site_option( 'ep_hide_' . $notice . '_notice', $value ); | |
| 810 | - } else { | |
| 811 | - update_option( 'ep_hide_' . $notice . '_notice', $value ); | |
| 812 | - } | |
| 875 | + | |
| 876 | + Utils\update_option( 'ep_hide_' . $notice . '_notice', $value ); | |
| 813 | 877 | } |
| 814 | 878 | |
| 815 | 879 | /** |
| 816 | 880 | * Return singleton instance of class |
| @@ -825,6 +889,37 @@ | ||
| 825 | 889 | $instance = new self(); |
| 826 | 890 | } |
| 827 | 891 | |
| 828 | 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 | + ]; | |
| 829 | 924 | } |
| 830 | 925 | } |