Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kimwhite/85681be00b1fd14d6c81080c6730e952 to your computer and use it in GitHub Desktop.
Save kimwhite/85681be00b1fd14d6c81080c6730e952 to your computer and use it in GitHub Desktop.
Function to Bulk update user's expiration dates via SQL - Paid Memberships Pro
<?php. // TESTING
/**
* Added SQL to a function. Run once then disable.
*
* Bulk update all users to have an expiration date that belong to a specific membership level.
* Visit https://yoursite.com/wp-admin/?my_query=1 when logged in as an admin to have existing users updated.
* Remove this code when finished.
*
* Please update the wp_ prefix to match that of your database as well as the membership_id and enddate value (YYYY-MM-DD).
*
* IMPORTANT: Have a backup of your site before running this code.
*/
function pmpro_process_query() {
//Run the code if ?my_query=1 is in URL and they're admin.
global $wpdb;
if ( ! empty( $_REQUEST['my_query'] ) && current_user_can( 'manage_options' ) ) {
$wpdb->query("UPDATE $wpdb->pmpro_memberships_users SET enddate = '2023-01-01 23:59:00' WHERE status = 'active' AND membership_id = 1;");
}
}
add_action( 'init', 'pmpro_process_query' );
//UPDATE wp_pmpro_memberships_users SET enddate = '2020-12-31 00:00:00' WHERE status = 'active' AND membership_id = 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment