Skip to content

Commit

Permalink
feat(ras): login reader after successful password reset (#3510)
Browse files Browse the repository at this point in the history
This PR logs in a reader after they have successfully reset their password when RAS is enabled.
  • Loading branch information
chickenn00dle authored Oct 30, 2024
1 parent 513d8c7 commit 6a78988
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions includes/reader-activation/class-reader-activation.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public static function init() {
\add_action( 'wp_footer', [ __CLASS__, 'render_auth_modal' ] );
\add_action( 'wp_footer', [ __CLASS__, 'render_newsletters_signup_modal' ] );
\add_action( 'wp_ajax_newspack_reader_activation_newsletters_signup', [ __CLASS__, 'newsletters_signup' ] );
\add_action( 'woocommerce_customer_reset_password', [ __CLASS__, 'login_after_password_reset' ] );

if ( self::is_enabled() ) {
\add_action( 'clear_auth_cookie', [ __CLASS__, 'clear_auth_intention_cookie' ] );
Expand Down Expand Up @@ -1923,8 +1924,6 @@ public static function set_current_reader( $user_or_user_id ) {
return new \WP_Error( 'newspack_authenticate_invalid_user', __( 'Invalid user.', 'newspack-plugin' ) );
}

$user_id = \absint( $user->ID );

\wp_clear_auth_cookie();
\wp_set_current_user( $user->ID );
\wp_set_auth_cookie( $user->ID, true );
Expand Down Expand Up @@ -2359,5 +2358,17 @@ private static function get_logged_in_reader_email_address() {

return $email_address;
}

/**
* Login a reader after they have successfully reset their password.
*
* @param WP_User $user WP_User object.
*/
public static function login_after_password_reset( $user ) {
if ( ! self::is_enabled() ) {
return;
}
set_current_reader( $user );
}
}
Reader_Activation::init();

0 comments on commit 6a78988

Please sign in to comment.