Skip to content

Commit

Permalink
fix: dont send metadata on subscribe (#1648)
Browse files Browse the repository at this point in the history
* fix: dont send metadata on subscribe

* fix: avoid warnings

* docs: add more inline docs
  • Loading branch information
leogermani authored Sep 11, 2024
1 parent b5c7e12 commit 5b4a059
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion includes/class-newspack-newsletters-contacts.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,17 @@ public static function subscribe( $contact, $lists = false, $async = false, $con
$existing_contact = Newspack_Newsletters_Subscription::get_contact_data( $contact['email'], true );
$is_updating = \is_wp_error( $existing_contact ) ? false : true;

$result = self::upsert( $contact, $lists, $context, $existing_contact );
// When subscribing, we only want to keep the status and name metadata.
// Additional metadata can only be added when upserting a contact.
// This method is specific for handling Newsletter subscription, in which case there is no additional metadata being passed.
// Any additional metadata will be passes to the logs and filters though, so other actions can act upon it.
$accepted_metadata = [ 'status', 'name' ];
$subscribe_contact = $contact;
if ( ! empty( $subscribe_contact['metadata'] ) ) {
$subscribe_contact['metadata'] = array_intersect_key( $subscribe_contact['metadata'], array_flip( $accepted_metadata ) );
}

$result = self::upsert( $subscribe_contact, $lists, $context, $existing_contact );

if ( is_wp_error( $result ) ) {
return $result;
Expand Down

0 comments on commit 5b4a059

Please sign in to comment.