Created
July 17, 2025 13:13
-
-
Save dparker1005/4ed551f70455d91612aea0e8c100d521 to your computer and use it in GitHub Desktop.
If the user only has a single level and that level is pending, show them non-member content.
This file contains hidden or 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 the user only has a single level and that level is pending, show them non-member content. | |
* | |
* This is used to modify the behavior described here: https://github.com/strangerstudios/pmpro-approvals/issues/192 | |
* | |
* 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_pmproapprovals_show_non_member_content_to_pending_users( $haslevel, $user_id, $levels ) { | |
global $pmpro_pages; | |
// Let members access PMPro pages, PMPro can handle the cases here. | |
if ( is_page( $pmpro_pages ) ) { | |
return $haslevel; | |
} | |
// If $haslevel is already true, skip. | |
if ( $haslevel ) { | |
return $haslevel; | |
} | |
// Show the real levels in the admin. | |
if ( is_admin() ) { | |
return $haslevel; | |
} | |
//no user, skip | |
if ( empty( $user_id ) ) { | |
return $haslevel; | |
} | |
// If levels is not an array or has more than one element, skip. | |
if ( ! is_array( $levels ) || count( $levels ) !== 1 ) { | |
return $haslevel; | |
} | |
// If the value is not 0 or '0', skip. | |
if ( $levels[0] !== 0 && $levels[0] !== '0' ) { | |
return $haslevel; | |
} | |
// If the user has only one level and it is pending, show non-member content. | |
$user_levels = pmpro_getMembershipLevelsForUser( $user_id ); | |
$approvals = PMPro_Approvals::get_instance(); | |
if ( count( $user_levels ) === 1 && $approvals::isPending( $user_id, $user_levels[0]->id ) ) { | |
// Show non-member content | |
return true; | |
} | |
// Otherwise, return the original $haslevel value. | |
return $haslevel; | |
} | |
add_filter( 'pmpro_has_membership_level', 'my_pmproapprovals_show_non_member_content_to_pending_users', 15, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment