Forked from JarrydLong/pmpro-remove-user-membership-order-data.php
Last active
April 16, 2020 17:36
-
-
Save femiyb/306ed0e21ad4235660eb27a3f12c0eb3 to your computer and use it in GitHub Desktop.
Removes a user's membership order data either by manually adding in a query param, or when deleting a user through /wp-admin/
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 | |
/** | |
* Remove user order manually by adjusting the ID's in the array, or adding them into a | |
* query param by setting it to /?reset_test_accounts=true&accounts=2,3 | |
*/ | |
function pmpro_remove_orders( $user_id = null ){ | |
if( isset( $_REQUEST['reset_test_accounts'] ) && $_REQUEST['reset_test_accounts'] == 'true' ){ | |
global $wpdb; | |
// Change this according to the user's you'd like to remove | |
$user_ids = array( 2, 3 ); | |
// Or set it in the URL /?reset_test_accounts=true&accounts=2,3 | |
if( isset( $_REQUEST['accounts'] ) ) | |
$user_str = $_REQUEST['accounts']; | |
$user_ids = explode( ",", $user_str ); | |
if( is_array( $user_ids ) ){ | |
foreach( $user_ids as $uid ){ | |
//Deleting the member order | |
$wpdb->delete( $wpdb->pmpro_membership_orders, array( 'user_id' => intval( $uid ) ) ); | |
} | |
} | |
//Results are cached - this will force a new query to be run with the updated results | |
delete_transient( 'pmpro_report_memberships_signups' ); | |
delete_transient( 'pmpro_report_memberships_cancellations' ); | |
} | |
} | |
add_action( 'init', 'pmpro_remove_orders' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment