Skip to content

Instantly share code, notes, and snippets.

@kimcoleman
Created February 19, 2024 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kimcoleman/a09e1af7442bbb58a63a4f8dce7d09ba to your computer and use it in GitHub Desktop.
Save kimcoleman/a09e1af7442bbb58a63a4f8dce7d09ba to your computer and use it in GitHub Desktop.
Re-run the PMPro v3.0 upgrade script.
<?php
/**
* Re-runs the 3.0 upgrade script.
*/
function pmpro_upgrade_3_0_rerun() {
global $wpdb;
// Create a subscription for each unique `subscription_transaction_id` in the orders table.
$sqlQuery = "
INSERT IGNORE INTO {$wpdb->pmpro_subscriptions} ( user_id, membership_level_id, gateway, gateway_environment, subscription_transaction_id, status )
SELECT DISTINCT user_id, membership_id, gateway, gateway_environment, subscription_transaction_id, IF(STRCMP(status,'success'), 'cancelled', 'active')
FROM {$wpdb->pmpro_membership_orders}
WHERE subscription_transaction_id <> ''
AND gateway <> ''
AND gateway_environment <> ''
AND status in ('success','cancelled')
";
$wpdb->query( $sqlQuery );
// Change all `cancelled` orders to `success` so that we can remove `cancelled` status.
$sqlQuery = "
UPDATE {$wpdb->pmpro_membership_orders}
SET status = 'success'
WHERE status = 'cancelled'
";
$wpdb->query( $sqlQuery );
return 3.0;
}
add_action( 'admin_init', 'rerun_pmpro_upgrade_3_0' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment