Created
April 29, 2021 19:34
-
-
Save JarrydLong/e4567ad77d001f60336a1edffd6fc596 to your computer and use it in GitHub Desktop.
This file contains 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 | |
/** | |
* This will remove all members who have an active membership and have bought through PayPal | |
* or PayPal Express | |
* | |
* Exercise caution when making these changes. They cannot be undone. Make a backup of your database | |
* before running this script. | |
* | |
* Enter /wp-admin/?removepaypal=true in your URL to run the script. | |
* | |
* | |
* You can add this recipe to your site by creating a custom plugin | |
* or using the Code Snippets plugin available for free in the WordPress repository. | |
* Read this companion article for step-by-step directions on either method. | |
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
function mypmpro_remove_paypal_users(){ | |
if( isset( $_GET['removepaypal'] ) ){ | |
global $wpdb; | |
//Get all transactions that were purchased using PayPal or PayPal Express | |
$sql = "SELECT * FROM $wpdb->pmpro_membership_orders WHERE `gateway` = 'paypal' OR `gateway` = 'paypalexpress'"; | |
$results = $wpdb->get_results( $sql ); | |
if( $results ){ | |
foreach( $results as $result ){ | |
//Lets make sure they're still using PayPal and haven't signed up with a different gateway | |
$last_order = new MemberOrder(); | |
$last_order->getLastMemberOrder( $result->user_id, 'success' ); | |
if( $last_order->gateway === 'paypal' || $last_order === 'paypalexpress' ){ | |
//They're still using PayPal - Remove their membership | |
$removed = pmpro_changeMembershipLevel( 0, $result->user_id ); | |
echo 'Removed Membership - '.$removed.' - '.$result->user_id; | |
} | |
} | |
} | |
exit( 'End' ); | |
} | |
} | |
add_action( 'admin_init', 'mypmpro_remove_paypal_users' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment