Last active
November 28, 2023 15:20
-
-
Save JarrydLong/56c0b6b56c4098985ebd2936de48a436 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 | |
/** | |
* 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 19 and 43 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 the 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