control the number of registering new users
-
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
-
You can try this modified code:
// 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( "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( "disabled_membership" == um_user("role") ){ UM()->form()->add_error('user_email', __( 'You are not allowed to add more users', 'ultimate-member' ) ); }else{ // no limit } } }
- This reply was modified 3 years ago by missveronica.
Hi @missveronicatv @champsupertramp thank you the helping
I tried the modified code and code snippets plugin accept it without error but it didn’t work in the next test
I changed role disabled_membership to be administrator and then I tried to register new user and the result was that no limitation happened and the new user was created normally
regards- This reply was modified 3 years ago by makmerghen.
its existed here in the previous message by @missveronicatv
I will copy it here// 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( "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( "disabled_membership" == um_user("role") ){ UM()->form()->add_error('user_email', __( 'You are not allowed to add more users', 'ultimate-member' ) ); }else{ // no limit } } }
regards
Hi @makmerghen
Did you change this part?
from:
elseif( "disabled_membership" == um_user("role") ){ UM()->form()->add_error('user_email', __( 'You are not allowed to add more users', 'ultimate-member' ) ); }
to:
elseif( "administrator" == um_user("role") ){ UM()->form()->add_error('user_email', __( 'You are not allowed to add more users', 'ultimate-member' ) ); }
Regards,
yes I did
Hi @makmerghen
With this code, it should show the error when an administrator tries to Register a new account:
elseif( "administrator" == um_user("role") ){ UM()->form()->add_error('user_email', __( 'You are not allowed to add more users', 'ultimate-member' ) ); }
Are you using an administrator account to test this? How many roles are assigned to your test admin account?
Regards,
I found where is the issue but don’t know how to fix please help
when doing the registration by fill username and email address with data I got the error and me as admin didn’t be able to create new user
but
when I fill only the username and left email empty and continue registration at this case the registration didn’t stopped and the new user was createdplease note that I am using code you provide me to fill email field automatically with dummy email in case it was left empty
add_action("um_submit_form_register","um_111121_email_field_optional", 1 ); function um_111121_email_field_optional(){ if( isset( UM()->form()->errors['user_email'] ) && UM()->form()->errors['user_email'] == "You must provide your email" ){ if( count( UM()->form()->errors ) == 1 ){ unset( UM()->form()->errors ); } unset( UM()->form()->errors['user_email'] ); } }
so please advise
Hi @makmerghen
Please try this code snippet:
add_action("um_submit_form_register","um_111121_email_field_optional", 1 ); function um_111121_email_field_optional(){ if( isset( UM()->form()->errors['user_email'] ) && UM()->form()->errors['user_email'] == "You must provide your email" ){ if( empty( UM()->form()->errors ) ){ unset( UM()->form()->errors ); } unset( UM()->form()->errors['user_email'] ); } }
Regards,
dear @champsupertramp thank for you reply
after using this code it didn’t create the user
but
in stead of did the normal behavior of refreshing the page with leaving the inserted data in the field of the form as it with error message You are not allowed to add more users
I found that
page refreshed and form is cleared as if the registration is doneso please advise
best regardsHi @makmerghen
Please try this one. Let me know if you’re still encountering issues:
add_action("um_submit_form_register","um_111121_email_field_optional", 1 ); function um_111121_email_field_optional(){ if( isset( UM()->form()->errors['user_email'] ) && UM()->form()->errors['user_email'] == "You must provide your email" ){ unset( UM()->form()->errors['user_email'] ); if( empty( UM()->form()->errors ) ){ unset( UM()->form()->errors ); } } }
Regards,
dear @champsupertramp thank for you reply
after using this code got extra issue
1- it create the new user in stead of suspend user from create the new user
2- in stead of did the normal behavior of refreshing the page with leaving the inserted data in the field of the form as it with error message You are not allowed to add more users
I found that
page refreshed and form is cleared as if the registration is doneso please advise
best regardsHi @makmerghen
Are you able to provide a video clip showing the issue? I couldn’t reproduce the issue on my end.
Regards,
Dear @champsupertramp
https://www.mediafire.com/file/860jn94syokxspe/video2218681415.mp4/fileyou will find in the video the first case of the registration is the right one and the second that has the issue and should be like the first one
best regardsHi @makmerghen
Unfortuantely, I still couldn’t reproduce the issue on my end. Could you please provide the latest custom codes you have for this feature and I will try it on my end?
Regards,
- The topic ‘control the number of registering new users’ is closed to new replies.