PluginProbe
ElasticPress / 5.0.0
ElasticPress v5.0.0
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 / Screen.php

Screen.php in ElasticPress 5.0.0, at includes/classes/Screen.php

207 lines 4.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Determine which ElasticPress screen we are viewing
4 *
5 * @since 3.0
6 * @package elasticpress
7 */
8
9 namespace ElasticPress;
10
11 use ElasticPress\Utils;
12 use ElasticPress\Installer;
13
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit; // Exit if accessed directly.
16 }
17
18 /**
19 * Screen class
20 */
21 class Screen {
22 /**
23 * Current screen
24 *
25 * @var string
26 * @since 3.0
27 */
28 protected $screen = null;
29
30 /**
31 * Sync screen instance
32 *
33 * @var Screen\Sync
34 * @since 3.6.0
35 */
36 public $sync_screen;
37
38 /**
39 * Info screen instance
40 *
41 * @var Screen\HealthInfo
42 * @since 4.3.0
43 */
44 public $health_info_screen;
45
46 /**
47 * Status report instance
48 *
49 * @var Screen\StatusReport
50 * @since 4.5.0
51 */
52 public $status_report;
53
54 /**
55 * Features instance
56 *
57 * @var Screen\Features
58 * @since 5.0.0
59 */
60 public $features;
61
62 /**
63 * Settings instance
64 *
65 * @var Screen\Settings
66 * @since 5.0.0
67 */
68 public $settings;
69
70 /**
71 * Initialize class
72 *
73 * @since 3.0
74 */
75 public function setup() {
76 add_action( 'admin_init', [ $this, 'determine_screen' ] );
77
78 $this->sync_screen = new Screen\Sync();
79 $this->health_info_screen = new Screen\HealthInfo();
80 $this->status_report = new Screen\StatusReport();
81 $this->features = new Screen\Features();
82 $this->settings = new Screen\Settings();
83
84 $this->sync_screen->setup();
85 $this->health_info_screen->setup();
86 $this->status_report->setup();
87 $this->features->setup();
88 $this->settings->setup();
89 }
90
91 /**
92 * Determine current ElasticPress screen. null means not EP screen.
93 *
94 * @since 3.0
95 */
96 public function determine_screen() {
97 // phpcs:disable WordPress.Security.NonceVerification
98 if ( ! empty( $_GET['page'] ) && false !== strpos( sanitize_key( $_GET['page'] ), 'elasticpress' ) ) {
99 $install_status = Installer::factory()->get_install_status();
100
101 $this->screen = 'install';
102
103 if ( 'elasticpress' === $_GET['page'] ) {
104 if ( ! isset( $_GET['install_complete'] ) && ( true === $install_status || isset( $_GET['do_sync'] ) ) ) {
105 if ( Utils\is_top_level_admin_context() ) {
106 $this->screen = 'dashboard';
107 } else {
108 $this->screen = 'weighting';
109 }
110 }
111 } elseif ( 'elasticpress-settings' === $_GET['page'] ) {
112 if ( true === $install_status || 2 === $install_status || isset( $_GET['do_sync'] ) ) {
113 $this->screen = 'settings';
114 }
115 } elseif ( 'elasticpress-health' === $_GET['page'] ) {
116 if ( ! isset( $_GET['install_complete'] ) && ( true === $install_status || isset( $_GET['do_sync'] ) ) ) {
117 $this->screen = 'health';
118 }
119 } elseif ( 'elasticpress-weighting' === $_GET['page'] ) {
120 if ( ! isset( $_GET['install_complete'] ) && ( true === $install_status || isset( $_GET['do_sync'] ) ) ) {
121 $this->screen = 'weighting';
122 }
123 } elseif ( 'elasticpress-synonyms' === $_GET['page'] ) {
124 if ( ! isset( $_GET['install_complete'] ) && ( true === $install_status || isset( $_GET['do_sync'] ) ) ) {
125 $this->screen = 'synonyms';
126 }
127 } elseif ( 'elasticpress-sync' === $_GET['page'] ) {
128 if ( ! isset( $_GET['install_complete'] ) && ( true === $install_status || isset( $_GET['do_sync'] ) ) ) {
129 $this->screen = 'sync';
130 }
131 } elseif ( 'elasticpress-status-report' === $_GET['page'] ) {
132 if ( ! isset( $_GET['install_complete'] ) && ( true === $install_status || isset( $_GET['do_sync'] ) ) ) {
133 $this->screen = 'status-report';
134 }
135 }
136 }
137 // phpcs:enable WordPress.Security.NonceVerification
138 }
139
140 /**
141 * Output template for current screen
142 *
143 * @since 3.0
144 */
145 public function output() {
146 $install_status = Installer::factory()->get_install_status();
147
148 switch ( $this->screen ) {
149 case 'dashboard':
150 require_once __DIR__ . '/../partials/dashboard-page.php';
151 break;
152 case 'settings':
153 require_once __DIR__ . '/../partials/settings-page.php';
154 break;
155 case 'install':
156 require_once __DIR__ . '/../partials/install-page.php';
157 break;
158 case 'health':
159 require_once __DIR__ . '/../partials/stats-page.php';
160 break;
161 case 'sync':
162 require_once __DIR__ . '/../partials/sync-page.php';
163 break;
164 case 'status-report':
165 require_once __DIR__ . '/../partials/status-report-page.php';
166 break;
167 }
168 }
169
170 /**
171 * Get current screen
172 *
173 * @since 3.0
174 * @return string
175 */
176 public function get_current_screen() {
177 return $this->screen;
178 }
179
180 /**
181 * Set current screen
182 *
183 * @since 3.0
184 * @param string $screen Screen to set
185 */
186 public function set_current_screen( $screen ) {
187 $this->screen = $screen;
188 }
189
190 /**
191 * Return singleton instance of class
192 *
193 * @return self
194 * @since 3.0
195 */
196 public static function factory() {
197 static $instance = false;
198
199 if ( ! $instance ) {
200 $instance = new self();
201 $instance->setup();
202 }
203
204 return $instance;
205 }
206 }
207