Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save kimwhite/85681be00b1fd14d6c81080c6730e952 to your computer and use it in GitHub Desktop.

Select an option

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. // This is an example. Modify for your use. BACKUP your database before running
/**
* 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() {
global $wpdb;
// Run only if ?my_query=1 is present and the user is an admin.
if ( ! empty( $_REQUEST['my_query'] ) && current_user_can( 'manage_options' ) ) {
$wpdb->query(
"UPDATE {$wpdb->pmpro_memberships_users}
SET enddate = '2026-03-01 23:59:00'
WHERE status = 'active'
AND membership_id = 1
AND (enddate IS NULL OR enddate = '0000-00-00 00:00:00')"
);
}
}
add_action( 'init', 'pmpro_process_query' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment