diff --git a/includes/class-newspack-newsletters-contacts.php b/includes/class-newspack-newsletters-contacts.php index 69c55a413..2f0d753c2 100644 --- a/includes/class-newspack-newsletters-contacts.php +++ b/includes/class-newspack-newsletters-contacts.php @@ -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;