Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save davidmutero/9f8ff88aadf49bd38b105140c7268ff2 to your computer and use it in GitHub Desktop.
Save davidmutero/9f8ff88aadf49bd38b105140c7268ff2 to your computer and use it in GitHub Desktop.
Function to Bulk update user's expiration dates via SQL (One Year from Start Date) - Paid Memberships Pro
<?php. // TESTING
/**
* Run SQL to bulk update all users in a specific membership level.
* Sets enddate = startdate + 1 year.
*
* 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.
*
* IMPORTANT: Have a backup of your site before running this code.
*/
function pmpro_process_query() {
global $wpdb;
// Run only if ?my_query=1 is in the URL and user is admin.
if ( ! empty( $_REQUEST['my_query'] ) && current_user_can( 'manage_options' ) ) {
$table = $wpdb->prefix . 'pmpro_memberships_users';
// Update: set enddate = startdate + 1 year for active members in membership_id = 1.
$sql = "
UPDATE $table
SET enddate = DATE_ADD(startdate, INTERVAL 1 YEAR)
WHERE status = 'active' AND membership_id = 1;
";
$wpdb->query( $sql );
}
}
add_action( 'init', 'pmpro_process_query' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment