PluginProbe
ElasticPress / 4.4.0
ElasticPress v4.4.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 4.4.0, at includes/classes/Screen.php

186 lines 4.4 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 * Initialize class
48 *
49 * @since 3.0
50 */
51 public function setup() {
52 add_action( 'admin_init', [ $this, 'determine_screen' ] );
53
54 $this->sync_screen = new Screen\Sync();
55 $this->health_info_screen = new Screen\HealthInfo();
56 $this->status_report = new Screen\StatusReport();
57
58 $this->sync_screen->setup();
59 $this->health_info_screen->setup();
60 $this->status_report->setup();
61 }
62
63 /**
64 * Determine current ElasticPress screen. null means not EP screen.
65 *
66 * @since 3.0
67 */
68 public function determine_screen() {
69 // If in network mode, don't output notice in admin and vice-versa.
70 if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
71 if ( ! is_network_admin() ) {
72 return false;
73 }
74 } else {
75 if ( is_network_admin() ) {
76 return false;
77 }
78 }
79
80 // phpcs:disable WordPress.Security.NonceVerification
81 if ( ! empty( $_GET['page'] ) && false !== strpos( $_GET['page'], 'elasticpress' ) ) {
82 $install_status = Installer::factory()->get_install_status();
83
84 $this->screen = 'install';
85
86 if ( 'elasticpress' === $_GET['page'] ) {
87 if ( ! isset( $_GET['install_complete'] ) && ( true === $install_status || isset( $_GET['do_sync'] ) ) ) {
88 $this->screen = 'dashboard';
89 }
90 } elseif ( 'elasticpress-settings' === $_GET['page'] ) {
91 if ( true === $install_status || 2 === $install_status || isset( $_GET['do_sync'] ) ) {
92 $this->screen = 'settings';
93 }
94 } elseif ( 'elasticpress-health' === $_GET['page'] ) {
95 if ( ! isset( $_GET['install_complete'] ) && ( true === $install_status || isset( $_GET['do_sync'] ) ) ) {
96 $this->screen = 'health';
97 }
98 } elseif ( 'elasticpress-weighting' === $_GET['page'] ) {
99 if ( ! isset( $_GET['install_complete'] ) && ( true === $install_status || isset( $_GET['do_sync'] ) ) ) {
100 $this->screen = 'weighting';
101 }
102 } elseif ( 'elasticpress-synonyms' === $_GET['page'] ) {
103 if ( ! isset( $_GET['install_complete'] ) && ( true === $install_status || isset( $_GET['do_sync'] ) ) ) {
104 $this->screen = 'synonyms';
105 }
106 } elseif ( 'elasticpress-sync' === $_GET['page'] ) {
107 if ( ! isset( $_GET['install_complete'] ) && ( true === $install_status || isset( $_GET['do_sync'] ) ) ) {
108 $this->screen = 'sync';
109 }
110 } elseif ( 'elasticpress-status-report' === $_GET['page'] ) {
111 if ( ! isset( $_GET['install_complete'] ) && ( true === $install_status || isset( $_GET['do_sync'] ) ) ) {
112 $this->screen = 'status-report';
113 }
114 }
115 }
116 // phpcs:enable WordPress.Security.NonceVerification
117 }
118
119 /**
120 * Output template for current screen
121 *
122 * @since 3.0
123 */
124 public function output() {
125 $install_status = Installer::factory()->get_install_status();
126
127 switch ( $this->screen ) {
128 case 'dashboard':
129 require_once __DIR__ . '/../partials/dashboard-page.php';
130 break;
131 case 'settings':
132 require_once __DIR__ . '/../partials/settings-page.php';
133 break;
134 case 'install':
135 require_once __DIR__ . '/../partials/install-page.php';
136 break;
137 case 'health':
138 require_once __DIR__ . '/../partials/stats-page.php';
139 break;
140 case 'sync':
141 require_once __DIR__ . '/../partials/sync-page.php';
142 break;
143 case 'status-report':
144 require_once __DIR__ . '/../partials/status-report-page.php';
145 break;
146 }
147 }
148
149 /**
150 * Get current screen
151 *
152 * @since 3.0
153 * @return string
154 */
155 public function get_current_screen() {
156 return $this->screen;
157 }
158
159 /**
160 * Set current screen
161 *
162 * @since 3.0
163 * @param string $screen Screen to set
164 */
165 public function set_current_screen( $screen ) {
166 $this->screen = $screen;
167 }
168
169 /**
170 * Return singleton instance of class
171 *
172 * @return self
173 * @since 3.0
174 */
175 public static function factory() {
176 static $instance = false;
177
178 if ( ! $instance ) {
179 $instance = new self();
180 $instance->setup();
181 }
182
183 return $instance;
184 }
185 }
186