Forked from greathmaster/pmpro-lock-membership-levels-lock-all-existing-members.php
Last active
March 7, 2022 16:56
-
-
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.
This file contains 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 | |
/** | |
* 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