| @@ -43,8 +43,32 @@ | ||
| 43 | 43 | */ |
| 44 | 44 | public $health_info_screen; |
| 45 | 45 | |
| 46 | 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 | + /** | |
| 47 | 71 | * Initialize class |
| 48 | 72 | * |
| 49 | 73 | * @since 3.0 |
| 50 | 74 | */ |
| @@ -52,10 +76,17 @@ | ||
| 52 | 76 | add_action( 'admin_init', [ $this, 'determine_screen' ] ); |
| 53 | 77 | |
| 54 | 78 | $this->sync_screen = new Screen\Sync(); |
| 55 | 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 | + | |
| 56 | 84 | $this->sync_screen->setup(); |
| 57 | 85 | $this->health_info_screen->setup(); |
| 86 | + $this->status_report->setup(); | |
| 87 | + $this->features->setup(); | |
| 88 | + $this->settings->setup(); | |
| 58 | 89 | } |
| 59 | 90 | |
| 60 | 91 | /** |
| 61 | 92 | * Determine current ElasticPress screen. null means not EP screen. |
| @@ -62,52 +93,52 @@ | ||
| 62 | 93 | * |
| 63 | 94 | * @since 3.0 |
| 64 | 95 | */ |
| 65 | 96 | 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; | |
| 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'; | |
| 70 | 112 | } |
| 71 | - } else { | |
| 72 | - if ( is_network_admin() ) { | |
| 73 | - return false; | |
| 74 | - } | |
| 113 | + return; | |
| 75 | 114 | } |
| 76 | 115 | |
| 77 | - // phpcs:disable WordPress.Security.NonceVerification | |
| 78 | - if ( ! empty( $_GET['page'] ) && false !== strpos( $_GET['page'], 'elasticpress' ) ) { | |
| 79 | - $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 | + ]; | |
| 80 | 125 | |
| 81 | - $this->screen = 'install'; | |
| 126 | + if ( ! isset( $page_screen_map[ $page ] ) ) { | |
| 127 | + return; | |
| 128 | + } | |
| 82 | 129 | |
| 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 | - } | |
| 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; | |
| 108 | 140 | } |
| 109 | - // phpcs:enable WordPress.Security.NonceVerification | |
| 110 | 141 | } |
| 111 | 142 | |
| 112 | 143 | /** |
| 113 | 144 | * Output template for current screen |
| @@ -114,27 +145,22 @@ | ||
| 114 | 145 | * |
| 115 | 146 | * @since 3.0 |
| 116 | 147 | */ |
| 117 | 148 | public function output() { |
| 118 | - $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 | + ]; | |
| 119 | 157 | |
| 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; | |
| 158 | + if ( ! isset( $page_screen_map[ $this->screen ] ) ) { | |
| 159 | + return; | |
| 136 | 160 | } |
| 161 | + | |
| 162 | + require_once __DIR__ . '/../partials/' . $page_screen_map[ $this->screen ] . '-page.php'; | |
| 137 | 163 | } |
| 138 | 164 | |
| 139 | 165 | /** |
| 140 | 166 | * Get current screen |