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 +70 -62 4.7.25.3.5 View file →
@@ -51,8 +51,24 @@
51 51 */
52 52 public $status_report;
53 53
54 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 + /**
55 71 * Initialize class
56 72 *
57 73 * @since 3.0
58 74 */
@@ -61,12 +77,16 @@
61 77
62 78 $this->sync_screen = new Screen\Sync();
63 79 $this->health_info_screen = new Screen\HealthInfo();
64 80 $this->status_report = new Screen\StatusReport();
81 + $this->features = new Screen\Features();
82 + $this->settings = new Screen\Settings();
65 83
66 84 $this->sync_screen->setup();
67 85 $this->health_info_screen->setup();
68 86 $this->status_report->setup();
87 + $this->features->setup();
88 + $this->settings->setup();
69 89 }
70 90
71 91 /**
72 92 * Determine current ElasticPress screen. null means not EP screen.
@@ -73,56 +93,52 @@
73 93 *
74 94 * @since 3.0
75 95 */
76 96 public function determine_screen() {
77 - // If in network mode, don't output notice in admin and vice-versa.
78 - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
79 - if ( ! is_network_admin() ) {
80 - 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';
81 112 }
82 - } else {
83 - if ( is_network_admin() ) {
84 - return false;
85 - }
113 + return;
86 114 }
87 115
88 - // phpcs:disable WordPress.Security.NonceVerification
89 - if ( ! empty( $_GET['page'] ) && false !== strpos( sanitize_key( $_GET['page'] ), 'elasticpress' ) ) {
90 - $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 + ];
91 125
92 - $this->screen = 'install';
126 + if ( ! isset( $page_screen_map[ $page ] ) ) {
127 + return;
128 + }
93 129
94 - if ( 'elasticpress' === $_GET['page'] ) {
95 - if ( ! isset( $_GET['install_complete'] ) && ( true === $install_status || isset( $_GET['do_sync'] ) ) ) {
96 - $this->screen = 'dashboard';
97 - }
98 - } elseif ( 'elasticpress-settings' === $_GET['page'] ) {
99 - if ( true === $install_status || 2 === $install_status || isset( $_GET['do_sync'] ) ) {
100 - $this->screen = 'settings';
101 - }
102 - } elseif ( 'elasticpress-health' === $_GET['page'] ) {
103 - if ( ! isset( $_GET['install_complete'] ) && ( true === $install_status || isset( $_GET['do_sync'] ) ) ) {
104 - $this->screen = 'health';
105 - }
106 - } elseif ( 'elasticpress-weighting' === $_GET['page'] ) {
107 - if ( ! isset( $_GET['install_complete'] ) && ( true === $install_status || isset( $_GET['do_sync'] ) ) ) {
108 - $this->screen = 'weighting';
109 - }
110 - } elseif ( 'elasticpress-synonyms' === $_GET['page'] ) {
111 - if ( ! isset( $_GET['install_complete'] ) && ( true === $install_status || isset( $_GET['do_sync'] ) ) ) {
112 - $this->screen = 'synonyms';
113 - }
114 - } elseif ( 'elasticpress-sync' === $_GET['page'] ) {
115 - if ( ! isset( $_GET['install_complete'] ) && ( true === $install_status || isset( $_GET['do_sync'] ) ) ) {
116 - $this->screen = 'sync';
117 - }
118 - } elseif ( 'elasticpress-status-report' === $_GET['page'] ) {
119 - if ( ! isset( $_GET['install_complete'] ) && ( true === $install_status || isset( $_GET['do_sync'] ) ) ) {
120 - $this->screen = 'status-report';
121 - }
122 - }
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;
123 140 }
124 - // phpcs:enable WordPress.Security.NonceVerification
125 141 }
126 142
127 143 /**
128 144 * Output template for current screen
@@ -129,30 +145,22 @@
129 145 *
130 146 * @since 3.0
131 147 */
132 148 public function output() {
133 - $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 + ];
134 157
135 - switch ( $this->screen ) {
136 - case 'dashboard':
137 - require_once __DIR__ . '/../partials/dashboard-page.php';
138 - break;
139 - case 'settings':
140 - require_once __DIR__ . '/../partials/settings-page.php';
141 - break;
142 - case 'install':
143 - require_once __DIR__ . '/../partials/install-page.php';
144 - break;
145 - case 'health':
146 - require_once __DIR__ . '/../partials/stats-page.php';
147 - break;
148 - case 'sync':
149 - require_once __DIR__ . '/../partials/sync-page.php';
150 - break;
151 - case 'status-report':
152 - require_once __DIR__ . '/../partials/status-report-page.php';
153 - break;
158 + if ( ! isset( $page_screen_map[ $this->screen ] ) ) {
159 + return;
154 160 }
161 +
162 + require_once __DIR__ . '/../partials/' . $page_screen_map[ $this->screen ] . '-page.php';
155 163 }
156 164
157 165 /**
158 166 * Get current screen