Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kimcoleman/31759b16d196922c355a1957ceabd17c to your computer and use it in GitHub Desktop.
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
<?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