• Resolved makmerghen

    (@makmerghen)


    hello
    in case using add_filter( ‘um_registration_for_loggedin_users’, ‘__return_true’ );
    to let the sign in user can add new users using UM registration form
    is it possible to determined the number of new users that specific user role can add ?

    as example if the user has “editor” role then he can add only 20 user and if he tried to add more he will find message saying you are not allow to add more users
    is that possible and how to do that?
    best regards

Viewing 7 replies - 31 through 37 (of 37 total)
  • Thread Starter makmerghen

    (@makmerghen)

    thanks dear @champsupertramp
    https://www.mediafire.com/file/9te8c0jznp3mwdn/UM+snippets.json/file
    please import this file to snippets code plugin it has all codes I used for UM
    the last 2 that related to our current issue
    one for control registration number
    and the other for create email if no email in UM register form to avoid error

    best regards

    Hello @champsupertramp
    I loved the idea of this post so I have request if possible to do please let me know if you can make it here or you need me to create new post for it
    need field in user profile page in back end or even in UM profile page
    this field I can add number of users the current user can register while he is logged in using UM register form
    so if I add for specific user in this field number 4 that mean he can add only 4 new users and then he will not be able to add more and if I change this number to be 20 he will get the ability again until he reach 20 registered new user then he will be not able to add more

    thanks

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @aymanibrahim77

    Please create a new topic.

    Regards,

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @makmerghen

    Please try this code snippet:

    // Add current logged-in user as a referer
    add_action( 'um_registration_complete', 'um_110821_user_referral' ,1 );
    function um_110821_user_referral( $user_id ){
        $referer_id = get_current_user_id();
        update_user_meta( $user_id, "um_user_referral", $referer_id );
    }
    
    // Validate registration limit
    add_action("um_submit_form_register","um_110821_validate_registration_limit", 1 );
    function um_110821_validate_registration_limit( $post_form ){
      
        //if(  isset( $post_form['user_email'] ) && ! empty( $post_form['user_email'] ) ){
            
            $users = count( get_users(
                    array(
                    'meta_key' => "um_user_referral",
                    'meta_value' => get_current_user_id(),
                    "fields" => "ids"
                    )
                )
            );
    	
    	    if( UM()->form()->errors['user_email'] === "You must provide your email" ){
               unset( UM()->form()->errors['user_email'] );
    		}
            
            if( "membership30" == um_user("role") ){
               if( $users > 30 ){
                UM()->form()->add_error('user_email', __( 'You are not allowed to add more users', 'ultimate-member' ) );
               }
           }elseif( "membership50" == um_user("role") ){
               if( $users > 50 ){
                UM()->form()->add_error('user_email', __( 'You are not allowed to add more users', 'ultimate-member' ) );
               }
           }elseif( "membership100" == um_user("role") ){
               if( $users > 100 ){
                UM()->form()->add_error('user_email', __( 'You are not allowed to add more users', 'ultimate-member' ) );
               }
           }elseif( "administrator" == um_user("role") ){
                 UM()->form()->add_error('user_email', __( 'You are not allowed to add more users', 'ultimate-member' ) );
           }else{
                // no limit
           }
        //}  
            if( empty( UM()->form()->errors ) ){
                unset( UM()->form()->errors );
            }
    
    }

    I’ve combined the control registration number and create email if no email in UM register form to avoid error.

    Regards,

    Thread Starter makmerghen

    (@makmerghen)

    @champsupertramp thank you very much its working now
    all the best

    Hello @champsupertramp
    I will create new post but please put in consideration that will use the snippets that provided in this post
    best regards

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @makmerghen

    Thanks for letting us know.

    Regards,

Viewing 7 replies - 31 through 37 (of 37 total)
  • The topic ‘control the number of registering new users’ is closed to new replies.