-
-
Save kimcoleman/31759b16d196922c355a1957ceabd17c to your computer and use it in GitHub Desktop.
Dynamically display certain levels on the Membership Levels page based on the current user's active 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 | |
/** | |
* Dynamically display certain levels on the Membership Levels page based on the current user's active level | |
* This example allows you to show/hide specific levels on the Membership Levels page. | |
*/ | |
/** | |
* Dynamically display certain levels on the Membership Levels page based on the current user's active level | |
* This example allows you to show/hide specific levels on the Membership Levels page. | |
*/ | |
function dynamic_pmpro_levels_array( $levels ) { | |
// Get all the levels | |
$levels = pmpro_getAllLevels( false, true ); | |
// remove level 1 if user has level 1. | |
if ( pmpro_hasMembershipLevel( '1' ) ) { | |
unset( $levels['1'] ); | |
} | |
// only show level 1 if user has no level. | |
if ( ! pmpro_hasMembershipLevel( ) ) { | |
unset( $levels['2'] ); | |
unset( $levels['3'] ); | |
} | |
return $levels; | |
} | |
add_filter( 'pmpro_levels_array', 'dynamic_pmpro_levels_array', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment