Skip to content

Instantly share code, notes, and snippets.

@kimcoleman
Last active February 19, 2024 18:58
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/e930d330a4be2938ac2b5058e1b217f9 to your computer and use it in GitHub Desktop.
Save kimcoleman/e930d330a4be2938ac2b5058e1b217f9 to your computer and use it in GitHub Desktop.
Optional database updates to drop orphaned orders table columns and unused usermeta rows.
<?php
/**
* Optional database updates to drop orphaned orders table columns and unused usermeta rows.
*/
function run_optional_pmpro_upgrade_3_0() {
global $wpdb;
// PMPro Stripe Billing Limits Add On has been merged into core and no longer needs `pmpro_stripe_billing_limit` user meta.
$sqlQuery = "
DELETE FROM {$wpdb->usermeta}
WHERE meta_key = 'pmpro_stripe_billing_limit'
";
$wpdb->query( $sqlQuery );
// Dropping deleted order columns.
$columns_to_drop = array(
'couponamount',
'certificate_id',
'certificateamount',
);
foreach ( $columns_to_drop as $column ) {
$sqlQuery = "
ALTER TABLE {$wpdb->pmpro_membership_orders}
DROP COLUMN {$column}
";
$wpdb->query( $sqlQuery );
}
}
add_action( 'admin_init', 'run_optional_pmpro_upgrade_3_0' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment