Forked from ideadude/my_approve_user_if_already_approved.php
Last active
May 24, 2023 22:09
-
-
Save michaelbeil/525270e6e254c7309fc4d2aea207c6c7 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 = false; | |
} | |
} | |
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