Skip to content

Commit

Permalink
feat: remove redundant code
Browse files Browse the repository at this point in the history
  • Loading branch information
leogermani committed Jul 18, 2024
1 parent a1fea57 commit 83e9ed1
Showing 1 changed file with 0 additions and 41 deletions.
41 changes: 0 additions & 41 deletions includes/class-newspack-newsletters-subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class Newspack_Newsletters_Subscription {
*/
public static function init() {
add_action( 'rest_api_init', [ __CLASS__, 'register_api_endpoints' ] );
add_action( 'newspack_registered_reader', [ __CLASS__, 'newspack_registered_reader' ], 10, 5 );

/** User email verification for subscription management. */
add_action( 'resetpass_form', [ __CLASS__, 'set_current_user_email_verified' ] );
Expand Down Expand Up @@ -550,46 +549,6 @@ public static function delete_user_subscription( $user_id ) {
return Newspack_Newsletters_Contacts::delete( $user_id );
}

/**
* Add a contact to ESP when a reader is registered.
*
* @param string $email Email address.
* @param bool $authenticate Whether to authenticate after registering.
* @param false|int $user_id The created user id.
* @param false|\WP_User $existing_user The existing user object.
* @param array $metadata Metadata.
*/
public static function newspack_registered_reader( $email, $authenticate, $user_id, $existing_user, $metadata ) {
// Prevent double-syncing to audience if the registration method was through a Newsletter Subscription Form block.
if ( isset( $metadata['registration_method'] ) && 'newsletters-subscription' === $metadata['registration_method'] ) {
return;
}

if ( empty( $metadata['lists'] ) ) {
return;
}

$lists = $metadata['lists'];
unset( $metadata['lists'] );

$metadata['newsletters_subscription_method'] = 'reader-registration';

// Adding is actually upserting, so no need to check if the hook is called for an existing user.
try {
self::add_contact(
[
'email' => $email,
'metadata' => $metadata,
],
$lists,
true // Async.
);
} catch ( \Exception $e ) {
// Avoid breaking the registration process.
Newspack_Newsletters_Logger::log( 'Error adding contact: ' . $e->getMessage() );
}
}

/**
* Update a contact lists subscription.
*
Expand Down

0 comments on commit 83e9ed1

Please sign in to comment.