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

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