Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Automatically approve, previously approved members. [Paid Memberships Pro]
<?php
/**
* Automatically approve any previously approved member.
* Add this code to your site following this guide - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmpro_automatically_approve_previously_approved( $level_id, $user_id, $cancelled_level ) {
if ( ! class_exists( 'PMPro_Approvals' ) ) {
return;
}
if ( ! PMPro_Approvals::requiresApproval( $level_id ) ) {
return;
}
$prev_approved = get_user_meta( $user_id, 'pmpro_approval_log', true );
if ( is_array( $prev_approved) && ! empty( $prev_approved ) ) {
// Approve member if they have previously been approved.
foreach( $prev_approved as $approval_string ) {
if ( strpos( $approval_string, 'approved' ) !== false ) {
// Let's approve the member
PMPro_Approvals::approveMember( $user_id, $level_id );
break;
}
}
}
}
add_action( 'pmpro_after_change_membership_level', 'my_pmpro_automatically_approve_previously_approved', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment