Created
March 31, 2025 09:37
-
-
Save JarrydLong/5bf8ea1a639275798db5ea31d0d79b85 to your computer and use it in GitHub Desktop.
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 //do not copy | |
function my_pmpro_registration_checks( $okay, $level ){ | |
global $pmpro_msg, $pmpro_msgt; | |
/** | |
* Restricts based on gender field - START | |
*/ | |
$gender = isset( $_REQUEST['gender'] ) ? $_REQUEST['gender'] : ''; //change to your field name | |
if( empty( $gender ) ) { | |
return $okay; | |
} | |
if( $gender == 'Ma' ) { | |
$pmpro_msg = "You cannot sign up for this membership level"; //change to your preferred wording | |
$pmpro_msgt = "pmpro_error"; | |
return false; | |
} | |
/** | |
* Restricts based on gender field - END | |
*/ | |
/** | |
* Restricts based on current level - START | |
*/ | |
//Gets the levels of the current member if they are logged in | |
$levels = pmpro_getMembershipLevelsForUser(); | |
if( !$levels ) { | |
return $okay; | |
} | |
$levels_not_allowed = array( 1, 2 ); //Level 1 and 2 can't sign up if they have level 3 | |
$level_required = 3; | |
foreach( $levels as $member_levels ) { | |
if( $member_levels->id == $level_required ) { | |
//They have level 3 in this case, lets check what level they want to sign up for | |
if( in_array( $level, $levels_not_allowed ) ) { | |
$pmpro_msg = "You cannot sign up for level 1 or 2 because you hold level 3."; //change to your preferred wording | |
$pmpro_msgt = "pmpro_error"; | |
return false; | |
} | |
} | |
} | |
/** | |
* Restricts based on current level - END | |
*/ | |
return $okay; | |
} | |
add_filter( "pmpro_registration_checks", "my_pmpro_registration_checks", 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment