Skip to content

Commit

Permalink
fix: re-add params on login
Browse files Browse the repository at this point in the history
  • Loading branch information
chickenn00dle committed Feb 28, 2025
1 parent 8663d70 commit ae1217f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
11 changes: 11 additions & 0 deletions includes/reader-activation/class-reader-activation.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Newspack\Recaptcha;
use Newspack\Reader_Activation\Sync;
use Newspack\Renewal;
use Newspack\WooCommerce_My_Account;

defined( 'ABSPATH' ) || exit;

Expand Down Expand Up @@ -1356,6 +1357,16 @@ public static function render_auth_form( $in_modal = true ) {
if ( Renewal::is_subscriptions_page() ) {
// If we are on the subscriptions page, set the auth callback URL to the subscriptions page.
$auth_callback_url = Renewal::get_subscriptions_url();
} elseif ( WooCommerce_My_Account::is_myaccount_url() ) {
$params = [];
// If we are using one of our my account params, reattach the param to the my account URL.
foreach ( WooCommerce_My_Account::ALLOWED_PARAMS as $param ) {
$value = $_GET[ $param ] ?? null; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Recommended
if ( $value ) {
$params[ $param ] = $value;
}
}
$auth_callback_url = add_query_arg( $params, \wc_get_page_permalink( 'myaccount' ) );
} elseif ( function_exists( 'wc_get_page_permalink' ) && function_exists( 'is_account_page' ) && \is_account_page() ) {
// If we are already on the my account page, set the my account URL so the page reloads on submit.
$auth_callback_url = \wc_get_page_permalink( 'myaccount' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ class WooCommerce_My_Account {
const CANCEL_EMAIL_CHANGE_PARAM = 'cancel-email-change';
const VERIFY_EMAIL_CHANGE_PARAM = 'verify-email-change';
const PENDING_EMAIL_CHANGE_META = 'newspack_pending_email_change';
const ALLOWED_PARAMS = [
self::RESET_PASSWORD_URL_PARAM,
self::DELETE_ACCOUNT_URL_PARAM,
self::SEND_MAGIC_LINK_PARAM,
self::AFTER_ACCOUNT_DELETION_PARAM,
self::CANCEL_EMAIL_CHANGE_PARAM,
self::VERIFY_EMAIL_CHANGE_PARAM,
];

/**
* Initialize.
Expand Down Expand Up @@ -420,7 +428,8 @@ function_exists( 'wc_get_page_permalink' ) &&
! $is_resubscribe_request &&
! $is_renewal_request &&
! $is_cancel_membership_request &&
! $is_checkout_request
! $is_checkout_request &&
! self::is_myaccount_url()
) {
global $wp;
$current_url = \home_url( $wp->request );
Expand Down Expand Up @@ -920,6 +929,17 @@ public static function handle_cancel_email_change() {
\wp_safe_redirect( \wc_get_endpoint_url( 'edit-account', '', \wc_get_page_permalink( 'myaccount' ) ) );
exit;
}

/**
* Check if url is newspack my account url.
*
* @return bool
*/
public static function is_myaccount_url() {
$cancel_secret = filter_input( INPUT_GET, self::CANCEL_EMAIL_CHANGE_PARAM, FILTER_SANITIZE_FULL_SPECIAL_CHARS );
$verify_secret = filter_input( INPUT_GET, self::VERIFY_EMAIL_CHANGE_PARAM, FILTER_SANITIZE_FULL_SPECIAL_CHARS );
return ! empty( $cancel_secret ) || ! empty( $verify_secret );
}
}

WooCommerce_My_Account::init();

0 comments on commit ae1217f

Please sign in to comment.