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
elasticpress / includes / classes / HealthCheck / HealthCheckElasticsearch.php

HealthCheckElasticsearch.php in ElasticPress 5.3.5, at includes/classes/HealthCheck/HealthCheckElasticsearch.php

86 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Elasticsearch health check
4 *
5 * @since 3.6.0
6 * @package elasticpress
7 */
8
9 namespace ElasticPress\HealthCheck;
10
11 use ElasticPress\Elasticsearch;
12 use ElasticPress\HealthCheck;
13 use ElasticPress\Utils;
14
15 if ( ! defined( 'ABSPATH' ) ) {
16 // @codeCoverageIgnoreStart
17 exit; // Exit if accessed directly.
18 // @codeCoverageIgnoreEnd
19 }
20
21 /**
22 * HealthCheckElasticsearch class
23 */
24 class HealthCheckElasticsearch extends HealthCheck {
25
26 /**
27 * Create Elasticsearch health check.
28 */
29 public function __construct() {
30 $this->test_name = 'elasticpress-health-check-elasticsearch';
31 $this->async = true;
32 }
33
34 /**
35 * Runs the test.
36 *
37 * @return array Data about the result of the test.
38 */
39 public function run() {
40 $result = [
41 'label' => esc_html__( 'Your site can connect to Elasticsearch.', 'elasticpress' ),
42 'status' => 'good',
43 'badge' => [
44 'label' => esc_html__( 'ElasticPress', 'elasticpress' ),
45 'color' => 'green',
46 ],
47 'description' => esc_html__( 'You can have a fast and flexible search and query engine for WordPress using ElasticPress.', 'elasticpress' ),
48 'actions' => '',
49 'test' => $this->test_name,
50 ];
51
52 $host = Utils\get_host();
53
54 $elasticpress_settings_url = defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ? admin_url( 'network/admin.php?page=elasticpress-settings' ) : admin_url( 'admin.php?page=elasticpress-settings' );
55
56 if ( empty( $host ) ) {
57 $result['label'] = esc_html__( 'Your site could not connect to Elasticsearch', 'elasticpress' );
58 $result['status'] = 'critical';
59 $result['badge']['color'] = 'red';
60 $result['description'] = esc_html__( 'The Elasticsearch host is not set.', 'elasticpress' );
61 $result['actions'] = sprintf(
62 '<p><a href="%s">%s</a></p>',
63 esc_url( $elasticpress_settings_url ),
64 esc_html__( 'Add a host', 'elasticpress' )
65 );
66 } elseif ( ! Elasticsearch::factory()->get_elasticsearch_version( true ) ) {
67 $result['label'] = esc_html__( 'Your site could not connect to Elasticsearch', 'elasticpress' );
68 $result['status'] = 'critical';
69 $result['badge']['color'] = 'red';
70 $result['actions'] = sprintf(
71 '<p><a href="%s">%s</a></p>',
72 esc_url( $elasticpress_settings_url ),
73 esc_html__( 'Update your settings', 'elasticpress' )
74 );
75
76 if ( Utils\is_epio() ) {
77 $result['description'] = esc_html__( 'Check if your credentials to ElasticPress.io host are correct.', 'elasticpress' );
78 } else {
79 $result['description'] = esc_html__( 'Check if your Elasticsearch host URL is correct and you have the right access to the host.', 'elasticpress' );
80 }
81 }
82
83 return $result;
84 }
85 }
86