Created
February 18, 2022 22:11
-
-
Save ideadude/99714ad43279aac85f086fc0c0b703f4 to your computer and use it in GitHub Desktop.
PMPro Approvals: If a user was approved for any other level, consider them approved for every level.
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 | |
/** | |
* If a user was approved for any other level, consider them approved for every level. | |
* Requires the PMPro Approval Process for Membership Add On - https://www.paidmembershipspro.com/add-ons/approval-process-membership/ | |
* Must be using PMPro Approvals version 1.4.2 or higher. | |
* Add this code to your site following this guide - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
function my_approve_user_if_already_approved( $approved, $user_id, $level_id, $user_approval ) { | |
// Already approved? | |
if ( $approved ) { | |
return $approved; | |
} | |
// Check if this level requires approval. | |
if ( ! PMPro_Approvals::requiresApproval( $level_id ) ) { | |
return $approved; | |
} | |
// Okay, check their approval log. | |
$approval_log = get_user_meta( $user_id, 'pmpro_approval_log', true ); | |
if ( is_array( $approval_log) && ! empty( $approval_log ) ) { | |
$last_entry = end( $approval_log ); | |
if ( strpos( $last_entry, 'approved' ) !== false ) { | |
// Previously approved. | |
$approved = true; | |
} | |
} | |
return $approved; | |
} | |
add_action( 'pmproap_user_is_approved', 'my_approve_user_if_already_approved', 10, 4 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This recipe is included in the blog post on "Automatically Approve Previously Approved Members" at Paid Memberships Pro here: https://www.paidmembershipspro.com/automatically-approve-previously-approved-members/