Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(esp-sync): sync Connected Account field #3414

Merged
merged 4 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions includes/oauth/class-google-login.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@ public static function api_google_login_register( $request ) {
];

if ( $existing_user ) {
// Update user meta with connected account info.
\update_user_meta( $existing_user->ID, Reader_Activation::CONNECTED_ACCOUNT, 'google' );

// Log the user in.
$result = Reader_Activation::set_current_reader( $existing_user->ID );
$message = __( 'Thank you for signing in!', 'newspack-plugin' );
Expand Down
1 change: 1 addition & 0 deletions includes/reader-activation/class-reader-activation.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ final class Reader_Activation {
const EMAIL_VERIFIED = 'np_reader_email_verified';
const WITHOUT_PASSWORD = 'np_reader_without_password';
const REGISTRATION_METHOD = 'np_reader_registration_method';
const CONNECTED_ACCOUNT = 'np_reader_connected_account';
const READER_SAVED_GENERIC_DISPLAY_NAME = 'np_reader_saved_generic_display_name';

/**
Expand Down
17 changes: 17 additions & 0 deletions includes/reader-activation/sync/class-metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

namespace Newspack\Reader_Activation\Sync;

use Error;
dkoo marked this conversation as resolved.
Show resolved Hide resolved
use Newspack\Reader_Activation;
use Newspack\Logger;

defined( 'ABSPATH' ) || exit;
Expand Down Expand Up @@ -330,10 +332,25 @@ public static function normalize_contact_data( $contact ) {
}

$metadata = $contact['metadata'];
$user = ! empty( $metadata['account'] ) ? \get_user_by( 'id', $metadata['account'] ) : false;
$normalized_metadata = [];
$raw_keys = self::get_raw_keys();
$prefixed_keys = self::get_prefixed_keys();

// Registration-related fields.
if ( $user ) {
$registration_method = ! empty( $metadata['registration_method'] ) ? $metadata['registration_method'] : \get_user_meta( $user->ID, Reader_Activation::REGISTRATION_METHOD, true );
$connected_account = ! empty( $metadata['connected_account'] ) ? $metadata['connected_account'] : \get_user_meta( $user->ID, Reader_Activation::CONNECTED_ACCOUNT, true );
if ( ! empty( $registration_method ) ) {
$metadata['registration_method'] = $registration_method;
}
if ( $connected_account && in_array( $connected_account, Reader_Activation::SSO_REGISTRATION_METHODS ) ) {
$metadata['connected_account'] = $connected_account;
} elseif ( $registration_method && in_array( $registration_method, Reader_Activation::SSO_REGISTRATION_METHODS ) ) {
$metadata['connected_account'] = $registration_method;
}
}
dkoo marked this conversation as resolved.
Show resolved Hide resolved

// Capture UTM params and signup/payment page URLs as meta for registration or payment.
if ( self::has_key( 'current_page_url', $metadata ) || self::has_key( 'payment_page', $metadata ) ) {
$is_payment = self::has_key( 'payment_page', $metadata );
Expand Down
2 changes: 1 addition & 1 deletion includes/reader-activation/sync/class-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public static function get_contact_from_customer( $customer, $payment_page_url =
$last_name = $customer->get_billing_last_name();
$full_name = trim( "$first_name $last_name" );
$contact = [
'email' => $customer->get_billing_email(),
'email' => ! empty( $customer->get_billing_email() ) ? $customer->get_billing_email() : $customer->get_email(),
'metadata' => $metadata,
];
if ( ! empty( $full_name ) ) {
Expand Down