• Resolved miladism65

    (@miladism65)


    Hi friends. please answer me :
    I need a user name generator to randomly generatng usernames with my custom prefix and 6 digits after that (i.e mycustom prefix+random and uniqe and unedditable six digits ) , in sign up page made by um register form. how is this possible?!
    Thanks

    • This topic was modified 3 years, 8 months ago by miladism65.
    • This topic was modified 3 years, 8 months ago by miladism65.
Viewing 7 replies - 1 through 7 (of 7 total)
  • I don’t know but I’d also be interested in such a solution. Hopefully they will answer with some actual information but I have a feeling they’ll just say it’s not doable…

    @miladism65
    @audreyprice

    You can add this code to your child theme functions.php
    and update ‘prefix’ with your preferred prefix text.

    I have tested without having the Username field (meta key: user_login) in the registration form.

    add_filter( 'um_add_user_frontend_submitted', 'my_custom_user_frontend', 10, 1 );
    
    	function my_custom_user_frontend( $args ) {
    
    		if( $args['mode'] == 'register' ) {
    			$prefix = 'prefix';
    			$args['user_login'] = $prefix . rand( 100000, 999999 );
    			while( username_exists( $args['user_login'] )) {
    				$args['user_login'] = $prefix . rand( 100000, 999999 );
    			}
    		}
    		return $args;
    	}
    • This reply was modified 3 years, 8 months ago by missveronica.
    Plugin Contributor Champ Camba

    (@champsupertramp)

    With @missveronicatv’s code snipppet you can also add the previous registered user ID and increment it for the user login:

    add_filter( 'um_add_user_frontend_submitted', 'my_custom_user_frontend', 10, 1 );
     function my_custom_user_frontend( $args ) {
    
    		if( $args['mode'] == 'register' ) {
    			$prefix = 'prefix';
                          $args = array(
                              'role'         => 'author', // authors only
                              'orderby'      => 'registered', // registered date
                              'order'        => 'DESC', // last registered goes first
                              'number'       => 1 // limit to the last one
                         );
    
                          $users = get_users( $args );
    
                          $last_user_registered = $users[0]; // the first user from the list
                            $idx = $last_user_registered->ID++;
    
    			$args['user_login'] = $prefix . rand( 100000, 999999 )."_".$idx;
    			while( username_exists( $args['user_login'] )) {
                                    $idx++
    				$args['user_login'] = $prefix . rand( 100000, 999999 )."_".$idx;
    			}
    		}
    		return $args;
    }

    Regards,

    Thread Starter miladism65

    (@miladism65)

    @audreyprice @missveronicatv
    Thanks dudes, i will try your solutions at my 1st opportunity.hope to work

    Thread Starter miladism65

    (@miladism65)

    @audreyprice audreyprice
    Hi my friend.is this possible for you to
    try replies and tell me the result by mentioning me here?! Im a little busy these days??

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @miladism65

    Is the solution above resolves the issue on your end? You can contact each other through email for the custom work and not on this topic.

    I’m closing this thread now.

    Regards,

    Thread Starter miladism65

    (@miladism65)

    @missveronicatv I just tried the code you gave. Thank you very much. It really worked! Thank you very much for your answer.

    • This reply was modified 3 years, 7 months ago by miladism65.
    • This reply was modified 3 years, 7 months ago by miladism65.
Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Username generator for new sign up in u. M?!’ is closed to new replies.