Created
November 6, 2023 07:03
-
-
Save JarrydLong/cf8179d3a0bfa528bfa16313f4c48bec to your computer and use it in GitHub Desktop.
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 //do not copy | |
/** | |
* This recipe will bulk approve users that may have signed up before the Add On was installed. | |
* | |
* Use /wp-admin/?approvemembers=true to run the script. | |
* | |
* Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
function mypmpro_approve_all_existing_members_once(){ | |
if( isset( $_REQUEST['approvemembers'] ) ) { | |
if ( ! class_exists( 'PMPro_Approvals' ) ) { | |
return; | |
} | |
$users = get_users(); | |
if( ! $users ) { | |
return; | |
} | |
foreach( $users as $user ) { | |
$user_id = $user->ID; | |
$users_level = pmpro_getMembershipLevelForUser( $user_id ); | |
if( empty( $users_level ) ) { | |
continue; | |
} | |
//doesn't require approval, do nothing | |
if ( ! PMPro_Approvals::requiresApproval( $users_level->id ) ) { | |
echo "Did not need to approve user ".$user_id."<br/>"; | |
} else { | |
//approve them | |
PMPro_Approvals::ApproveMember( $user_id, $users_level->id ); | |
echo "Approving user ".$user_id." for level ".$users_level->id."<br/>"; | |
} | |
} | |
exit(); | |
} | |
} | |
add_action( 'admin_init', 'mypmpro_approve_all_existing_members_once' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment