Skip to content

Instantly share code, notes, and snippets.

@kimwhite
Last active August 24, 2021 16:34
Show Gist options
  • Save kimwhite/3a10cccc019c1af98cfd534170b656bb to your computer and use it in GitHub Desktop.
Save kimwhite/3a10cccc019c1af98cfd534170b656bb to your computer and use it in GitHub Desktop.
<?php
/**
* This recipe will restrict someone with level 1 changing to level 2.
* change line 25 for other level numbers
* 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_pmpro_restrict_membership_by_level( $okay ) {
// If something else isn't okay, stop from running this code further.
if ( ! $okay ) {
return $okay;
}
// If the user doesn't have a membership level carry on with checkout.
if ( ! pmpro_hasMembershipLevel() ) {
return $okay;
}
// Check if the user's current membership level is restricted from chaning to new level.
if ( pmpro_hasMembershipLevel( '1' ) && $_REQUEST['level'] == '2' ) { // Change level ID to a different level.
$okay = false;
pmpro_setMessage( 'This Level is for new Members Only', 'pmpro_error' );
}
return $okay;
}
add_filter( 'pmpro_registration_checks', 'my_pmpro_restrict_membership_by_level', 10, 1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment