Skip to content

Commit

Permalink
fix(mc): handle standard MC merge fields when fixing duplicates (#3637)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkoo authored Jan 16, 2025
1 parent 9562ecb commit 80248a2
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions includes/cli/class-mailchimp.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function( $acc, $field_slug ) use ( $prefix, $all_fields ) {

$result = Mailchimp_API::get( "lists/$audience_id/merge-fields?count=1000" );
if ( is_wp_error( $result ) || empty( $result['merge_fields'] || ! is_array( $result['merge_fields'] ) ) ) {
\WP_CLI::error( __( 'Could not connect to Mailchimp API. Is the site connected to Mailchimp?', 'newspack-subscription-migrations' ) );
\WP_CLI::error( __( 'Could not connect to Mailchimp API. Is the site connected to Mailchimp?', 'newspack-plugin' ) );
}
$fields = $result['merge_fields'];

Expand Down Expand Up @@ -123,7 +123,7 @@ public static function cli_mailchimp_delete_merge_fields( $args, $assoc_args ) {
$prefix = $assoc_args['prefix'] ?? '';

if ( empty( $fields_to_delete ) ) {
\WP_CLI::error( __( 'Please specify at least one field to delete.', 'newspack-subscription-migrations' ) );
\WP_CLI::error( __( 'Please specify at least one field to delete.', 'newspack-plugin' ) );
}

$all_fields = Metadata::get_all_fields();
Expand All @@ -149,7 +149,7 @@ function( $acc, $field_slug ) use ( $prefix, $all_fields ) {

$result = Mailchimp_API::get( "lists/$audience_id/merge-fields?count=1000" );
if ( is_wp_error( $result ) || empty( $result['merge_fields'] || ! is_array( $result['merge_fields'] ) ) ) {
\WP_CLI::error( __( 'Could not connect to Mailchimp API. Is the site connected to Mailchimp?', 'newspack-subscription-migrations' ) );
\WP_CLI::error( __( 'Could not connect to Mailchimp API. Is the site connected to Mailchimp?', 'newspack-plugin' ) );
}
$fields = $result['merge_fields'];

Expand Down Expand Up @@ -450,8 +450,7 @@ private static function delete_duplicate_fields_for_list( $list_id, $is_dry_run
* @return array
*/
private static function get_fields_to_check_for_duplicates() {
$all_fields = Metadata::get_all_fields();
$fields = array_map(
$fields = array_map(
function( $key ) {
return Metadata::get_key( $key );
},
Expand All @@ -462,6 +461,13 @@ function( $key ) {
$fields = array_merge(
$fields,
[
// Standard Mailchimp merge fields.
'First Name',
'Last Name',
'Phone',
'Address',

// Other Newspack-specific fields.
'origin_newspack',
'newsletters_subscription_method',
'current_page_url',
Expand Down

0 comments on commit 80248a2

Please sign in to comment.