Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save michaelbeil/56a4dcec91da4e87e7b56c881f5e1d24 to your computer and use it in GitHub Desktop.
Save michaelbeil/56a4dcec91da4e87e7b56c881f5e1d24 to your computer and use it in GitHub Desktop.
<?php //do not copy
/**
* This recipe lock members into their existing membership.
* They won't be able to cancel or sign up for a different membership level.
*
* Change lines 21 and 45 to the level ID that requires you to be locked in.
*
* If you don't want to prevent them from cancelling, comment out line 30 with //
*
* 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/
*/
/**
* Prevent members from cancelling their existing subscription
*/
function my_pmpro_free_remove_cancel_link( $pmpro_member_action_links ) {
if ( pmpro_hasMembershipLevel( '9' ) ) { //Change the your chosen level ID
unset( $pmpro_member_action_links['cancel'] );
}
return $pmpro_member_action_links;
}
add_filter( 'pmpro_member_action_links', 'my_pmpro_free_remove_cancel_link', 10);
/**
* Check if they're trying to sign up for a different level other than the existing level they have
*/
function pmproml_pmpro_registration_date_checks( $value ) {
global $pmpro_msg, $pmpro_msgt;
if( !empty( $_REQUEST['level'] ) ){
$level_id = intval( $_REQUEST['level'] );
} else {
$level_id = 0;
}
if ( pmpro_hasMembershipLevel( '9' ) && $level_id !== 9 ) { // Change to your chosen level ID
$pmpro_msg = __( "Registration has been disabled for any level other than your existing level. ", 'paid-memberships-pro' );
$pmpro_msgt = "pmpro_error";
return false;
}
return $value;
}
add_filter( 'pmpro_registration_checks', 'pmproml_pmpro_registration_date_checks', 10, 1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment