Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save andrewlimaza/698908d40b57dd2ca1106c73407c7898 to your computer and use it in GitHub Desktop.
Save andrewlimaza/698908d40b57dd2ca1106c73407c7898 to your computer and use it in GitHub Desktop.
PMPro Lock Membership Levels-lock existing members. Add this to your customizations plugin and refresh the page. Recommend deleting the code snippet after the operation is complete.
<?php
/**
* Bulk Update all member's with level ID 4 to be locked indefinitely.
* Run this code by adding to your site, loading a page. Once done, you may remove this code from your site.
*/
function bulk_lock_all_members() {
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
global $wpdb;
$users = $wpdb->get_results( "SELECT user_id FROM $wpdb->pmpro_memberships_users WHERE membership_id = 4 AND status = 'active'
" );
if( $users ) {
foreach ( $users as $user ) {
update_user_meta( $user->ID, 'pmprolml', 1 );
}
}
}
add_action( "init", "bulk_lock_all_members", 10, 0 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment