Skip to content

Commit

Permalink
Merge pull request #145 from andrewlimaza/3.1-support
Browse files Browse the repository at this point in the history
Add support for frontend changes V3.1+
  • Loading branch information
kimcoleman authored Sep 24, 2024
2 parents 633ca20 + 30db899 commit c3af3e6
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 72 deletions.
6 changes: 4 additions & 2 deletions classes/class-pmpromc-mailchimp-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ public function set_key() {
);

// the datacenter that the key belongs to.
list(, self::$dc) = explode('-', self::$api_key);
if ( strpos( self::$api_key, '-' ) != false ) {
list(, self::$dc) = explode('-', self::$api_key);
}

// Build the URL based on the datacenter
self::$api_url = "https://" . self::$dc . ".api.mailchimp.com/3.0";
Expand Down Expand Up @@ -492,7 +494,7 @@ private function set_error_msg($obj, $message = NULL)
global $msg;

$msgt = 'error';

if ( !is_string($obj) && ( 200 !== wp_remote_retrieve_response_code( $obj )) ) {
//there is an error and we have some kind of array or response object
if(is_array($obj) && !empty($obj['response'])) {
Expand Down
2 changes: 1 addition & 1 deletion includes/export-csv.php
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ function pmpro_transmit_content( $csv_fh, $filename, $headers = array() ) {
{
echo esc_html( str_repeat('-', 75 ) ) . "<br/>\n";
echo 'Please open a support case and paste in the warnings/errors you see above this text to\n ';
echo 'the <a href="http://paidmembershipspro.com/support/" target="_blank">Paid Memberships Pro support forum</a><br/>\n';
echo 'the <a href="https://www.paidmembershipspro.com/support/" target="_blank">Paid Memberships Pro support forum</a><br/>\n';
echo esc_html( str_repeat("=", 75) ) . "<br/>\n";
echo esc_html( file_get_contents($filename) );
echo esc_html( str_repeat("=", 75) ) . "<br/>\n";
Expand Down
110 changes: 66 additions & 44 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,52 +185,74 @@ function pmpromc_additional_lists_on_checkout() {

$display_modifier = empty( $pmpro_review ) ? '' : 'style="display: none;"';
?>
<div id="pmpro_mailing_lists" class="pmpro_checkout" <?php echo esc_html( $display_modifier ); ?>>
<hr />
<h2>
<span class="pmpro_checkout-h2-name">
<?php
if ( count( $additional_lists_array ) > 1 ) {
esc_html_e( 'Join one or more of our mailing lists.', 'pmpro-mailchimp' );
} else {
esc_html_e( 'Join our mailing list.', 'pmpro-mailchimp' );
}
?>
</span>
</h2>
<div class="pmpro_checkout-fields">
<?php
global $current_user;
// Nonce not needed as this is only setting the default value for the checkbox, not processing form data.
if ( isset( $_REQUEST['additional_lists'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
$additional_lists_selected = $_REQUEST['additional_lists']; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
} elseif ( isset( $_SESSION['additional_lists'] ) ) {
$additional_lists_selected = $_SESSION['additional_lists'];
} elseif ( ! empty( $current_user->ID ) ) {
$additional_lists_selected = get_user_meta( $current_user->ID, 'pmpromc_additional_lists', true );
} else {
$additional_lists_selected = array();
}
$count = 0;
foreach ( $additional_lists_array as $key => $additional_list ) {
$count++;
?>
<input type="checkbox" id="additional_lists_<?php echo esc_attr( $count ); ?>" name="additional_lists[]" value="<?php echo esc_attr( $additional_list->id ); ?>"
<?php
if ( is_array( $additional_lists_selected ) ) {
checked( in_array( $additional_list->id, $additional_lists_selected ) );
};
?>
/>
<label for="additional_lists_<?php echo esc_attr( $count ); ?>" class="pmpromc-checkbox-label"><?php echo esc_html( $additional_list->name ); ?></label><br/>
<?php
}
?>
</div>
</div>
<fieldset id="pmpro_form_fieldset-mailchimp-opt-in" class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_form_fieldset' ) ); ?>">
<div id="pmpro_mailing_lists" class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_card' ) ); ?>" <?php echo esc_html( $display_modifier ); ?>>
<div class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_card_content' ) ); ?>">
<legend class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_form_legend' ) ); ?>">
<h2 class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_form_heading pmpro_font-large' ) ); ?>">
<?php
if ( count( $additional_lists_array ) > 1 ) {
esc_html_e( 'Opt-In Mailing Lists', 'pmpro-mailchimp' );
} else {
esc_html_e( 'Opt-In Mailing List', 'pmpro-mailchimp' );
}
?>
</h2>
</legend>
<div class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_form_fields' ) ); ?>">
<div class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_form_fields-description' ) ); ?>">
<p>
<?php
if ( count( $additional_lists_array ) > 1 ) {
esc_html_e( 'Join one or more of our mailing lists.', 'pmpro-mailchimp' );
} else {
esc_html_e( 'Join our mailing list.', 'pmpro-mailchimp' );
}
?>
</p>
</div>
<div id="pmpro_mailchimp_opt_in_lists_div" class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_form_field pmpro_form_field-checkbox-grouped' ) ); ?>">
<ul class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_list pmpro_list-plain' ) ); ?>">
<?php
global $current_user;
// Nonce not needed as this is only setting the default value for the checkbox, not processing form data.
if ( isset( $_REQUEST['additional_lists'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
$additional_lists_selected = $_REQUEST['additional_lists']; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
} elseif ( isset( $_SESSION['additional_lists'] ) ) {
$additional_lists_selected = $_SESSION['additional_lists'];
} elseif ( ! empty( $current_user->ID ) ) {
$additional_lists_selected = get_user_meta( $current_user->ID, 'pmpromc_additional_lists', true );
} else {
$additional_lists_selected = array();
}
$count = 0;
foreach ( $additional_lists_array as $key => $additional_list ) {
$count++;
?>
<li class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_list_item' ) ); ?>">
<span class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_form_field-checkbox-grouped-item' ) ); ?>">
<input type="checkbox" id="additional_lists_<?php echo esc_attr( $count ); ?>" name="additional_lists[]" value="<?php echo esc_attr( $additional_list->id ); ?>" class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_form_input pmpro_form_input-checkbox' ) ); ?>"
<?php
if ( is_array( $additional_lists_selected ) ) {
checked( in_array( $additional_list->id, $additional_lists_selected ) );
};
?>
/>
<label for="additional_lists_<?php echo esc_attr( $count ); ?>" class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_form_label pmpro_form_label-inline pmpro_clickable' ) ); ?>"><?php echo esc_html( $additional_list->name ); ?></label>
</span>
</li>
<?php
}
?>
</ul>
</div> <!-- end pmpro_mailchimp_opt_in_lists_div -->
</div> <!-- end pmpro_form_fields -->
</div> <!-- end pmpro_card_content -->
</div> <!-- end pmpro_card -->
</fieldset> <!-- end pmpro_form_fieldset-mailchimp-opt-in -->
<?php
}
add_action( 'pmpro_checkout_after_tos_fields', 'pmpromc_additional_lists_on_checkout' );
add_action( 'pmpro_checkout_boxes', 'pmpromc_additional_lists_on_checkout' );

/**
* Preserve info when going off-site for payment w/offsite payment gateway (PayPal Express).
Expand Down
74 changes: 53 additions & 21 deletions includes/profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,29 +81,61 @@ function pmpromc_add_custom_user_profile_fields( $user ) {
</table>
<?php
} else { // Show on front-end profile page.
?>

<div class="pmpro_member_profile_edit-field pmpro_member_profile_edit-field-pmpromc_opt_in_list">
<label for="address">
<?php esc_html_e( 'Opt-in Mailchimp Mailing Lists', 'pmpro-mailchimp' );?>
</label>
<?php
$user_additional_audiences = get_user_meta( $user->ID, 'pmpromc_additional_lists', true );
?>
<div class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_spacer' ) ); ?>"></div>
<fieldset id="pmpro_form_fieldset-mailchimp-opt-in" class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_form_fieldset' ) ); ?>">
<legend class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_form_legend' ) ); ?>">
<h2 class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_form_heading pmpro_font-large' ) ); ?>">
<?php
if ( count( $additional_audiences_info ) > 1 ) {
esc_html_e( 'Opt-In Mailing Lists', 'pmpro-mailchimp' );
} else {
esc_html_e( 'Opt-In Mailing List', 'pmpro-mailchimp' );
}
?>
</h2>
</legend>
<div class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_form_fields' ) ); ?>">
<div class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_form_fields-description' ) ); ?>">
<p>
<?php
if ( count( $additional_audiences_info ) > 1 ) {
esc_html_e( 'Join one or more of our mailing lists.', 'pmpro-mailchimp' );
} else {
esc_html_e( 'Join our mailing list.', 'pmpro-mailchimp' );
}
?>
</p>
</div>
<div id="pmpro_mailchimp_opt_in_lists_div" class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_form_field pmpro_form_field-checkbox-grouped' ) ); ?>">
<ul class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_list pmpro_list-plain' ) ); ?>">
<?php
$user_additional_audiences = get_user_meta( $user->ID, 'pmpromc_additional_lists', true );

if ( isset( $user_additional_audiences ) ) {
$selected_audiences = $user_additional_audiences;
} else {
$selected_audiences = array();
}
if ( isset( $user_additional_audiences ) ) {
$selected_audiences = $user_additional_audiences;
} else {
$selected_audiences = array();
}

echo '<input type="hidden" name="additional_lists_profile" value="1" />';
foreach ( $additional_audiences_info as $audience_arr ) {
$checked_modifier = ( is_array( $selected_audiences ) && in_array( $audience_arr['id'], $selected_audiences ) ) ? ' checked' : '';
echo( "<input type='checkbox' name='additional_lists[]' value='" . esc_attr( $audience_arr['id'] ) . "' id='pmpromc_additional_lists_" . esc_attr( $audience_arr['id'] ) . "'" . esc_attr( $checked_modifier ) . ">" );
echo( "<label for='pmpromc_additional_lists_" . esc_attr( $audience_arr['id'] ) . "' class='pmpromc-checkbox-label'>" . esc_html( $audience_arr['name'] ) . "</label><br>" );
} ?>
</div> <!-- end pmpro_member_profile_edit-field-first_name -->
<?php
echo '<input type="hidden" name="additional_lists_profile" value="1" />';
foreach ( $additional_audiences_info as $audience_arr ) {
$checked_modifier = ( is_array( $selected_audiences ) && in_array( $audience_arr['id'], $selected_audiences ) ) ? ' checked' : '';
?>
<li class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_list_item' ) ); ?>">
<span class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_form_field-checkbox-grouped-item' ) ); ?>">
<input type="checkbox" name="additional_lists[]" value="<?php echo esc_attr( $audience_arr['id'] ); ?>" id="pmpromc_additional_lists_<?php echo esc_attr( $audience_arr['id'] ); ?>" class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_form_input pmpro_form_input-checkbox' ) ); ?>" <?php echo esc_attr( $checked_modifier ); ?>>
<label for="pmpromc_additional_lists_<?php echo esc_attr( $audience_arr['id'] ); ?>" class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_form_label pmpro_form_label-inline pmpro_clickable' ) ); ?>"><?php echo esc_html( $audience_arr['name'] ); ?></label>
</span>
</li>
<?php
}
?>
</ul>
</div> <!-- end pmpro_mailchimp_opt_in_lists_div -->
</div> <!-- end pmpro_form_fields -->
</fieldset> <!-- end pmpro_form_fieldset-mailchimp-opt-in -->
<?php
}
}
add_action( 'show_user_profile', 'pmpromc_add_custom_user_profile_fields', 12 );
Expand Down
6 changes: 3 additions & 3 deletions includes/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function pmpromc_options_page()
<?php if (function_exists('pmpro_getAllLevels')) { ?>
<hr/>
<h2><?php esc_html_e("Synchronize a Member's Level Name and ID", 'pmpro-mailchimp');?></h2>
<p><?php echo wp_kses_post( __("Since v2.0, this plugin creates and synchronizes the <code>PMPLEVEL</code> and <code>PMPLEVELID</code> merge field in Mailchimp. <strong>This will only affect new or updated members.</strong> You must import this data into MailChimp for existing members.", 'pmpro-mailchimp') ) ;?> <a href="http://www.paidmembershipspro.com/import-level-name-id-existing-members-using-new-merge-fields-pmpro-mailchimp-v2-0/" target="_blank"><?php esc_html_e('Read the documentation on importing existing members into MailChimp', 'pmpro-mailchimp');?></a>.</p>
<p><?php echo wp_kses_post( __("Since v2.0, this plugin creates and synchronizes the <code>PMPLEVEL</code> and <code>PMPLEVELID</code> merge field in Mailchimp. <strong>This will only affect new or updated members.</strong> You must import this data into MailChimp for existing members.", 'pmpro-mailchimp') ) ;?> <a href="https://www.paidmembershipspro.com/import-level-name-id-existing-members-using-new-merge-fields-pmpro-mailchimp-v2-0/" target="_blank"><?php esc_html_e('Read the documentation on importing existing members into MailChimp', 'pmpro-mailchimp');?></a>.</p>
<p><a class="button" onclick="jQuery('#pmpromc_export_instructions').show();"><?php esc_html_e('Click here to export your members list for a MailChimp Import', 'pmpro-mailchimp');?></a></p>
<hr/>

Expand All @@ -101,15 +101,15 @@ function pmpromc_options_page()
<li><?php esc_html_e('Log in to Mailchimp.', 'pmpro-mailchimp');?></li>
<li><?php esc_html_e('Go to Audiences -> Choose an Audience -> Add Members -> Import Members -> CSV or tab-delimited text file.', 'pmpro-mailchimp');?>
</li>
<li><?php esc_html_e('Import columns <code>PMPLEVEL</code> and <code>PMPLEVELID</code>. The fields should have those exact names in all uppercase letters.', 'pmpro-mailchimp');?>
<li><?php echo wp_kses_post( __('Import columns <code>PMPLEVEL</code> and <code>PMPLEVELID</code>. The fields should have those exact names in all uppercase letters.', 'pmpro-mailchimp') );?>
</li>
<li><?php esc_html_e('Check "auto update my existing audience". Click "Import".', 'pmpro-mailchimp');?></li>
</ol>

<p>
<?php
/* translators: %s - link to documentation */
echo wp_kses_post( sprintf( __('For more detailed instructions and screenshots, <a href="%s" target="_blank">click here to read our documentation on importing existing members into Mailchimp</a>.', 'pmpro-mailchimp'), 'http://www.paidmembershipspro.com/import-level-name-id-existing-members-using-new-merge-fields-pmpro-mailchimp-v2-0/' ) );
echo wp_kses_post( sprintf( __('For more detailed instructions and screenshots, <a href="%s" target="_blank">click here to read our documentation on importing existing members into Mailchimp</a>.', 'pmpro-mailchimp'), 'https://www.paidmembershipspro.com/import-level-name-id-existing-members-using-new-merge-fields-pmpro-mailchimp-v2-0/' ) );
?>
</p>

Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Please post it in the issues section of GitHub and we'll fix it as soon as we ca

= I need help installing, configuring, or customizing the plugin. =

Please visit [our support site at https://www.paidmembershipspro.com](http://www.paidmembershipspro.com/) for more documentation and our support forums.
Please visit [our support site at https://www.paidmembershipspro.com](https://www.paidmembershipspro.com/) for more documentation and our support forums.

== Screenshots ==

Expand Down

0 comments on commit c3af3e6

Please sign in to comment.