author | ymh <ymh.work@gmail.com> |
Mon, 14 Oct 2019 18:28:13 +0200 | |
changeset 9 | 177826044cd9 |
parent 7 | cf61fcea0001 |
child 16 | a86126ab1dd4 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* Retrieves and creates the wp-config.php file. |
|
4 |
* |
|
5 |
* The permissions for the base directory must allow for writing files in order |
|
6 |
* for the wp-config.php to be created using this page. |
|
7 |
* |
|
8 |
* @package WordPress |
|
9 |
* @subpackage Administration |
|
10 |
*/ |
|
11 |
||
12 |
/** |
|
13 |
* We are installing. |
|
14 |
*/ |
|
9 | 15 |
define( 'WP_INSTALLING', true ); |
0 | 16 |
|
17 |
/** |
|
18 |
* We are blissfully unaware of anything. |
|
19 |
*/ |
|
9 | 20 |
define( 'WP_SETUP_CONFIG', true ); |
0 | 21 |
|
22 |
/** |
|
23 |
* Disable error reporting |
|
24 |
* |
|
5 | 25 |
* Set this to error_reporting( -1 ) for debugging |
0 | 26 |
*/ |
9 | 27 |
error_reporting( 0 ); |
0 | 28 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
29 |
if ( ! defined( 'ABSPATH' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
30 |
define( 'ABSPATH', dirname( dirname( __FILE__ ) ) . '/' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
31 |
} |
0 | 32 |
|
5 | 33 |
require( ABSPATH . 'wp-settings.php' ); |
0 | 34 |
|
5 | 35 |
/** Load WordPress Administration Upgrade API */ |
36 |
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
0 | 37 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
38 |
/** Load WordPress Translation Installation API */ |
5 | 39 |
require_once( ABSPATH . 'wp-admin/includes/translation-install.php' ); |
0 | 40 |
|
5 | 41 |
nocache_headers(); |
0 | 42 |
|
43 |
// Support wp-config-sample.php one level up, for the develop repo. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
44 |
if ( file_exists( ABSPATH . 'wp-config-sample.php' ) ) { |
0 | 45 |
$config_file = file( ABSPATH . 'wp-config-sample.php' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
46 |
} elseif ( file_exists( dirname( ABSPATH ) . '/wp-config-sample.php' ) ) { |
0 | 47 |
$config_file = file( dirname( ABSPATH ) . '/wp-config-sample.php' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
48 |
} else { |
9 | 49 |
wp_die( |
50 |
sprintf( |
|
51 |
/* translators: %s: wp-config-sample.php */ |
|
52 |
__( 'Sorry, I need a %s file to work from. Please re-upload this file to your WordPress installation.' ), |
|
53 |
'<code>wp-config-sample.php</code>' |
|
54 |
) |
|
55 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
56 |
} |
0 | 57 |
|
58 |
// Check if wp-config.php has been created |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
59 |
if ( file_exists( ABSPATH . 'wp-config.php' ) ) { |
9 | 60 |
wp_die( |
61 |
'<p>' . sprintf( |
|
62 |
/* translators: 1: wp-config.php, 2: install.php */ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
63 |
__( 'The file %1$s already exists. If you need to reset any of the configuration items in this file, please delete it first. You may try <a href="%2$s">installing now</a>.' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
64 |
'<code>wp-config.php</code>', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
65 |
'install.php' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
66 |
) . '</p>' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
67 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
68 |
} |
0 | 69 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
70 |
// Check if wp-config.php exists above the root directory but is not part of another installation |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
71 |
if ( @file_exists( ABSPATH . '../wp-config.php' ) && ! @file_exists( ABSPATH . '../wp-settings.php' ) ) { |
9 | 72 |
wp_die( |
73 |
'<p>' . sprintf( |
|
74 |
/* translators: 1: wp-config.php, 2: install.php */ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
75 |
__( 'The file %1$s already exists one level above your WordPress installation. If you need to reset any of the configuration items in this file, please delete it first. You may try <a href="%2$s">installing now</a>.' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
76 |
'<code>wp-config.php</code>', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
77 |
'install.php' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
78 |
) . '</p>' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
79 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
80 |
} |
0 | 81 |
|
5 | 82 |
$step = isset( $_GET['step'] ) ? (int) $_GET['step'] : -1; |
0 | 83 |
|
84 |
/** |
|
85 |
* Display setup wp-config.php file header. |
|
86 |
* |
|
87 |
* @ignore |
|
88 |
* @since 2.3.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
89 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
90 |
* @global string $wp_local_package |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
91 |
* @global WP_Locale $wp_locale |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
92 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
93 |
* @param string|array $body_classes |
0 | 94 |
*/ |
5 | 95 |
function setup_config_display_header( $body_classes = array() ) { |
9 | 96 |
$body_classes = (array) $body_classes; |
5 | 97 |
$body_classes[] = 'wp-core-ui'; |
9 | 98 |
$dir_attr = ''; |
5 | 99 |
if ( is_rtl() ) { |
100 |
$body_classes[] = 'rtl'; |
|
9 | 101 |
$dir_attr = ' dir="rtl"'; |
5 | 102 |
} |
0 | 103 |
|
104 |
header( 'Content-Type: text/html; charset=utf-8' ); |
|
9 | 105 |
?> |
0 | 106 |
<!DOCTYPE html> |
9 | 107 |
<html xmlns="http://www.w3.org/1999/xhtml"<?php echo $dir_attr; ?>> |
0 | 108 |
<head> |
5 | 109 |
<meta name="viewport" content="width=device-width" /> |
110 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
111 |
<meta name="robots" content="noindex,nofollow" /> |
5 | 112 |
<title><?php _e( 'WordPress › Setup Configuration File' ); ?></title> |
113 |
<?php wp_admin_css( 'install', true ); ?> |
|
0 | 114 |
</head> |
5 | 115 |
<body class="<?php echo implode( ' ', $body_classes ); ?>"> |
9 | 116 |
<p id="logo"><a href="<?php echo esc_url( __( 'https://wordpress.org/' ) ); ?>"><?php _e( 'WordPress' ); ?></a></p> |
117 |
<?php |
|
0 | 118 |
} // end function setup_config_display_header(); |
119 |
||
5 | 120 |
$language = ''; |
121 |
if ( ! empty( $_REQUEST['language'] ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
122 |
$language = preg_replace( '/[^a-zA-Z0-9_]/', '', $_REQUEST['language'] ); |
5 | 123 |
} elseif ( isset( $GLOBALS['wp_local_package'] ) ) { |
124 |
$language = $GLOBALS['wp_local_package']; |
|
125 |
} |
|
126 |
||
9 | 127 |
switch ( $step ) { |
5 | 128 |
case -1: |
129 |
if ( wp_can_install_language_pack() && empty( $language ) && ( $languages = wp_get_available_translations() ) ) { |
|
130 |
setup_config_display_header( 'language-chooser' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
131 |
echo '<h1 class="screen-reader-text">Select a default language</h1>'; |
5 | 132 |
echo '<form id="setup" method="post" action="?step=0">'; |
133 |
wp_install_language_form( $languages ); |
|
134 |
echo '</form>'; |
|
135 |
break; |
|
136 |
} |
|
137 |
||
138 |
// Deliberately fall through if we can't reach the translations API. |
|
139 |
||
0 | 140 |
case 0: |
5 | 141 |
if ( ! empty( $language ) ) { |
142 |
$loaded_language = wp_download_language_pack( $language ); |
|
143 |
if ( $loaded_language ) { |
|
144 |
load_default_textdomain( $loaded_language ); |
|
145 |
$GLOBALS['wp_locale'] = new WP_Locale(); |
|
146 |
} |
|
147 |
} |
|
148 |
||
0 | 149 |
setup_config_display_header(); |
5 | 150 |
$step_1 = 'setup-config.php?step=1'; |
151 |
if ( isset( $_REQUEST['noapi'] ) ) { |
|
152 |
$step_1 .= '&noapi'; |
|
153 |
} |
|
154 |
if ( ! empty( $loaded_language ) ) { |
|
155 |
$step_1 .= '&language=' . $loaded_language; |
|
156 |
} |
|
9 | 157 |
?> |
158 |
<h1 class="screen-reader-text"><?php _e( 'Before getting started' ); ?></h1> |
|
159 |
<p><?php _e( 'Welcome to WordPress. Before getting started, we need some information on the database. You will need to know the following items before proceeding.' ); ?></p> |
|
0 | 160 |
<ol> |
161 |
<li><?php _e( 'Database name' ); ?></li> |
|
162 |
<li><?php _e( 'Database username' ); ?></li> |
|
163 |
<li><?php _e( 'Database password' ); ?></li> |
|
164 |
<li><?php _e( 'Database host' ); ?></li> |
|
165 |
<li><?php _e( 'Table prefix (if you want to run more than one WordPress in a single database)' ); ?></li> |
|
166 |
</ol> |
|
9 | 167 |
<p> |
168 |
<?php |
|
169 |
/* translators: %s: wp-config.php */ |
|
170 |
printf( |
|
171 |
__( 'We’re going to use this information to create a %s file.' ), |
|
172 |
'<code>wp-config.php</code>' |
|
173 |
); |
|
174 |
?> |
|
175 |
<strong> |
|
176 |
<?php |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
177 |
/* translators: 1: wp-config-sample.php, 2: wp-config.php */ |
9 | 178 |
printf( |
179 |
__( 'If for any reason this automatic file creation doesn’t work, don’t worry. All this does is fill in the database information to a configuration file. You may also simply open %1$s in a text editor, fill in your information, and save it as %2$s.' ), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
180 |
'<code>wp-config-sample.php</code>', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
181 |
'<code>wp-config.php</code>' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
182 |
); |
9 | 183 |
?> |
184 |
</strong> |
|
185 |
<?php |
|
186 |
/* translators: %s: Codex URL */ |
|
187 |
printf( |
|
188 |
__( 'Need more help? <a href="%s">We got it</a>.' ), |
|
189 |
__( 'https://codex.wordpress.org/Editing_wp-config.php' ) |
|
190 |
); |
|
191 |
?> |
|
192 |
</p> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
193 |
<p><?php _e( 'In all likelihood, these items were supplied to you by your Web Host. If you don’t have this information, then you will need to contact them before you can continue. If you’re all ready…' ); ?></p> |
0 | 194 |
|
5 | 195 |
<p class="step"><a href="<?php echo $step_1; ?>" class="button button-large"><?php _e( 'Let’s go!' ); ?></a></p> |
9 | 196 |
<?php |
197 |
break; |
|
0 | 198 |
|
199 |
case 1: |
|
5 | 200 |
load_default_textdomain( $language ); |
201 |
$GLOBALS['wp_locale'] = new WP_Locale(); |
|
202 |
||
0 | 203 |
setup_config_display_header(); |
9 | 204 |
|
205 |
$autofocus = wp_is_mobile() ? '' : ' autofocus'; |
|
206 |
?> |
|
207 |
<h1 class="screen-reader-text"><?php _e( 'Set up your database connection' ); ?></h1> |
|
0 | 208 |
<form method="post" action="setup-config.php?step=2"> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
209 |
<p><?php _e( 'Below you should enter your database connection details. If you’re not sure about these, contact your host.' ); ?></p> |
9 | 210 |
<table class="form-table" role="presentation"> |
0 | 211 |
<tr> |
212 |
<th scope="row"><label for="dbname"><?php _e( 'Database Name' ); ?></label></th> |
|
9 | 213 |
<td><input name="dbname" id="dbname" type="text" aria-describedby="dbname-desc" size="25" value="wordpress"<?php echo $autofocus; ?>/></td> |
214 |
<td id="dbname-desc"><?php _e( 'The name of the database you want to use with WordPress.' ); ?></td> |
|
0 | 215 |
</tr> |
216 |
<tr> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
217 |
<th scope="row"><label for="uname"><?php _e( 'Username' ); ?></label></th> |
9 | 218 |
<td><input name="uname" id="uname" type="text" aria-describedby="uname-desc" size="25" value="<?php echo htmlspecialchars( _x( 'username', 'example username' ), ENT_QUOTES ); ?>" /></td> |
219 |
<td id="uname-desc"><?php _e( 'Your database username.' ); ?></td> |
|
0 | 220 |
</tr> |
221 |
<tr> |
|
222 |
<th scope="row"><label for="pwd"><?php _e( 'Password' ); ?></label></th> |
|
9 | 223 |
<td><input name="pwd" id="pwd" type="text" aria-describedby="pwd-desc" size="25" value="<?php echo htmlspecialchars( _x( 'password', 'example password' ), ENT_QUOTES ); ?>" autocomplete="off" /></td> |
224 |
<td id="pwd-desc"><?php _e( 'Your database password.' ); ?></td> |
|
0 | 225 |
</tr> |
226 |
<tr> |
|
227 |
<th scope="row"><label for="dbhost"><?php _e( 'Database Host' ); ?></label></th> |
|
9 | 228 |
<td><input name="dbhost" id="dbhost" type="text" aria-describedby="dbhost-desc" size="25" value="localhost" /></td> |
229 |
<td id="dbhost-desc"> |
|
230 |
<?php |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
231 |
/* translators: %s: localhost */ |
9 | 232 |
printf( __( 'You should be able to get this info from your web host, if %s doesn’t work.' ), '<code>localhost</code>' ); |
233 |
?> |
|
234 |
</td> |
|
0 | 235 |
</tr> |
236 |
<tr> |
|
237 |
<th scope="row"><label for="prefix"><?php _e( 'Table Prefix' ); ?></label></th> |
|
9 | 238 |
<td><input name="prefix" id="prefix" type="text" aria-describedby="prefix-desc" value="wp_" size="25" /></td> |
239 |
<td id="prefix-desc"><?php _e( 'If you want to run multiple WordPress installations in a single database, change this.' ); ?></td> |
|
0 | 240 |
</tr> |
241 |
</table> |
|
9 | 242 |
<?php |
243 |
if ( isset( $_GET['noapi'] ) ) { |
|
244 |
?> |
|
245 |
<input name="noapi" type="hidden" value="1" /><?php } ?> |
|
5 | 246 |
<input type="hidden" name="language" value="<?php echo esc_attr( $language ); ?>" /> |
0 | 247 |
<p class="step"><input name="submit" type="submit" value="<?php echo htmlspecialchars( __( 'Submit' ), ENT_QUOTES ); ?>" class="button button-large" /></p> |
248 |
</form> |
|
9 | 249 |
<?php |
250 |
break; |
|
0 | 251 |
|
252 |
case 2: |
|
9 | 253 |
load_default_textdomain( $language ); |
254 |
$GLOBALS['wp_locale'] = new WP_Locale(); |
|
5 | 255 |
|
9 | 256 |
$dbname = trim( wp_unslash( $_POST['dbname'] ) ); |
257 |
$uname = trim( wp_unslash( $_POST['uname'] ) ); |
|
258 |
$pwd = trim( wp_unslash( $_POST['pwd'] ) ); |
|
259 |
$dbhost = trim( wp_unslash( $_POST['dbhost'] ) ); |
|
260 |
$prefix = trim( wp_unslash( $_POST['prefix'] ) ); |
|
5 | 261 |
|
9 | 262 |
$step_1 = 'setup-config.php?step=1'; |
263 |
$install = 'install.php'; |
|
264 |
if ( isset( $_REQUEST['noapi'] ) ) { |
|
265 |
$step_1 .= '&noapi'; |
|
266 |
} |
|
5 | 267 |
|
9 | 268 |
if ( ! empty( $language ) ) { |
269 |
$step_1 .= '&language=' . $language; |
|
270 |
$install .= '?language=' . $language; |
|
271 |
} else { |
|
272 |
$install .= '?language=en_US'; |
|
273 |
} |
|
0 | 274 |
|
9 | 275 |
$tryagain_link = '</p><p class="step"><a href="' . $step_1 . '" onclick="javascript:history.go(-1);return false;" class="button button-large">' . __( 'Try again' ) . '</a>'; |
0 | 276 |
|
9 | 277 |
if ( empty( $prefix ) ) { |
278 |
wp_die( __( '<strong>ERROR</strong>: "Table Prefix" must not be empty.' ) . $tryagain_link ); |
|
279 |
} |
|
0 | 280 |
|
9 | 281 |
// Validate $prefix: it can only contain letters, numbers and underscores. |
282 |
if ( preg_match( '|[^a-z0-9_]|i', $prefix ) ) { |
|
283 |
wp_die( __( '<strong>ERROR</strong>: "Table Prefix" can only contain numbers, letters, and underscores.' ) . $tryagain_link ); |
|
284 |
} |
|
0 | 285 |
|
9 | 286 |
// Test the db connection. |
287 |
/**#@+ |
|
288 |
* |
|
289 |
* @ignore |
|
290 |
*/ |
|
291 |
define( 'DB_NAME', $dbname ); |
|
292 |
define( 'DB_USER', $uname ); |
|
293 |
define( 'DB_PASSWORD', $pwd ); |
|
294 |
define( 'DB_HOST', $dbhost ); |
|
295 |
/**#@-*/ |
|
0 | 296 |
|
9 | 297 |
// Re-construct $wpdb with these new values. |
298 |
unset( $wpdb ); |
|
299 |
require_wp_db(); |
|
300 |
||
301 |
/* |
|
302 |
* The wpdb constructor bails when WP_SETUP_CONFIG is set, so we must |
|
303 |
* fire this manually. We'll fail here if the values are no good. |
|
304 |
*/ |
|
305 |
$wpdb->db_connect(); |
|
0 | 306 |
|
9 | 307 |
if ( ! empty( $wpdb->error ) ) { |
308 |
wp_die( $wpdb->error->get_error_message() . $tryagain_link ); |
|
0 | 309 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
310 |
|
9 | 311 |
$errors = $wpdb->hide_errors(); |
312 |
$wpdb->query( "SELECT $prefix" ); |
|
313 |
$wpdb->show_errors( $errors ); |
|
314 |
if ( ! $wpdb->last_error ) { |
|
315 |
// MySQL was able to parse the prefix as a value, which we don't want. Bail. |
|
316 |
wp_die( __( '<strong>ERROR</strong>: "Table Prefix" is invalid.' ) ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
317 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
318 |
|
9 | 319 |
// Generate keys and salts using secure CSPRNG; fallback to API if enabled; further fallback to original wp_generate_password(). |
320 |
try { |
|
321 |
$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_ []{}<>~`+=,.;:/?|'; |
|
322 |
$max = strlen( $chars ) - 1; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
323 |
for ( $i = 0; $i < 8; $i++ ) { |
9 | 324 |
$key = ''; |
325 |
for ( $j = 0; $j < 64; $j++ ) { |
|
326 |
$key .= substr( $chars, random_int( 0, $max ), 1 ); |
|
327 |
} |
|
328 |
$secret_keys[] = $key; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
329 |
} |
9 | 330 |
} catch ( Exception $ex ) { |
331 |
$no_api = isset( $_POST['noapi'] ); |
|
332 |
||
333 |
if ( ! $no_api ) { |
|
334 |
$secret_keys = wp_remote_get( 'https://api.wordpress.org/secret-key/1.1/salt/' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
335 |
} |
0 | 336 |
|
9 | 337 |
if ( $no_api || is_wp_error( $secret_keys ) ) { |
338 |
$secret_keys = array(); |
|
339 |
for ( $i = 0; $i < 8; $i++ ) { |
|
340 |
$secret_keys[] = wp_generate_password( 64, true, true ); |
|
341 |
} |
|
342 |
} else { |
|
343 |
$secret_keys = explode( "\n", wp_remote_retrieve_body( $secret_keys ) ); |
|
344 |
foreach ( $secret_keys as $k => $v ) { |
|
345 |
$secret_keys[ $k ] = substr( $v, 28, 64 ); |
|
346 |
} |
|
347 |
} |
|
0 | 348 |
} |
349 |
||
9 | 350 |
$key = 0; |
351 |
foreach ( $config_file as $line_num => $line ) { |
|
352 |
if ( '$table_prefix =' == substr( $line, 0, 15 ) ) { |
|
353 |
$config_file[ $line_num ] = '$table_prefix = \'' . addcslashes( $prefix, "\\'" ) . "';\r\n"; |
|
354 |
continue; |
|
355 |
} |
|
0 | 356 |
|
9 | 357 |
if ( ! preg_match( '/^define\(\s*\'([A-Z_]+)\',([ ]+)/', $line, $match ) ) { |
358 |
continue; |
|
359 |
} |
|
360 |
||
361 |
$constant = $match[1]; |
|
362 |
$padding = $match[2]; |
|
0 | 363 |
|
9 | 364 |
switch ( $constant ) { |
365 |
case 'DB_NAME': |
|
366 |
case 'DB_USER': |
|
367 |
case 'DB_PASSWORD': |
|
368 |
case 'DB_HOST': |
|
369 |
$config_file[ $line_num ] = "define( '" . $constant . "'," . $padding . "'" . addcslashes( constant( $constant ), "\\'" ) . "' );\r\n"; |
|
370 |
break; |
|
371 |
case 'DB_CHARSET': |
|
372 |
if ( 'utf8mb4' === $wpdb->charset || ( ! $wpdb->charset && $wpdb->has_cap( 'utf8mb4' ) ) ) { |
|
373 |
$config_file[ $line_num ] = "define( '" . $constant . "'," . $padding . "'utf8mb4' );\r\n"; |
|
374 |
} |
|
375 |
break; |
|
376 |
case 'AUTH_KEY': |
|
377 |
case 'SECURE_AUTH_KEY': |
|
378 |
case 'LOGGED_IN_KEY': |
|
379 |
case 'NONCE_KEY': |
|
380 |
case 'AUTH_SALT': |
|
381 |
case 'SECURE_AUTH_SALT': |
|
382 |
case 'LOGGED_IN_SALT': |
|
383 |
case 'NONCE_SALT': |
|
384 |
$config_file[ $line_num ] = "define( '" . $constant . "'," . $padding . "'" . $secret_keys[ $key++ ] . "' );\r\n"; |
|
385 |
break; |
|
386 |
} |
|
0 | 387 |
} |
9 | 388 |
unset( $line ); |
0 | 389 |
|
9 | 390 |
if ( ! is_writable( ABSPATH ) ) : |
391 |
setup_config_display_header(); |
|
392 |
?> |
|
393 |
<p> |
|
394 |
<?php |
|
395 |
/* translators: %s: wp-config.php */ |
|
396 |
printf( __( 'Sorry, but I can’t write the %s file.' ), '<code>wp-config.php</code>' ); |
|
397 |
?> |
|
398 |
</p> |
|
399 |
<p> |
|
400 |
<?php |
|
401 |
/* translators: %s: wp-config.php */ |
|
402 |
printf( __( 'You can create the %s file manually and paste the following text into it.' ), '<code>wp-config.php</code>' ); |
|
403 |
||
404 |
$config_text = ''; |
|
405 |
||
406 |
foreach ( $config_file as $line ) { |
|
407 |
$config_text .= htmlentities( $line, ENT_COMPAT, 'UTF-8' ); |
|
408 |
} |
|
409 |
?> |
|
410 |
</p> |
|
411 |
<textarea id="wp-config" cols="98" rows="15" class="code" readonly="readonly"><?php echo $config_text; ?></textarea> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
412 |
<p><?php _e( 'After you’ve done that, click “Run the installation.”' ); ?></p> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
413 |
<p class="step"><a href="<?php echo $install; ?>" class="button button-large"><?php _e( 'Run the installation' ); ?></a></p> |
0 | 414 |
<script> |
415 |
(function(){ |
|
5 | 416 |
if ( ! /iPad|iPod|iPhone/.test( navigator.userAgent ) ) { |
417 |
var el = document.getElementById('wp-config'); |
|
418 |
el.focus(); |
|
419 |
el.select(); |
|
420 |
} |
|
0 | 421 |
})(); |
422 |
</script> |
|
9 | 423 |
<?php |
0 | 424 |
else : |
5 | 425 |
/* |
426 |
* If this file doesn't exist, then we are using the wp-config-sample.php |
|
427 |
* file one level up, which is for the develop repo. |
|
428 |
*/ |
|
9 | 429 |
if ( file_exists( ABSPATH . 'wp-config-sample.php' ) ) { |
0 | 430 |
$path_to_wp_config = ABSPATH . 'wp-config.php'; |
9 | 431 |
} else { |
0 | 432 |
$path_to_wp_config = dirname( ABSPATH ) . '/wp-config.php'; |
9 | 433 |
} |
0 | 434 |
|
435 |
$handle = fopen( $path_to_wp_config, 'w' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
436 |
foreach ( $config_file as $line ) { |
0 | 437 |
fwrite( $handle, $line ); |
438 |
} |
|
439 |
fclose( $handle ); |
|
440 |
chmod( $path_to_wp_config, 0666 ); |
|
441 |
setup_config_display_header(); |
|
9 | 442 |
?> |
443 |
<h1 class="screen-reader-text"><?php _e( 'Successful database connection' ); ?></h1> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
444 |
<p><?php _e( '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…' ); ?></p> |
0 | 445 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
446 |
<p class="step"><a href="<?php echo $install; ?>" class="button button-large"><?php _e( 'Run the installation' ); ?></a></p> |
9 | 447 |
<?php |
0 | 448 |
endif; |
9 | 449 |
break; |
0 | 450 |
} |
451 |
?> |
|
5 | 452 |
<?php wp_print_scripts( 'language-chooser' ); ?> |
0 | 453 |
</body> |
454 |
</html> |