Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 17 additions & 0 deletions includes/plugins/class-newspack-newsletters.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,23 @@ public static function get_metadata_fields() {
return array_values( \get_option( self::METADATA_FIELDS_OPTION, self::get_default_metadata_fields() ) );
}

/**
* Get enabled fields which match provided keys.
* Will return key-value pairs of enabled fields which match the keys provided.
*
* @param string[] $keys Array of keys to match.
*/
public static function filter_enabled_fields( $keys ) {
$enabled_fields = self::get_metadata_fields();
return array_filter(
self::get_metadata_keys(),
function( $val, $key ) use ( $keys, $enabled_fields ) {
return in_array( $key, $keys ) && in_array( $val, $enabled_fields );
},
ARRAY_FILTER_USE_BOTH
);
}

/**
* Update the list of fields to be synced to the connected ESP.
*
Expand Down
5 changes: 5 additions & 0 deletions includes/plugins/class-teams-for-memberships.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ public static function normalize_contact( $contact ) {
return $contact;
}

$filtered_enabled_fields = Newspack_Newsletters::filter_enabled_fields( [ 'woo_team' ] );
if ( count( $filtered_enabled_fields ) === 0 ) {
return $contact;
}

if ( empty( $contact['email'] ) ) {
return $contact;
}
Expand Down