Skip to content

Commit fdf1f19

Browse files
committed
Wrap wp_install function in a function_exists() condition
1 parent 6e5b9e8 commit fdf1f19

File tree

1 file changed

+100
-98
lines changed

1 file changed

+100
-98
lines changed

wp-includes/sqlite/install-functions.php

+100-98
Original file line numberDiff line numberDiff line change
@@ -110,118 +110,120 @@ function sqlite_make_db_sqlite() {
110110
return true;
111111
}
112112

113-
/**
114-
* Installs the site.
115-
*
116-
* Runs the required functions to set up and populate the database,
117-
* including primary admin user and initial options.
118-
*
119-
* @since 1.0.0
120-
*
121-
* @param string $blog_title Site title.
122-
* @param string $user_name User's username.
123-
* @param string $user_email User's email.
124-
* @param bool $is_public Whether the site is public.
125-
* @param string $deprecated Optional. Not used.
126-
* @param string $user_password Optional. User's chosen password. Default empty (random password).
127-
* @param string $language Optional. Language chosen. Default empty.
128-
* @return array {
129-
* Data for the newly installed site.
130-
*
131-
* @type string $url The URL of the site.
132-
* @type int $user_id The ID of the site owner.
133-
* @type string $password The password of the site owner, if their user account didn't already exist.
134-
* @type string $password_message The explanatory message regarding the password.
135-
* }
136-
*/
137-
function wp_install( $blog_title, $user_name, $user_email, $is_public, $deprecated = '', $user_password = '', $language = '' ) {
138-
if ( ! empty( $deprecated ) ) {
139-
_deprecated_argument( __FUNCTION__, '2.6.0' );
140-
}
113+
if ( ! function_exists( 'wp_install' ) ) {
114+
/**
115+
* Installs the site.
116+
*
117+
* Runs the required functions to set up and populate the database,
118+
* including primary admin user and initial options.
119+
*
120+
* @since 1.0.0
121+
*
122+
* @param string $blog_title Site title.
123+
* @param string $user_name User's username.
124+
* @param string $user_email User's email.
125+
* @param bool $is_public Whether the site is public.
126+
* @param string $deprecated Optional. Not used.
127+
* @param string $user_password Optional. User's chosen password. Default empty (random password).
128+
* @param string $language Optional. Language chosen. Default empty.
129+
* @return array {
130+
* Data for the newly installed site.
131+
*
132+
* @type string $url The URL of the site.
133+
* @type int $user_id The ID of the site owner.
134+
* @type string $password The password of the site owner, if their user account didn't already exist.
135+
* @type string $password_message The explanatory message regarding the password.
136+
* }
137+
*/
138+
function wp_install( $blog_title, $user_name, $user_email, $is_public, $deprecated = '', $user_password = '', $language = '' ) {
139+
if ( ! empty( $deprecated ) ) {
140+
_deprecated_argument( __FUNCTION__, '2.6.0' );
141+
}
141142

142-
wp_check_mysql_version();
143-
wp_cache_flush();
144-
/* SQLite changes: Replace the call to make_db_current_silent() with sqlite_make_db_sqlite(). */
145-
sqlite_make_db_sqlite(); // phpcs:ignore PHPCompatibility.Extensions.RemovedExtensions.sqliteRemoved
146-
populate_options();
147-
populate_roles();
143+
wp_check_mysql_version();
144+
wp_cache_flush();
145+
/* SQLite changes: Replace the call to make_db_current_silent() with sqlite_make_db_sqlite(). */
146+
sqlite_make_db_sqlite(); // phpcs:ignore PHPCompatibility.Extensions.RemovedExtensions.sqliteRemoved
147+
populate_options();
148+
populate_roles();
148149

149-
update_option( 'blogname', $blog_title );
150-
update_option( 'admin_email', $user_email );
151-
update_option( 'blog_public', $is_public );
150+
update_option( 'blogname', $blog_title );
151+
update_option( 'admin_email', $user_email );
152+
update_option( 'blog_public', $is_public );
152153

153-
// Freshness of site - in the future, this could get more specific about actions taken, perhaps.
154-
update_option( 'fresh_site', 1 );
154+
// Freshness of site - in the future, this could get more specific about actions taken, perhaps.
155+
update_option( 'fresh_site', 1 );
155156

156-
if ( $language ) {
157-
update_option( 'WPLANG', $language );
158-
}
157+
if ( $language ) {
158+
update_option( 'WPLANG', $language );
159+
}
159160

160-
$guessurl = wp_guess_url();
161+
$guessurl = wp_guess_url();
161162

162-
update_option( 'siteurl', $guessurl );
163+
update_option( 'siteurl', $guessurl );
163164

164-
// If not a public site, don't ping.
165-
if ( ! $is_public ) {
166-
update_option( 'default_pingback_flag', 0 );
167-
}
165+
// If not a public site, don't ping.
166+
if ( ! $is_public ) {
167+
update_option( 'default_pingback_flag', 0 );
168+
}
168169

169-
/*
170-
* Create default user. If the user already exists, the user tables are
171-
* being shared among sites. Just set the role in that case.
172-
*/
173-
$user_id = username_exists( $user_name );
174-
$user_password = trim( $user_password );
175-
$email_password = false;
176-
$user_created = false;
177-
178-
if ( ! $user_id && empty( $user_password ) ) {
179-
$user_password = wp_generate_password( 12, false );
180-
$message = __( '<strong><em>Note that password</em></strong> carefully! It is a <em>random</em> password that was generated just for you.', 'sqlite-database-integration' );
181-
$user_id = wp_create_user( $user_name, $user_password, $user_email );
182-
update_user_meta( $user_id, 'default_password_nag', true );
183-
$email_password = true;
184-
$user_created = true;
185-
} elseif ( ! $user_id ) {
186-
// Password has been provided.
187-
$message = '<em>' . __( 'Your chosen password.', 'sqlite-database-integration' ) . '</em>';
188-
$user_id = wp_create_user( $user_name, $user_password, $user_email );
189-
$user_created = true;
190-
} else {
191-
$message = __( 'User already exists. Password inherited.', 'sqlite-database-integration' );
192-
}
170+
/*
171+
* Create default user. If the user already exists, the user tables are
172+
* being shared among sites. Just set the role in that case.
173+
*/
174+
$user_id = username_exists( $user_name );
175+
$user_password = trim( $user_password );
176+
$email_password = false;
177+
$user_created = false;
178+
179+
if ( ! $user_id && empty( $user_password ) ) {
180+
$user_password = wp_generate_password( 12, false );
181+
$message = __( '<strong><em>Note that password</em></strong> carefully! It is a <em>random</em> password that was generated just for you.', 'sqlite-database-integration' );
182+
$user_id = wp_create_user( $user_name, $user_password, $user_email );
183+
update_user_meta( $user_id, 'default_password_nag', true );
184+
$email_password = true;
185+
$user_created = true;
186+
} elseif ( ! $user_id ) {
187+
// Password has been provided.
188+
$message = '<em>' . __( 'Your chosen password.', 'sqlite-database-integration' ) . '</em>';
189+
$user_id = wp_create_user( $user_name, $user_password, $user_email );
190+
$user_created = true;
191+
} else {
192+
$message = __( 'User already exists. Password inherited.', 'sqlite-database-integration' );
193+
}
193194

194-
$user = new WP_User( $user_id );
195-
$user->set_role( 'administrator' );
195+
$user = new WP_User( $user_id );
196+
$user->set_role( 'administrator' );
196197

197-
if ( $user_created ) {
198-
$user->user_url = $guessurl;
199-
wp_update_user( $user );
200-
}
198+
if ( $user_created ) {
199+
$user->user_url = $guessurl;
200+
wp_update_user( $user );
201+
}
201202

202-
wp_install_defaults( $user_id );
203+
wp_install_defaults( $user_id );
203204

204-
wp_install_maybe_enable_pretty_permalinks();
205+
wp_install_maybe_enable_pretty_permalinks();
205206

206-
flush_rewrite_rules();
207+
flush_rewrite_rules();
207208

208-
wp_new_blog_notification( $blog_title, $guessurl, $user_id, ( $email_password ? $user_password : __( 'The password you chose during installation.', 'sqlite-database-integration' ) ) );
209+
wp_new_blog_notification( $blog_title, $guessurl, $user_id, ( $email_password ? $user_password : __( 'The password you chose during installation.', 'sqlite-database-integration' ) ) );
209210

210-
wp_cache_flush();
211+
wp_cache_flush();
211212

212-
/**
213-
* Fires after a site is fully installed.
214-
*
215-
* @since 3.9.0
216-
*
217-
* @param WP_User $user The site owner.
218-
*/
219-
do_action( 'wp_install', $user );
220-
221-
return array(
222-
'url' => $guessurl,
223-
'user_id' => $user_id,
224-
'password' => $user_password,
225-
'password_message' => $message,
226-
);
213+
/**
214+
* Fires after a site is fully installed.
215+
*
216+
* @since 3.9.0
217+
*
218+
* @param WP_User $user The site owner.
219+
*/
220+
do_action( 'wp_install', $user );
221+
222+
return array(
223+
'url' => $guessurl,
224+
'user_id' => $user_id,
225+
'password' => $user_password,
226+
'password_message' => $message,
227+
);
228+
}
227229
}

0 commit comments

Comments
 (0)