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 / Screen.php

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

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