Skip to content
Merged
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
27 changes: 19 additions & 8 deletions includes/reader-activation/class-reader-activation.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ public static function init() {
\add_filter( 'lostpassword_errors', [ __CLASS__, 'rate_limit_lost_password' ], 10, 2 );
\add_filter( 'newspack_esp_sync_contact', [ __CLASS__, 'set_mailchimp_sync_contact_status' ], 10, 2 );
\add_filter( 'login_url', [ __CLASS__, 'redirect_oauth_to_ras_login' ], 10, 3 );

/**
* If RAS is enabled, we assume that any user created by Woo is a reader, without a password and unverified.
*/
\add_action( 'woocommerce_created_customer', [ __CLASS__, 'add_default_reader_metadata' ] );
}
}

Expand Down Expand Up @@ -2291,14 +2296,7 @@ public static function register_reader( $email, $display_name = '', $authenticat
return $user_id;
}

/**
* Add default reader related meta.
*/
\update_user_meta( $user_id, self::READER, true );
/** Email is not yet verified. */
\update_user_meta( $user_id, self::EMAIL_VERIFIED, false );
/** User hasn't set their own password yet. */
\update_user_meta( $user_id, self::WITHOUT_PASSWORD, true );
self::add_default_reader_metadata( $user_id );

Logger::log( 'Created new reader user with ID ' . $user_id );

Expand Down Expand Up @@ -2921,5 +2919,18 @@ public static function get_checkout_configuration() {
'woocommerce_terms_confirmation_url' => self::get_terms_confirmation_url(),
];
}

/**
* Add default reader related meta to a user that was just created.
*
* @param int $customer_id User ID.
*/
public static function add_default_reader_metadata( $customer_id ) {
\update_user_meta( $customer_id, self::READER, true );
/** Email is not yet verified. */
\update_user_meta( $customer_id, self::EMAIL_VERIFIED, false );
/** User hasn't set their own password yet. */
\update_user_meta( $customer_id, self::WITHOUT_PASSWORD, true );
}
}
Reader_Activation::init();