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(sync): use newspack_esp_sync_contact filter for the network_registration_site field #132

Merged
merged 5 commits into from
Sep 4, 2024
Merged
Changes from 3 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
18 changes: 17 additions & 1 deletion includes/class-esp-metadata-sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Esp_Metadata_Sync {
public static function init() {
\add_filter( 'newspack_ras_metadata_keys', [ __CLASS__, 'add_custom_metadata_fields' ] );
\add_filter( 'newspack_register_reader_metadata', [ __CLASS__, 'handle_custom_metadata_fields' ], 10, 2 );
\add_filter( 'newspack_data_events_reader_registered_metadata', [ __CLASS__, 'handle_custom_metadata_fields' ], 10, 2 );
\add_filter( 'newspack_esp_sync_contact', [ __CLASS__, 'handle_esp_sync_contact' ], 10, 2 );
\add_action( 'init', [ __CLASS__, 'register_listeners' ] );
}

Expand Down Expand Up @@ -55,6 +55,22 @@ public static function add_custom_metadata_fields( $metadata_fields ) {
return $metadata_fields;
}

/**
* Add handling for custom metadata fields when syncing to ESP.
*
* @param array $contact The contact metadata data.
*
* @return array The updated contact data.
*/
public static function handle_esp_sync_contact( $contact ) {
$user = get_user_by( 'email', $contact['email'] );
if ( ! $user ) {
return $contact;
}
$contact['metadata']['network_registration_site'] = self::get_registration_site_meta( $user->ID );
return $metadata;
miguelpeixe marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Add handling for custom metadata fields. Only fire for newly created users.
*
Expand Down