Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

thanks for reading.

I'd like to take total control of how the registrations are done on my new site.

I want the new user to write his own password, and fill different fields. Display my own errors and messages, etc..

Can you point me in the right direction? All I'm finding are plugins that use short codes, that aren't even close enough to what I'm trying to achieve.

share|improve this question
add comment

2 Answers

Copy this function and modify it as per your needs.

function custom_register_new_user( $user_login, $user_email ) {
    $errors = new WP_Error();

    $sanitized_user_login = sanitize_user( $user_login );
    $user_email = apply_filters( 'user_registration_email', $user_email );

    // Check the username
    if ( $sanitized_user_login == '' ) {
        $errors->add( 'empty_username', __( '<strong>ERROR</strong>: Please enter a username.' ) );
    } elseif ( ! validate_username( $user_login ) ) {
        $errors->add( 'invalid_username', __( '<strong>ERROR</strong>: This username is invalid because it uses illegal characters. Please enter a valid username.' ) );
        $sanitized_user_login = '';
    } elseif ( username_exists( $sanitized_user_login ) ) {
        $errors->add( 'username_exists', __( '<strong>ERROR</strong>: This username is already registered. Please choose another one.' ) );
    }

    // Check the e-mail address
    if ( $user_email == '' ) {
        $errors->add( 'empty_email', __( '<strong>ERROR</strong>: Please type your e-mail address.' ) );
    } elseif ( ! is_email( $user_email ) ) {
        $errors->add( 'invalid_email', __( '<strong>ERROR</strong>: The email address isn&#8217;t correct.' ) );
        $user_email = '';
    } elseif ( email_exists( $user_email ) ) {
        $errors->add( 'email_exists', __( '<strong>ERROR</strong>: This email is already registered, please choose another one.' ) );
    }

    do_action( 'register_post', $sanitized_user_login, $user_email, $errors );

    $errors = apply_filters( 'registration_errors', $errors, $sanitized_user_login, $user_email );

    if ( $errors->get_error_code() )
        return $errors;

    $user_pass = wp_generate_password( 12, false);
    $user_id = wp_create_user( $sanitized_user_login, $user_pass, $user_email );
    if ( ! $user_id ) {
        $errors->add( 'registerfail', sprintf( __( '<strong>ERROR</strong>: Couldn&#8217;t register you... please contact the <a href="mailto:%s">webmaster</a> !' ), get_option( 'admin_email' ) ) );
        return $errors;
    }

    update_user_option( $user_id, 'default_password_nag', true, true ); //Set up the Password change nag.

    wp_new_user_notification( $user_id, $user_pass );

    return $user_id;
}

Read this page to display your own error messages.

Related questions:

Front-end Register Form

How to display Wordpress User Registration Form in front-end of the website?

share|improve this answer
    
I came across this tutorial: codex.wordpress.org/Customizing_the_Registration_Form It's being really helpful too –  sanchy Feb 18 '13 at 23:15
    
Thank you so much for pointing me to this awesome function! I managed to do everything that I was expecting to do. –  sanchy Feb 19 '13 at 2:38
1  
You are welcome mate... –  Giri Feb 19 '13 at 6:28
add comment
up vote 1 down vote accepted

Using Giri's function and information from this link http://codex.wordpress.org/Customizing_the_Registration_Form

I managed to end up with the following function to create a Custom Registration for my WordPress site. The user chooses his own password, also specifies Name and Last Names. Username equals e-mail, since I don't want usernames.

In a separate file (where the register form is) check if the form has been submited and call this function with all the parameters required. Then handle errors and succesful submits.

Inside functions.php file I added the following:

function custom_register_new_user( $user_login, $user_email, $user_apellidos, $user_nombre, $user_password, $user_repassword ) {
    $errors = new WP_Error();

    $sanitized_user_login = sanitize_user( $user_login );
    $user_email = apply_filters( 'user_registration_email', $user_email );
    $user_nombre = escape($user_nombre);
    $user_password = escape($user_password);
    $user_repassword = escape($user_repassword);

    // Check the username
    if ( $sanitized_user_login == '' ) {
        $errors->add( 'empty_username', __( 'Por favor escrib&iacute; un <strong>E-mail</strong>' ) );
    } elseif ( ! validate_username( $user_login ) ) {
        $errors->add( 'invalid_username', __( 'El <strong>e-mail</strong> es incorrecto' ) );
        $sanitized_user_login = '';
    } elseif ( username_exists( $sanitized_user_login ) ) {
        $errors->add( 'username_exists', __( 'Este <strong>e-mail</strong> ya est&aacute; registrado, eleg&iacute; otro' ) );
    }

    // Check the e-mail address
    if ( $user_email == '' ) {
        $errors->add( 'empty_email', 'Por favor escrib&iacute; un <strong>E-mail</strong>' );
    } elseif ( ! is_email( $user_email ) ) {
        $errors->add( 'invalid_email', 'El <strong>e-mail</strong> es incorrecto' );
        $user_email = '';
    } elseif ( email_exists( $user_email ) ) {
        $errors->add( 'email_exists', 'Este <strong>e-mail</strong> ya est&aacute; registrado, eleg&iacute; otro' );
    }

    // Check the apellidos
    if ( $user_apellidos == '') {
        $errors->add( 'apellidos_error', 'Por favor escrib&iacute; tus <strong>Apellidos</strong>' );
    }

    // Check the nombre
    if ( $user_nombre == '') {
        $errors->add( 'nombre_error', 'Por favor escrib&iacute; tu <strong>Nombre</strong>' );
    }

    // Check the password
    if( $user_password == '' ) {
        $errors->add ( 'password_error', 'Por favor escrib&iacute; una <strong>Contrase&ntilde;a</strong>' );   
    }
    elseif( !(ctype_alnum($user_password)) ) {
        $errors->add ( 'password_error', '<strong>Contrase&ntilde;a</strong> no valida. Us&aacute; solo letras y n&uacute;meros' ); 
    }
    elseif( $user_repassword == '' || $user_password != $user_password ) {
        $errors->add ( 'password_error', 'Las <strong>Constrase&ntilde;as</strong> no coinciden</strong>' );
    }



    do_action( 'register_post', $sanitized_user_login, $user_email, $errors );

    $errors = apply_filters( 'registration_errors', $errors, $sanitized_user_login, $user_email, $user_nombre, $user_apellidos, $user_password );

    if ( $errors->get_error_code() )
        return $errors;

    $user_pass = $user_password;
    $user_id = wp_create_user( $sanitized_user_login, $user_pass, $user_email );
    if ( ! $user_id ) {
        $errors->add( 'registerfail', sprintf( __( '<strong>ERROR</strong>: Couldn&#8217;t register you... please contact the <a href="mailto:%s">webmaster</a> !' ), get_option( 'admin_email' ) ) );
        return $errors;
    }

    update_user_meta($user_id, 'first_name', $user_nombre );
    update_user_meta($user_id, 'last_name', $user_apellidos );

    /* wp_new_user_notification( $user_id, $user_pass ); */

    return $user_id;
}

To handle errors, check if the function's Return is_wp_error. Else continue with a welcome message or something.

$return = custom_register_new_user($_POST['email'], $_POST['email'], $_POST['apellidos'], $_POST['nombre'], $_POST['password'], $_POST['repassword']);

                    if( is_wp_error($return) ) {

                        $errores = $return->errors;
                        if( count($errores) > 0 ) {

                            if( $errores['apellidos_error'] )
                                $error_apellidos = $errores['apellidos_error'][0];

                            if( $errores['nombre_error'] )
                                $error_nombre = $errores['nombre_error'][0];

                                ....
                                etc
                                .... 

Also, added "Header" redirect at the deafult registration form, so users will always land on my custom form. Same for Login and Forgotten password

share|improve this answer
    
To manage your custom Login Form you can use this function codex.wordpress.org/Function_Reference/wp_signon –  sanchy Feb 19 '13 at 12:47
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.