Created
April 4, 2019 09:27
-
-
Save andrewlimaza/5d78034f0360bbea0c5f855d6c00a3bb to your computer and use it in GitHub Desktop.
Hide Members from Member Directory Page when not approved [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 | |
/** | |
* PLEASE NOTE: This will affect only new signups that have happened after this code has been added to your site | |
* (this won't run through existing pending/denied members and update their directory status). | |
* This will run on checkout and every time a member is approved, denied or reset in the Approvals Add On. | |
* Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
// Hide users from Directory when level requires Approval + show them once they are approved. | |
function hide_user_from_directory_if_level_requires_approval( $level_id, $user_id ) { | |
if ( ! class_exists('PMPro_Approvals') ) { | |
return; | |
} | |
if ( ! PMPro_Approvals::requiresApproval( $level_id ) ){ | |
return; | |
} | |
update_user_meta( $user_id, 'pmpromd_hide_directory', true ); | |
} | |
add_action( 'pmpro_after_change_membership_level', 'hide_user_from_directory_if_level_requires_approval', 10, 2 ); | |
function my_pmpro_add_users_to_directory( $user_id, $level_id ) { | |
delete_user_meta( $user_id, 'pmpromd_hide_directory' ); | |
} | |
add_action( 'pmpro_approvals_after_approve_member', 'my_pmpro_add_users_to_directory', 10, 2 ); | |
function my_pmpro_remove_users_from_directory( $user_id, $level_id ) { | |
update_user_meta( $user_id, 'pmpromd_hide_directory', true ); | |
} | |
add_action( 'pmpro_approvals_after_deny_member', 'my_pmpro_remove_users_from_directory', 10, 2 ); | |
add_action( 'pmpro_approvals_after_reset_member', 'my_pmpro_remove_users_from_directory', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment