Forked from travislima/automatically-approve-previously-approved.php
Created
December 3, 2021 14:36
-
-
Save ideadude/60d28b84068b5a1a5c67488ea2ef8ec0 to your computer and use it in GitHub Desktop.
Automatically approve, previously approved members. [Paid Memberships Pro]
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 | |
/** | |
* Automatically approve any previously approved member. | |
* Requires the PMPro Approval Process for Membership Add On - https://www.paidmembershipspro.com/add-ons/approval-process-membership/ | |
* 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, true ); | |
break; | |
} | |
} | |
} | |
} | |
add_action( 'pmpro_after_change_membership_level', 'my_pmpro_automatically_approve_previously_approved', 10, 3 ); |
Here is a new method how to automatically keep an approved member, approved - https://gist.github.com/ideadude/99714ad43279aac85f086fc0c0b703f4
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Forked from: https://gist.github.com/travislima/bd0879ace049afcf511b6a111a9cc1b0#file-automatically-approve-previously-approved-php
Updated to use the 3rd "force" parameter in the approveMember call to bypass the admin check.
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/