the4bee
Forum Replies Created
-
It seems that the provided code allows access to any logged in user.
The following is modified for access only by administrator or partner_manager roles:
if ( ! defined( ‘ABSPATH’ ) ) {
exit;
}add_action( ‘init’, ‘custom_um_registration_access’ );
function custom_um_registration_access() {
// Check if Ultimate Member is available.
if ( ! function_exists( ‘UM’ ) ) {
return;
}// If the user is logged in, verify they have an allowed role. if ( is_user_logged_in() ) { $current_user = wp_get_current_user(); $allowed_roles = array( 'administrator', 'partner_manager' ); if ( ! array_intersect( $allowed_roles, $current_user->roles ) ) { // User is logged in but not allowed; do not modify registration access. return; } } // Either not logged in, or logged in with allowed role. add_filter( 'um_registration_for_loggedin_users', '__return_true' ); add_filter( 'um_field_value', 'custom_um_field_value_admin_registration', 10, 5 );
}
function custom_um_field_value_admin_registration( $value, $default, $key, $type, $data ) {
// Ensure Ultimate Member’s fields are available.
if ( function_exists( ‘UM’ ) ) {
$fields = UM()->fields();
// Check that the fields object exists and that we are in registration mode.
if ( is_object( $fields ) && isset( $fields->set_mode ) && ‘register’ === $fields->set_mode ) {
$value = $default;
}
}
return $value;
}Magic!
I will go through it and see how I can adapt it to another user role.
Then I will mark the thread solved.Thank you very much!