Created
October 4, 2021 14:15
-
-
Save DumahX/0d81120700520c1834eb155c95cbc9af 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 | |
function mepr_validate_user_role($errors) { | |
// Memberships to apply restrictions on. | |
$membership_ids = array('123', '321', '12345'); | |
// The current membership isn't being validated, so don't do anything else. | |
if(!in_array($_POST['mepr_product_id'], $membership_ids)) { | |
return $errors; | |
} | |
$current_user = wp_get_current_user(); | |
if($current_user->ID == 0) { | |
$errors[] = 'You must be logged in and have the MICHA Member user role to sign up.'; | |
} else { | |
// Check if the user has the MICHA Member role. | |
if(!in_array('micha_member', (array) $current_user->roles)) { | |
$errors[] = 'You must have the MICHA Member user role to sign up.'; | |
} | |
} | |
return $errors; | |
} | |
add_filter('mepr-validate-signup', 'mepr_validate_user_role'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment