| @@ -45,8 +45,12 @@ | ||
| 45 | 45 | /** |
| 46 | 46 | * Maybe member is trying to connect via Hub Connection Module. |
| 47 | 47 | */ |
| 48 | 48 | public function maybe_hcm_connection_attempt() { |
| 49 | + if ( ! current_user_can( 'manage_options' ) ) { | |
| 50 | + return; | |
| 51 | + } | |
| 52 | + | |
| 49 | 53 | $module_slug = defender_get_data_from_request( 'module_slug', 'g' ); |
| 50 | 54 | $is_callback = defender_get_data_from_request( 'hub_connector_callback', 'g' ); |
| 51 | 55 | |
| 52 | 56 | if ( is_string( $module_slug ) && '' !== $module_slug && is_string( $is_callback ) && '' !== $is_callback ) { |
| @@ -160,30 +164,35 @@ | ||
| 160 | 164 | * |
| 161 | 165 | * @return array An array of data for the frontend. |
| 162 | 166 | */ |
| 163 | 167 | public function data_frontend(): array { |
| 168 | + // Current admin page slug, used to build callbacks that return to the originating page. | |
| 169 | + $current_page = sanitize_text_field( wp_unslash( $_GET['page'] ?? 'wp-defender' ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 170 | + $is_hub_connector_logged_in = Hub_Connector_Component::is_logged_in(); | |
| 171 | + | |
| 164 | 172 | return array_merge( |
| 165 | 173 | array( |
| 166 | - 'button_label' => $this->service->get_button_label(), | |
| 167 | - 'is_dash_installed' => $this->is_dash_installed(), | |
| 168 | - 'is_dash_activated' => $this->is_dash_activated(), | |
| 169 | - 'dash_url' => add_query_arg( 'page', 'wpmudev', is_multisite() ? network_admin_url( 'admin.php' ) : admin_url( 'admin.php' ) ), | |
| 170 | - 'is_hub_connected' => $this->is_site_connected_to_hub_via_hcm_or_dash(), | |
| 171 | - 'is_logged_in' => Hub_Connector_Component::is_logged_in() || Hub_Connector_Component::is_wpmudev_dashboard_connected(), | |
| 172 | - 'is_dashboard_connected' => Hub_Connector_Component::is_wpmudev_dashboard_connected(), | |
| 173 | - 'has_login_error' => Hub_Connector_Component::has_error_in_login(), | |
| 174 | - 'login_error_msg' => Hub_Connector_Component::get_auth_error(), | |
| 175 | - 'hub_auth_url' => Hub_Connector_Component::get_hub_google_login_url(), | |
| 176 | - 'redirect_url' => Hub_Connector_Component::get_hub_connector_callback_url(), | |
| 177 | - 'domain' => Hub_Connector_Component::get_site_domain(), | |
| 178 | - 'auth_nonce' => wp_create_nonce( 'auth_nonce' ), | |
| 179 | - 'login_auth_url' => Hub_Connector_Component::get_hub_site_login_auth_url(), | |
| 180 | - 'hub_signup_url' => Hub_Connector_Component::get_hub_register_url(), | |
| 181 | - 'forgot_password_url' => Hub_Connector_Component::get_hub_forgot_password_url(), | |
| 182 | - 'is_syncing' => Hub_Connector_Component::is_syncing(), | |
| 183 | - 'logout_url' => rest_url( 'hub-connector/v1/logout' ), | |
| 184 | - 'logout_nonce' => wp_create_nonce( 'wp_rest' ), | |
| 185 | - 'hub_connector_url' => array( | |
| 174 | + 'button_label' => $this->service->get_button_label(), | |
| 175 | + 'is_dash_installed' => $this->is_dash_installed(), | |
| 176 | + 'is_dash_activated' => $this->is_dash_activated(), | |
| 177 | + 'dash_url' => add_query_arg( 'page', 'wpmudev', is_multisite() ? network_admin_url( 'admin.php' ) : admin_url( 'admin.php' ) ), | |
| 178 | + 'is_hub_connected' => $this->is_site_connected_to_hub_via_hcm_or_dash(), | |
| 179 | + 'is_logged_in' => $is_hub_connector_logged_in || Hub_Connector_Component::is_wpmudev_dashboard_connected(), | |
| 180 | + 'is_hub_connector_logged_in' => $is_hub_connector_logged_in, | |
| 181 | + 'is_dashboard_connected' => Hub_Connector_Component::is_wpmudev_dashboard_connected(), | |
| 182 | + 'has_login_error' => Hub_Connector_Component::has_error_in_login(), | |
| 183 | + 'login_error_msg' => Hub_Connector_Component::get_auth_error(), | |
| 184 | + 'hub_auth_url' => Hub_Connector_Component::get_hub_google_login_url(), | |
| 185 | + 'redirect_url' => Hub_Connector_Component::get_hub_connector_callback_url( $current_page ), | |
| 186 | + 'domain' => Hub_Connector_Component::get_site_domain(), | |
| 187 | + 'auth_nonce' => wp_create_nonce( 'auth_nonce' ), | |
| 188 | + 'login_auth_url' => Hub_Connector_Component::get_hub_site_login_auth_url(), | |
| 189 | + 'hub_signup_url' => Hub_Connector_Component::get_hub_register_url( $current_page ), | |
| 190 | + 'forgot_password_url' => Hub_Connector_Component::get_hub_forgot_password_url(), | |
| 191 | + 'is_syncing' => Hub_Connector_Component::is_syncing(), | |
| 192 | + 'logout_url' => rest_url( 'hub-connector/v1/logout' ), | |
| 193 | + 'logout_nonce' => wp_create_nonce( 'wp_rest' ), | |
| 194 | + 'hub_connector_url' => array( | |
| 186 | 195 | 'default' => $this->service->get_url(), |
| 187 | 196 | 'global-ip' => $this->service->get_url( 'wdf-ip-lockout', 'global-ip' ), |
| 188 | 197 | 'blocklist' => $this->service->get_url( 'wdf-ip-lockout', 'blocklist' ), |
| 189 | 198 | 'onboard' => $this->service->get_url( 'wp-defender', 'onboard' ), |
| @@ -202,14 +211,14 @@ | ||
| 202 | 211 | // Custom one if a trigger is the Summary section. |
| 203 | 212 | 'summary-box' => $this->service->get_url( 'wdf-ip-lockout', 'summary-box' ), |
| 204 | 213 | // Custom one for Antibot notice shown on all Defender pages. |
| 205 | 214 | 'antibot-notice' => $this->service->get_url( 'wdf-ip-lockout', '', 'def_antibot_survey_notice', 'hub_connector' ), |
| 206 | - // Signup URLs with post_sync_redirect embedded — Hub always calls back to Dashboard. | |
| 207 | - 'settings-redirect-signup' => Hub_Connector_Component::get_hub_register_url( 'wp-defender', $this->service->get_url( 'wdf-setting', 'tools' ) ), | |
| 208 | - 'settings-blocklist-signup' => Hub_Connector_Component::get_hub_register_url( 'wp-defender', $this->service->get_url( 'wdf-setting', 'tools', '', '', 'blocklist-monitor' ) ), | |
| 209 | - 'scan-signup' => Hub_Connector_Component::get_hub_register_url( 'wp-defender', $this->service->get_url( 'wdf-scan' ) ), | |
| 210 | - 'global-firewall-signup' => Hub_Connector_Component::get_hub_register_url( 'wp-defender', $this->service->get_url( 'wdf-ip-lockout', 'global-ip', '', '', Antibot_Global_Firewall_Setting::MODULE_SLUG ) ), | |
| 211 | - 'custom-rules-signup' => Hub_Connector_Component::get_hub_register_url( 'wp-defender', $this->service->get_url( 'wdf-ip-lockout', 'custom-rules', '', '', Global_Ip::MODULE_SLUG ) ), | |
| 215 | + // Signup URLs embed post_sync_redirect so the callback lands on the current page, then redirects to the target. | |
| 216 | + 'settings-redirect-signup' => Hub_Connector_Component::get_hub_register_url( $current_page, $this->service->get_url( 'wdf-setting', 'tools' ) ), | |
| 217 | + 'settings-blocklist-signup' => Hub_Connector_Component::get_hub_register_url( $current_page, $this->service->get_url( 'wdf-setting', 'tools', '', '', 'blocklist-monitor' ) ), | |
| 218 | + 'scan-signup' => Hub_Connector_Component::get_hub_register_url( $current_page, $this->service->get_url( 'wdf-scan' ) ), | |
| 219 | + 'global-firewall-signup' => Hub_Connector_Component::get_hub_register_url( $current_page, $this->service->get_url( 'wdf-ip-lockout', 'global-ip', '', '', Antibot_Global_Firewall_Setting::MODULE_SLUG ) ), | |
| 220 | + 'custom-rules-signup' => Hub_Connector_Component::get_hub_register_url( $current_page, $this->service->get_url( 'wdf-ip-lockout', 'custom-rules', '', '', Global_Ip::MODULE_SLUG ) ), | |
| 212 | 221 | ), |
| 213 | 222 | ), |
| 214 | 223 | $this->dump_routes_and_nonces() |
| 215 | 224 | ); |