self::PAGE_SLUG, 'tab' => $current_tab, 'settings-updated' => 'true', ); if ( self::TAB_SETTINGS === $current_tab && ! empty( $_POST['forwp_account_settings_sub'] ) ) { $redirect_args['section'] = sanitize_key( wp_unslash( $_POST['forwp_account_settings_sub'] ) ); } if ( self::TAB_AUTH === $current_tab && ! empty( $_POST['forwp_account_open_provider'] ) ) { $redirect_args['provider'] = sanitize_key( wp_unslash( (string) $_POST['forwp_account_open_provider'] ) ); } wp_safe_redirect( add_query_arg( $redirect_args, admin_url( 'admin.php' ) ) ); exit; } /** * @return array */ public static function get_tabs(): array { return array( self::TAB_AUTH => __( 'Auth / Register', '4wp-account' ), self::TAB_APPEARANCE => __( 'Appearance', '4wp-account' ), self::TAB_SETTINGS => __( 'Settings', '4wp-account' ), ); } /** * @param string $tab Raw tab slug. */ public static function sanitize_tab( string $tab ): string { $tabs = self::get_tabs(); return array_key_exists( $tab, $tabs ) ? $tab : self::TAB_AUTH; } /** * Active admin tab from the query string (read-only navigation). */ private static function get_request_tab(): string { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only tab switch; no state change. $tab = isset( $_GET['tab'] ) ? sanitize_key( wp_unslash( (string) $_GET['tab'] ) ) : self::TAB_AUTH; return self::sanitize_tab( $tab ); } /** * Tab to save: posted hidden field first, then the query string. */ private static function get_save_tab(): string { if ( isset( $_POST['forwp_account_current_tab'] ) ) { return self::sanitize_tab( sanitize_key( wp_unslash( (string) $_POST['forwp_account_current_tab'] ) ) ); } return self::get_request_tab(); } /** * Active Settings sub-section from the query string. */ private static function get_request_section( string $default ): string { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only section switch. return isset( $_GET['section'] ) ? sanitize_key( wp_unslash( (string) $_GET['section'] ) ) : $default; } /** * Whether the PRG flash flag is present after a successful save. */ private static function is_settings_updated_flash(): bool { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Redirect flash after PRG save. return isset( $_GET['settings-updated'] ) && 'true' === sanitize_text_field( wp_unslash( (string) $_GET['settings-updated'] ) ); } /** * Render admin page. */ public static function render(): void { if ( ! current_user_can( 'manage_options' ) ) { return; } $current_tab = self::get_request_tab(); if ( self::is_settings_updated_flash() ) { echo '

' . esc_html__( 'Settings saved.', '4wp-account' ) . '

'; } $tabs = self::get_tabs(); $heading_svg = ''; $svg_allowed = array( 'svg' => array( 'xmlns' => true, 'viewbox' => true, 'width' => true, 'height' => true, 'fill' => true, 'focusable' => true, 'aria-hidden' => true, ), 'path' => array( 'd' => true, 'fill' => true, ), ); ?>

$post POST data. */ private static function save_settings( string $tab, array $post ): void { if ( self::TAB_SETTINGS === $tab ) { SettingsTab::save( $post ); return; } if ( self::TAB_APPEARANCE === $tab ) { AppearanceTab::save( $post ); return; } AuthTab::save( $post ); } }