WordPress.org

Make WordPress Core

Ticket #8647: setup-config-php-secure-keys.diff

File setup-config-php-secure-keys.diff, 2.4 KB (added by sivel, 7 years ago)
  • wp-admin/setup-config.php

     
    2929require_once('../wp-includes/compat.php'); 
    3030require_once('../wp-includes/functions.php'); 
    3131require_once('../wp-includes/classes.php'); 
     32require_once('../wp-includes/http.php'); 
     33require_once('../wp-includes/plugin.php'); 
     34require_once('../wp-includes/l10n.php'); 
    3235 
    3336if (!file_exists('../wp-config-sample.php')) 
    3437        wp_die('Sorry, I need a wp-config-sample.php file to work from. Please re-upload this file from your WordPress installation.'); 
     
    155158        if ( !empty($wpdb->error) ) 
    156159                wp_die($wpdb->error->get_error_message()); 
    157160 
     161        $response = wp_remote_get('https://api.wordpress.org/secret-key/1.1/'); 
     162        if ( !is_wp_error($response) ) 
     163                list($auth, $secure_auth, $logged_in, $nonce) = preg_split('/\n/',$response['body']); 
     164 
    158165        $handle = fopen('../wp-config.php', 'w'); 
    159166 
    160167        foreach ($configFile as $line_num => $line) { 
     
    171178                        case "define('DB_HOST'": 
    172179                                fwrite($handle, str_replace("localhost", $dbhost, $line)); 
    173180                                break; 
     181                        case "define('AUTH_KEY": 
     182                                is_wp_error($response) ? fwrite($handle, $line) : fwrite($handle, "$auth\r\n"); 
     183                                break; 
     184                        case "define('SECURE_A": 
     185                                is_wp_error($response) ? fwrite($handle, $line) : fwrite($handle, "$secure_auth\r\n"); 
     186                                break; 
     187                        case "define('LOGGED_I": 
     188                                is_wp_error($response) ? fwrite($handle, $line) : fwrite($handle, "$logged_in\r\n"); 
     189                                break; 
     190                        case "define('NONCE_KE": 
     191                                is_wp_error($response) ? fwrite($handle, $line) : fwrite($handle, "$nonce\r\n"); 
     192                                break; 
    174193                        case '$table_prefix  =': 
    175194                                fwrite($handle, str_replace('wp_', $prefix, $line)); 
    176195                                break; 
     
    182201        chmod('../wp-config.php', 0666); 
    183202 
    184203        display_header(); 
     204 
     205if ( is_wp_error($response) ) :  
    185206?> 
     207<p>Unique authentication keys were unable to be configured.  For added security please configure the 'Authentication Unique Keys' section  manually in your <code>wp-config.php</code> file after the install has finished.</p> 
     208<?php endif; ?> 
     209 
    186210<p>All right sparky! You've made it through this part of the installation. WordPress can now communicate with your database. If you are ready, time now to&hellip;</p> 
    187211 
    188212<p class="step"><a href="install.php" class="button">Run the install</a></p> 
     213 
    189214<?php 
    190215        break; 
    191216}