PluginProbe
ElasticPress / 4.3.1
ElasticPress v4.3.1
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 / Installer.php

Installer.php in ElasticPress 4.3.1, at includes/classes/Installer.php

159 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * ElasticPress installer handler
4 *
5 * @since 3.0
6 * @package elasticpress
7 */
8
9 namespace ElasticPress;
10
11 use ElasticPress\Utils;
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit; // Exit if accessed directly.
15 }
16
17 /**
18 * Installer class
19 */
20 class Installer {
21 /**
22 * Current install status
23 *
24 * @var int|bool
25 * @since 3.0
26 */
27 protected $install_status;
28
29 /**
30 * Initialize class
31 *
32 * @since 3.0
33 */
34 public function setup() {
35 add_action( 'admin_init', [ $this, 'calculate_install_status' ], 9 );
36 add_filter( 'admin_title', [ $this, 'filter_admin_title' ], 10, 2 );
37 }
38
39 /**
40 * Filter admin title for install page
41 *
42 * @param string $admin_title Current title
43 * @param string $title Original title
44 * @since 3.0
45 * @return string
46 */
47 public function filter_admin_title( $admin_title, $title ) {
48 if ( 'install' === Screen::factory()->get_current_screen() ) {
49 // translators: Site Name
50 return sprintf( esc_html__( 'ElasticPress Setup &lsaquo; %s &#8212; WordPress', 'elasticpress' ), esc_html( get_bloginfo( 'name' ) ) );
51 }
52
53 return $admin_title;
54 }
55
56 /**
57 * Determine current install status
58 *
59 * @since 3.0
60 */
61 public function calculate_install_status() {
62 if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
63 $skip_install = get_site_option( 'ep_skip_install', false );
64 } else {
65 $skip_install = get_option( 'ep_skip_install', false );
66 }
67
68 if ( $skip_install ) {
69 $this->install_status = true;
70
71 return;
72 }
73
74 $last_sync = ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) ? get_site_option( 'ep_last_sync', false ) : get_option( 'ep_last_sync', false );
75 if ( ! empty( $last_sync ) ) {
76 $this->install_status = true;
77
78 return;
79 }
80
81 $host = Utils\get_host();
82
83 if ( empty( $host ) && empty( $_POST['ep_host'] ) ) { // phpcs:ignore
84 $this->install_status = 2;
85
86 return;
87 }
88
89 $this->install_status = 3;
90
91 $this->maybe_set_features();
92 }
93
94 /**
95 * Get installation status
96 *
97 * false - not installed
98 * 2 - On step two of install
99 * 3 - On step three of install
100 * true - Install complete
101 *
102 * @return bool|int
103 */
104 public function get_install_status() {
105 /**
106 * Filter install status
107 *
108 * @hook ep_install_status
109 * @param {string} $install_status Current install status
110 * @return {string} New install status
111 * @since 3.0
112 */
113 return apply_filters( 'ep_install_status', $this->install_status );
114 }
115
116 /**
117 * Check if it should use the features selected during the install to update the settings.
118 */
119 public function maybe_set_features() {
120 if ( empty( $_POST['ep_install_page_nonce'] ) || ! wp_verify_nonce( $_POST['ep_install_page_nonce'], 'ep_install_page' ) ) {
121 return;
122 }
123
124 if ( ! isset( $_POST['features'] ) || ! is_array( $_POST['features'] ) ) {
125 return;
126 }
127
128 $registered_features = \ElasticPress\Features::factory()->registered_features;
129 $activation_features = wp_list_filter( $registered_features, array( 'available_during_installation' => true ) );
130
131 foreach ( $activation_features as $slug => $feature ) {
132 if ( in_array( $slug, $_POST['features'], true ) ) {
133 \ElasticPress\Features::factory()->activate_feature( $slug );
134 } else {
135 \ElasticPress\Features::factory()->deactivate_feature( $slug );
136 }
137 }
138
139 $this->install_status = 4;
140 }
141
142 /**
143 * Return singleton instance of class
144 *
145 * @return self
146 * @since 3.0
147 */
148 public static function factory() {
149 static $instance = false;
150
151 if ( ! $instance ) {
152 $instance = new self();
153 $instance->setup();
154 }
155
156 return $instance;
157 }
158 }
159