PluginProbe
ElasticPress / 5.3.5
ElasticPress v5.3.5
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
← All changes | includes/classes/Screen.php +92 -56 4.2.05.3.5 View file →
@@ -35,8 +35,40 @@
35 35 */
36 36 public $sync_screen;
37 37
38 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 + /**
39 71 * Initialize class
40 72 *
41 73 * @since 3.0
42 74 */
@@ -42,10 +74,19 @@
42 74 */
43 75 public function setup() {
44 76 add_action( 'admin_init', [ $this, 'determine_screen' ] );
45 77
46 - $this->sync_screen = new Screen\Sync();
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 +
47 84 $this->sync_screen->setup();
85 + $this->health_info_screen->setup();
86 + $this->status_report->setup();
87 + $this->features->setup();
88 + $this->settings->setup();
48 89 }
49 90
50 91 /**
51 92 * Determine current ElasticPress screen. null means not EP screen.
@@ -52,52 +93,52 @@
52 93 *
53 94 * @since 3.0
54 95 */
55 96 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;
97 + $page = ! empty( $_GET['page'] ) ? sanitize_key( $_GET['page'] ) : false; // phpcs:ignore WordPress.Security.NonceVerification
98 + if ( ! $page || false === strpos( $page, 'elasticpress' ) ) {
99 + return;
100 + }
101 +
102 + $install_status = Installer::factory()->get_install_status();
103 + $install_complete = ! empty( $_GET['install_complete'] ) ? sanitize_key( $_GET['install_complete'] ) : false; // phpcs:ignore WordPress.Security.NonceVerification
104 +
105 + $this->screen = 'install';
106 +
107 + // Handle main dashboard page with special logic
108 + if ( 'elasticpress' === $page ) {
109 + $can_access = ! $install_complete && ( true === $install_status || Utils\isset_do_sync_parameter() );
110 + if ( $can_access ) {
111 + $this->screen = Utils\is_top_level_admin_context() ? 'dashboard' : 'weighting';
60 112 }
61 - } else {
62 - if ( is_network_admin() ) {
63 - return false;
64 - }
113 + return;
65 114 }
66 115
67 - // phpcs:disable WordPress.Security.NonceVerification
68 - if ( ! empty( $_GET['page'] ) && false !== strpos( $_GET['page'], 'elasticpress' ) ) {
69 - $install_status = Installer::factory()->get_install_status();
116 + // Map page slugs to screen names with their access conditions
117 + $page_screen_map = [
118 + 'elasticpress-settings' => 'settings',
119 + 'elasticpress-health' => 'health',
120 + 'elasticpress-weighting' => 'weighting',
121 + 'elasticpress-synonyms' => 'synonyms',
122 + 'elasticpress-sync' => 'sync',
123 + 'elasticpress-status-report' => 'status-report',
124 + ];
70 125
71 - $this->screen = 'install';
126 + if ( ! isset( $page_screen_map[ $page ] ) ) {
127 + return;
128 + }
72 129
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 - }
130 + $screen_name = $page_screen_map[ $page ];
131 + $is_settings = 'settings' === $screen_name;
132 +
133 + // Settings screen allows install status 2, others require completed install or sync parameter
134 + $can_access = $is_settings
135 + ? ( true === $install_status || 2 === $install_status || Utils\isset_do_sync_parameter() )
136 + : ( ! $install_complete && ( true === $install_status || Utils\isset_do_sync_parameter() ) );
137 +
138 + if ( $can_access ) {
139 + $this->screen = $screen_name;
98 140 }
99 - // phpcs:enable WordPress.Security.NonceVerification
100 141 }
101 142
102 143 /**
103 144 * Output template for current screen
@@ -104,27 +145,22 @@
104 145 *
105 146 * @since 3.0
106 147 */
107 148 public function output() {
108 - $install_status = Installer::factory()->get_install_status();
149 + $page_screen_map = [
150 + 'dashboard' => 'dashboard',
151 + 'settings' => 'settings',
152 + 'install' => 'install',
153 + 'health' => 'stats',
154 + 'sync' => 'sync',
155 + 'status-report' => 'status-report',
156 + ];
109 157
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;
158 + if ( ! isset( $page_screen_map[ $this->screen ] ) ) {
159 + return;
126 160 }
161 +
162 + require_once __DIR__ . '/../partials/' . $page_screen_map[ $this->screen ] . '-page.php';
127 163 }
128 164
129 165 /**
130 166 * Get current screen