From 8edad530d0ad719c4fe9812f3f3d58d5fa30d9c2 Mon Sep 17 00:00:00 2001 From: leogermani Date: Fri, 12 Dec 2025 16:42:46 -0300 Subject: [PATCH] fix: add default reader meta --- .../class-reader-activation.php | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/includes/reader-activation/class-reader-activation.php b/includes/reader-activation/class-reader-activation.php index aaba371503..ad2be6d3ab 100644 --- a/includes/reader-activation/class-reader-activation.php +++ b/includes/reader-activation/class-reader-activation.php @@ -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' ] ); } } @@ -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 ); @@ -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();