Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion inc/admin-pages/class-settings-admin-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,23 @@ public function default_handler(): void {

WP_Ultimo()->settings->save_settings($filtered_data);

wp_safe_redirect(add_query_arg('updated', 1, wu_get_current_url()));
$redirect_url = add_query_arg('updated', 1, wu_get_current_url());

/**
* Filters the redirect URL after settings are saved.
*
* Allows gateways or other components to redirect elsewhere
* after a settings save (e.g. to initiate an OAuth flow).
*
* @since 2.x.x
*
* @param string $redirect_url The default redirect URL.
* @param array $filtered_data The saved settings data.
* @return string
*/
$redirect_url = apply_filters('wu_settings_save_redirect', $redirect_url, $filtered_data);

wp_safe_redirect($redirect_url);

exit;
}
Expand Down
33 changes: 29 additions & 4 deletions inc/gateways/class-stripe-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public function hooks(): void {
// Handle OAuth callbacks and disconnects
add_action('admin_init', [$this, 'handle_oauth_callbacks']);

// Redirect to OAuth init after settings save when connect button was clicked
add_filter('wu_settings_save_redirect', [$this, 'maybe_redirect_to_stripe_oauth'], 10, 2);

add_filter(
'wu_customer_payment_methods',
function ($fields, $customer): array {
Expand All @@ -63,6 +66,29 @@ function ($fields, $customer): array {
);
}

/**
* Redirect to Stripe OAuth init URL after settings are saved.
*
* When the user clicks the "Connect with Stripe" button, the settings form
* is submitted first (saving sandbox mode, active gateways, etc.), then
* this filter redirects to the OAuth init URL instead of the normal
* settings page.
*
* @since 2.x.x
*
* @param string $redirect_url The default redirect URL.
* @param array $saved_data The saved settings data.
* @return string
*/
public function maybe_redirect_to_stripe_oauth(string $redirect_url, array $saved_data): string {

if (empty($_POST['wu_connect_stripe'])) { // phpcs:ignore WordPress.Security.NonceVerification
return $redirect_url;
}

return $this->get_oauth_init_url();
}

/**
* Adds the Stripe Gateway settings to the settings screen.
*
Expand Down Expand Up @@ -891,18 +917,17 @@ public function render_oauth_connection(): void {
);
}

// Disconnected state - show connect button
// Disconnected state - show connect button (submits form to save settings first)
printf(
'<div class="wu-oauth-status wu-disconnected wu-p-4 wu-bg-blue-50 wu-border wu-border-blue-200 wu-rounded">
<p class="wu-text-sm wu-text-gray-700 wu-mb-3">%s</p>
<a href="%s" class="button button-primary">
<button type="submit" name="wu_connect_stripe" value="1" class="button button-primary">
<span class="dashicons dashicons-admin-links wu-mr-1 wu-mt-1"></span>
%s
</a>
</button>
<p class="wu-text-xs wu-text-gray-500 wu-mt-2">%s</p>
</div>',
esc_html__('Connect your Stripe account with one click.', 'ultimate-multisite'),
esc_url($this->get_oauth_init_url()),
esc_html__('Connect with Stripe', 'ultimate-multisite'),
esc_html__('You will be redirected to Stripe to securely authorize the connection.', 'ultimate-multisite'),
);
Expand Down
Loading