Skip to content

Commit

Permalink
fix: verify reader on google authentication (#1873)
Browse files Browse the repository at this point in the history
* fix: verify reader on google authentication

* fix: namespace
  • Loading branch information
miguelpeixe authored Aug 9, 2022
1 parent 67cbcfd commit c9c4eef
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions includes/class-reader-activation.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,12 +315,18 @@ public static function is_user_reader( $user ) {
/**
* Verify email address of a reader given the user.
*
* @param \WP_User $user User object.
* @param \WP_User|int $user_or_user_id User object.
*
* @return bool Whether the email address was verified.
*/
public static function set_reader_verified( $user ) {
if ( ! $user ) {
public static function set_reader_verified( $user_or_user_id ) {
if ( $user_or_user_id instanceof \WP_User ) {
$user = $user_or_user_id;
} elseif ( absint( $user_or_user_id ) ) {
$user = get_user_by( 'id', $user_or_user_id );
}

if ( ! isset( $user ) || ! $user ) {
return false;
}

Expand All @@ -329,13 +335,15 @@ public static function set_reader_verified( $user ) {
return false;
}

$verified = \get_user_meta( $user->ID, self::EMAIL_VERIFIED, true );
if ( $verified ) {
return true;
}

\update_user_meta( $user->ID, self::EMAIL_VERIFIED, true );

/**
* Fires after a reader's email address is verified.
*
* @param \WP_User $user User object.
*/
do_action( 'newspack_reader_verified', $user );

return true;
}

Expand Down Expand Up @@ -1063,9 +1071,15 @@ public static function register_reader( $email, $display_name = '', $authenticat
}
}

/** Registration methods that don't require account verification. */
$verified_registration_methods = [ 'google' ];

// Note the user's login method for later use.
if ( isset( $metadata['registration_method'] ) ) {
\update_user_meta( $user_id, self::REGISTRATION_METHOD, $metadata['registration_method'] );
if ( in_array( $metadata['registration_method'], $verified_registration_methods, true ) ) {
self::set_reader_verified( $user_id );
}
}

/**
Expand Down

0 comments on commit c9c4eef

Please sign in to comment.