Make WordPress Core


Ignore:
Timestamp:
09/18/2016 11:41:53 AM (10 years ago)
Author:
johnbillion
Message:

Upgrade/Install: Automatically log users in after installation.

This change means that after entering their site's settings upon installation, users are immediately logged in and redirected to the admin dashboard, instead of being presented with the 'Success!' screen and then being asked to log in. This reduces friction and reduces the number of steps for installation.

Fixes #34084

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/install.php

    r38470 r38619  
    331331                $scripts_to_print[] = 'user-profile';
    332332
    333                 display_header();
    334333                // Fill in the data we gathered
    335334                $weblog_title = isset( $_POST['weblog_title'] ) ? trim( wp_unslash( $_POST['weblog_title'] ) ) : '';
     
    344343                if ( empty( $user_name ) ) {
    345344                        // TODO: poka-yoke
     345                        display_header();
    346346                        display_setup_form( __( 'Please provide a valid username.' ) );
    347347                        $error = true;
    348348                } elseif ( $user_name != sanitize_user( $user_name, true ) ) {
     349                        display_header();
    349350                        display_setup_form( __( 'The username you provided has invalid characters.' ) );
    350351                        $error = true;
    351352                } elseif ( $admin_password != $admin_password_check ) {
    352353                        // TODO: poka-yoke
     354                        display_header();
    353355                        display_setup_form( __( 'Your passwords do not match. Please try again.' ) );
    354356                        $error = true;
    355357                } elseif ( empty( $admin_email ) ) {
    356358                        // TODO: poka-yoke
     359                        display_header();
    357360                        display_setup_form( __( 'You must provide an email address.' ) );
    358361                        $error = true;
    359362                } elseif ( ! is_email( $admin_email ) ) {
    360363                        // TODO: poka-yoke
     364                        display_header();
    361365                        display_setup_form( __( 'Sorry, that isn&#8217;t a valid email address. Email addresses look like <code>username@example.com</code>.' ) );
    362366                        $error = true;
     
    366370                        $wpdb->show_errors();
    367371                        $result = wp_install( $weblog_title, $user_name, $admin_email, $public, '', wp_slash( $admin_password ), $loaded_language );
     372
     373                        // Log the user in and send them to wp-admin:
     374                        if ( ! headers_sent() ) {
     375                                wp_set_auth_cookie( $result['user_id'], true, is_ssl() );
     376                                wp_redirect( admin_url() );
     377                                exit;
     378                        }
     379
     380                        // If headers have already been sent, fall back to a "Success!" message:
     381                        display_header();
    368382?>
    369383
Note: See TracChangeset for help on using the changeset viewer.