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 +52 -57 5.0.05.3.5 View file →
@@ -93,49 +93,52 @@
93 93 *
94 94 * @since 3.0
95 95 */
96 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();
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 + }
100 101
101 - $this->screen = 'install';
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
102 104
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 - }
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';
135 112 }
113 + return;
136 114 }
137 - // phpcs:enable WordPress.Security.NonceVerification
115 +
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 + ];
125 +
126 + if ( ! isset( $page_screen_map[ $page ] ) ) {
127 + return;
128 + }
129 +
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;
140 + }
138 141 }
139 142
140 143 /**
141 144 * Output template for current screen
@@ -142,30 +145,22 @@
142 145 *
143 146 * @since 3.0
144 147 */
145 148 public function output() {
146 - $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 + ];
147 157
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;
158 + if ( ! isset( $page_screen_map[ $this->screen ] ) ) {
159 + return;
167 160 }
161 +
162 + require_once __DIR__ . '/../partials/' . $page_screen_map[ $this->screen ] . '-page.php';
168 163 }
169 164
170 165 /**
171 166 * Get current screen