• the4bee

    (@the4bee)


    I need to allow a specific role to user the register form to register new users.
    As it is a logged in user cannot access the register form.
    How can I access it?
    I am then going to process the data using ‘um_registration_complete’

Viewing 3 replies - 1 through 3 (of 3 total)
  • missveronica

    (@missveronicatv)

    @the4bee

    You can try the “Admin User Registrations” plugin

    https://github.com/MissVeronica/um-admin-user-registrations

    Thread Starter the4bee

    (@the4bee)

    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!

    Thread Starter the4bee

    (@the4bee)

    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;
    }

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.