From c3c631c7322379242b34c2f4c678c2e8dbf8eb3b Mon Sep 17 00:00:00 2001 From: efc Date: Wed, 15 Nov 2023 22:10:48 -0600 Subject: [PATCH 1/2] add filter for body parameter data --- classes/class-pmpromc-mailchimp-api.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/classes/class-pmpromc-mailchimp-api.php b/classes/class-pmpromc-mailchimp-api.php index 86537db..426d154 100644 --- a/classes/class-pmpromc-mailchimp-api.php +++ b/classes/class-pmpromc-mailchimp-api.php @@ -167,10 +167,10 @@ public function update_audience_members( $audience = '', $updates = [] ) { $this->add_pmpro_merge_fields( $audience) ; } - $data = (object) array( + $data = (object) apply_filters( 'pmpromc_body_parameters', array( 'members' => $updates, 'update_existing' => true, - ); + ), $audience ); $url = self::$api_url . "/lists/{$audience}"; $args = array( 'method' => 'POST', // Allows us update a user ID From 492452f6830aa2ecf551079f09ad97ac9f76e37c Mon Sep 17 00:00:00 2001 From: David Parker Date: Fri, 8 Mar 2024 10:24:58 -0500 Subject: [PATCH 2/2] Renaming filter and cleaning up code --- classes/class-pmpromc-mailchimp-api.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/classes/class-pmpromc-mailchimp-api.php b/classes/class-pmpromc-mailchimp-api.php index 426d154..38e760d 100644 --- a/classes/class-pmpromc-mailchimp-api.php +++ b/classes/class-pmpromc-mailchimp-api.php @@ -167,10 +167,21 @@ public function update_audience_members( $audience = '', $updates = [] ) { $this->add_pmpro_merge_fields( $audience) ; } - $data = (object) apply_filters( 'pmpromc_body_parameters', array( + $data = (object) array( 'members' => $updates, 'update_existing' => true, - ), $audience ); + ); + /** + * Filter the body parameter sent to the "update audience members" endpoint. + * + * @since TBD + * + * @param object $data The data to send to the Mailchimp API. + * @param string $audience The audience ID being updated. + * + * @return object The data to send to the Mailchimp API. + */ + $data = apply_filters( 'pmpromc_update_audience_members_data', $data, $audience ); $url = self::$api_url . "/lists/{$audience}"; $args = array( 'method' => 'POST', // Allows us update a user ID