From bc0a6018897607f94cc4a4a175047d9367784ccc Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Sun, 18 Sep 2016 11:41:53 +0000 Subject: [PATCH] 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 git-svn-id: https://develop.svn.wordpress.org/trunk@38619 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/install.php | 16 +++++++++++++++- src/wp-includes/default-constants.php | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/wp-admin/install.php b/src/wp-admin/install.php index 2403982046..80b7fbf1f5 100644 --- a/src/wp-admin/install.php +++ b/src/wp-admin/install.php @@ -330,7 +330,6 @@ switch($step) { $scripts_to_print[] = 'user-profile'; - display_header(); // Fill in the data we gathered $weblog_title = isset( $_POST['weblog_title'] ) ? trim( wp_unslash( $_POST['weblog_title'] ) ) : ''; $user_name = isset($_POST['user_name']) ? trim( wp_unslash( $_POST['user_name'] ) ) : ''; @@ -343,21 +342,26 @@ switch($step) { $error = false; if ( empty( $user_name ) ) { // TODO: poka-yoke + display_header(); display_setup_form( __( 'Please provide a valid username.' ) ); $error = true; } elseif ( $user_name != sanitize_user( $user_name, true ) ) { + display_header(); display_setup_form( __( 'The username you provided has invalid characters.' ) ); $error = true; } elseif ( $admin_password != $admin_password_check ) { // TODO: poka-yoke + display_header(); display_setup_form( __( 'Your passwords do not match. Please try again.' ) ); $error = true; } elseif ( empty( $admin_email ) ) { // TODO: poka-yoke + display_header(); display_setup_form( __( 'You must provide an email address.' ) ); $error = true; } elseif ( ! is_email( $admin_email ) ) { // TODO: poka-yoke + display_header(); display_setup_form( __( 'Sorry, that isn’t a valid email address. Email addresses look like username@example.com.' ) ); $error = true; } @@ -365,6 +369,16 @@ switch($step) { if ( $error === false ) { $wpdb->show_errors(); $result = wp_install( $weblog_title, $user_name, $admin_email, $public, '', wp_slash( $admin_password ), $loaded_language ); + + // Log the user in and send them to wp-admin: + if ( ! headers_sent() ) { + wp_set_auth_cookie( $result['user_id'], true, is_ssl() ); + wp_redirect( admin_url() ); + exit; + } + + // If headers have already been sent, fall back to a "Success!" message: + display_header(); ?>

diff --git a/src/wp-includes/default-constants.php b/src/wp-includes/default-constants.php index 2aa3430ec5..a269144819 100644 --- a/src/wp-includes/default-constants.php +++ b/src/wp-includes/default-constants.php @@ -205,7 +205,7 @@ function wp_cookie_constants() { if ( $siteurl ) define( 'COOKIEHASH', md5( $siteurl ) ); else - define( 'COOKIEHASH', '' ); + define( 'COOKIEHASH', md5( wp_guess_url() ) ); } /**