Created
February 19, 2024 15:54
-
-
Save kimcoleman/a09e1af7442bbb58a63a4f8dce7d09ba to your computer and use it in GitHub Desktop.
Re-run the PMPro v3.0 upgrade script.
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 | |
/** | |
* 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