Forked from messica/my_pmproec_pmpro_after_change_membership_level.php
Created
May 22, 2019 18:35
-
-
Save LMNTL/8b23e7240bd7180d942893409ecafdb8 to your computer and use it in GitHub Desktop.
Make PMPro MailChimp compatible with PMPro Email Confirmation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Make PMPro MailChimp compatible with PMPro Email Confirmation | |
*/ | |
// Don't subscribe to MailChimp if user is not validated. | |
function my_pmproec_pmpro_after_change_membership_level($level_id, $user_id) { | |
if( function_exists('pmproec_isEmailConfirmationLevel') && pmproec_isEmailConfirmationLevel($level_id) ) { | |
$validation_key = get_user_meta($user_id, "pmpro_email_confirmation_key", true); | |
if ( empty( $validation_key ) || $validation_key != "validated" ) { | |
remove_action("pmpro_after_change_membership_level", "pmpromc_pmpro_after_change_membership_level", 15, 2); | |
} | |
} | |
} | |
add_action('pmpro_after_change_membership_level', 'my_pmproec_pmpro_after_change_membership_level', 10, 2); // Run before PMPro MailChimp | |
// Don't subscribe to MailChimp if user is not validated. | |
function my_pmproec_pmpro_after_checkout($user_id) { | |
$level = pmpro_getMembershipLevelForUser($user_id); | |
if( function_exists('pmproec_isEmailConfirmationLevel') && pmproec_isEmailConfirmationLevel($level->id) ) { | |
$validation_key = get_user_meta($user_id, "pmpro_email_confirmation_key", true); | |
if ( empty( $validation_key ) || $validation_key != "validated" ) { | |
remove_action("pmpro_after_checkout", "pmpromc_pmpro_after_checkout", 15); | |
} | |
} | |
} | |
add_action('pmpro_after_checkout', 'my_pmproec_pmpro_after_checkout', 10); // Run before PMPro MailChimp | |
// Add user to MailChimp after Validation | |
function my_pmproec_after_validate_user($user_id) { | |
if(function_exists('pmpromc_pmpro_after_checkout')) { | |
pmpromc_pmpro_after_checkout($user_id); | |
} | |
} | |
add_action('pmproec_after_validate_user', 'my_pmproec_after_validate_user'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment