Forked from kimcoleman/dynamic_pmpro_levels_array.php
Created
February 3, 2020 04:38
-
-
Save ipokkel/d398838dd633f3fd33fe2e63636b6266 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 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 | |
/** | |
* 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 levels 1, 5, 6, and 7 user has level 1. | |
if ( pmpro_hasMembershipLevel( '1' ) ) { | |
unset( $levels['1'] ); | |
unset( $levels['5'] ); | |
unset( $levels['6'] ); | |
unset( $levels['7'] ); | |
} | |
// remove levels 1, 2, 3, and 4 if user has level 2. | |
if ( pmpro_hasMembershipLevel( '2' ) ) { | |
unset( $levels['1'] ); | |
unset( $levels['2'] ); | |
unset( $levels['3'] ); | |
unset( $levels['4'] ); | |
} | |
// only show levels 1 and 2 if user has no level. | |
if ( ! pmpro_hasMembershipLevel( ) ) { | |
unset( $levels['3'] ); | |
unset( $levels['4'] ); | |
unset( $levels['5'] ); | |
unset( $levels['6'] ); | |
unset( $levels['7'] ); | |
} | |
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