Forked from ipokkel/my-pmpro-log-out-non-approved-member-after-checkout.php
Last active
May 31, 2024 11:56
-
-
Save JarrydLong/b247a3b1e69ee0bf439e4ff0db3fcd85 to your computer and use it in GitHub Desktop.
Logs out non-approved members after PMPro checkout
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 | |
/** | |
* This recipe logs out non-approved members after checkout. | |
* | |
* Requires PMPro Approvals - pmpro-approvals | |
* https://www.paidmembershipspro.com/add-ons/approval-process-membership/ | |
* | |
* You can add this recipe to your site by creating a custom plugin | |
* or using the Code Snippets plugin available for free in the WordPress repository. | |
* Read this companion article for step-by-step directions on either method. | |
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
function my_pmpro_log_out_non_approved( $url, $user_id, $level_id) { | |
// only check logged in users. | |
if ( ! is_user_logged_in() ) { | |
return; | |
} | |
// bail if pmpro-approvals not active | |
if ( ! class_exists( 'PMPro_Approvals' ) ) { | |
return; | |
} | |
//check to see if the user has any membership level | |
if ( pmpro_hasMembershipLevel() ) { | |
// Get the current user ID and their level ID for the PMPro Approvals meta. | |
$level = pmpro_getMembershipLevelForUser( $user_id ); | |
$level_id = $level->id; | |
// Bail if the level does not require approval | |
if ( ! PMPro_Approvals::requiresApproval( $level_id ) ) { | |
return; | |
} | |
//get the user meta. | |
$approval_status = get_user_meta( $user_id, 'pmpro_approval_' . $level_id, true ); | |
//check the user meta. | |
if ( 'pending' == $approval_status['status'] || 'denied' == $approval_status['status'] ) { | |
//Redirect to the homepage and log the user out. | |
$url = site_url(); | |
wp_logout(); | |
} | |
} | |
return $url; | |
} | |
add_filter( 'pmpro_confirmation_url', 'my_pmpro_log_out_non_approved', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment