-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.php
239 lines (201 loc) · 7.98 KB
/
install.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
<?php
/**
* Plugin name: Better WP install.php dropin
* Plugin URI: https://github.com/alexsancho/wp-install-dropin
* Description: This dropin doesn't install bloat content like the default install.php and sets a few opionated wp options.
* Author: Alex Sancho
* Author URI: https://github.com/alexsancho
* License: MIT
* License URI: https://opensource.org/licenses/MIT
* Version: 1.0.0
*/
/**
* Installs the site.
*
* Runs the required functions to set up and populate the database,
* including primary admin user and initial options.
*
* @since 1.0.0
*
* @param string $blog_title Blog title.
* @param string $user_name User's username.
* @param string $user_email User's email.
* @param bool $public Whether blog is public.
* @param string $deprecated Optional. Not used.
* @param string $user_password Optional. User's chosen password. Default empty (random password).
* @param string $language Optional. Language chosen. Default empty.
*
* @return array Array keys 'url', 'user_id', 'password', and 'password_message'.
*/
function wp_install(
string $blog_title, string $user_name, string $user_email, bool $public,
string $deprecated = '', string $user_password = '', string $language = ''
) {
if ( ! empty( $deprecated ) ) {
_deprecated_argument( __FUNCTION__, '2.6' );
}
wp_check_mysql_version();
wp_cache_flush();
make_db_current_silent();
populate_options();
populate_roles();
// Use language from installer or env WPLANG or default to 'es_ES'.
if ( ! empty( $language ) ) {
update_option( 'WPLANG', $language );
} elseif ( ! empty( getenv( 'WPLANG' ) ) ) {
update_option( 'WPLANG', getenv( 'WPLANG' ) );
} else {
update_option( 'WPLANG', 'es_ES' );
}
update_option( 'blogname', $blog_title );
update_option( 'admin_email', $user_email );
update_option( 'blog_public', $public );
// Prefer empty description if someone forgots to change it.
update_option( 'blogdescription', '' );
$guessurl = wp_guess_url();
update_option( 'siteurl', $guessurl );
// If not a public blog, don't ping.
if ( ! $public ) {
update_option( 'default_pingback_flag', 0 );
}
/*
* Create default user. If the user already exists, the user tables are
* being shared among blogs. Just set the role in that case.
*/
$user_id = username_exists( $user_name );
$user_password = trim( $user_password );
$email_password = false;
if ( ! $user_id && empty( $user_password ) ) {
$user_password = wp_generate_password( 12, false );
$message = __( '<strong><em>Note that password</em></strong> carefully! It is a <em>random</em> password that was generated just for you.' );
$user_id = wp_create_user( $user_name, $user_password, $user_email );
update_user_option( $user_id, 'default_password_nag', true, true );
$email_password = true;
} elseif ( ! $user_id ) {
// Password has been provided.
$message = '<em>' . __( 'Your chosen password.' ) . '</em>';
$user_id = wp_create_user( $user_name, $user_password, $user_email );
} else {
$message = __( 'User already exists. Password inherited.' );
}
$user = new WP_User( $user_id );
$user->set_role( 'administrator' );
wp_install_defaults( $user_id );
wp_install_maybe_enable_pretty_permalinks();
flush_rewrite_rules();
wp_cache_flush();
/**
* Fires after a site is fully installed.
*
* @since 3.9.0
*
* @param WP_User $user The site owner.
*/
do_action( 'wp_install', $user );
return [ 'url' => $guessurl, 'user_id' => $user_id, 'password' => $user_password, 'password_message' => $message ];
}
/**
* Creates the initial content for a newly-installed site.
*
* Adds the default "Uncategorized" category, the first post (with comment),
* first page, and default widgets for default theme for the current version.
*
* @since 1.0.0
*
* @param int $user_id User ID.
*/
function wp_install_defaults( int $user_id ) {
global $wpdb, $wp_rewrite, $current_site, $table_prefix;
/**
* Time zone: Get the one from TZ environmental variable
*
* @see wp-admin/options-general.php
*/
update_option( 'timezone_string', ( ! empty( getenv( 'TZ' ) ) ? getenv( 'TZ' ) : 'Europe/Madrid' ) );
/**
* We don't want any default widgets. This fixes 'Undefined index: wp_inactive_widgets'
*
* @see wp-includes/widgets.php:1208
*/
update_option( 'sidebars_widgets', [ 'wp_inactive_widgets' => [] ] );
/**
* Before a comment appears a comment must be manually approved: true
*
* @see wp-admin/options-discussion.php
*/
update_option( 'comment_moderation', 1 );
/** Before a comment appears the comment author must have a previously approved comment: false */
update_option( 'comment_whitelist', 0 );
/** Allow people to post comments on new articles (this setting may be overridden for individual articles): false */
update_option( 'default_comment_status', 0 );
/** Allow link notifications from other blogs: false */
update_option( 'default_ping_status', 0 );
/** Attempt to notify any blogs linked to from the article: false */
update_option( 'default_pingback_flag', 0 );
/**
* Organize my uploads into month- and year-based folders: true
*
* @see wp-admin/options-media.php
*/
update_option( 'uploads_use_yearmonth_folders', 1 );
/**
* Permalink custom structure: /%postname%
*
* @see wp-admin/options-permalink.php
*/
update_option( 'permalink_structure', '/%postname%/' );
/**
* Create Default category.
*/
// Somehow translations won't work always. So check if Finnish was used.
$cat_name = ( get_option( 'WPLANG' ) == 'es_ES' ) ? 'Sin categorizar' : __( 'Uncategorized' );
/* translators: Default category slug */
$cat_slug = sanitize_title( ( get_option( 'WPLANG' ) == 'es_ES' ) ? 'sin-categorizar' : _x( 'Uncategorized', 'Default category slug' ) );
if ( global_terms_enabled() ) {
$cat_id = $wpdb->get_var( $wpdb->prepare( "SELECT cat_ID FROM {$wpdb->sitecategories} WHERE category_nicename = %s", $cat_slug ) );
if ( null == $cat_id ) {
$wpdb->insert( $wpdb->sitecategories, [ 'cat_ID' => 0, 'cat_name' => $cat_name, 'category_nicename' => $cat_slug, 'last_updated' => current_time( 'mysql', true ) ] );
$cat_id = $wpdb->insert_id;
}
update_option( 'default_category', $cat_id );
} else {
$cat_id = 1;
}
$wpdb->insert( $wpdb->terms, [ 'term_id' => $cat_id, 'name' => $cat_name, 'slug' => $cat_slug, 'term_group' => 0 ] );
$wpdb->insert( $wpdb->term_taxonomy, [ 'term_id' => $cat_id, 'taxonomy' => 'category', 'description' => '', 'parent' => 0, 'count' => 1 ] );
$cat_tt_id = $wpdb->insert_id;
/**
* Create new page and add it as front page
*/
$id = wp_insert_post( [
// Somehow translations won't work always. So check if Finnish was used.
'post_title' => ( get_option( 'WPLANG' ) == 'es_ES' ) ? 'Portada' : __( 'Front page' ),
'post_type' => 'page',
'post_status' => 'publish',
// Prefer empty content if someone forgets to change it.
'post_content' => '',
] );
// Add page we just created as front page
update_option( 'page_on_front', $id );
update_option( 'show_on_front', 'page' );
if ( is_multisite() ) {
// Flush rules to pick up the new page.
$wp_rewrite->init();
$wp_rewrite->flush_rules();
$user = new WP_User( $user_id );
$wpdb->update( $wpdb->options, [ 'option_value' => $user->user_email ], [ 'option_name' => 'admin_email' ] );
// Remove all perms except for the login user.
$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->usermeta WHERE user_id != %d AND meta_key = %s", $user_id, $table_prefix . 'user_level' ) );
$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->usermeta WHERE user_id != %d AND meta_key = %s", $user_id, $table_prefix . 'capabilities' ) );
// Delete any caps that snuck into the previously active blog. (Hardcoded to blog 1 for now.) TODO: Get previous_blog_id.
if ( 1 !== $user_id && ! is_super_admin( $user_id ) ) {
$wpdb->delete( $wpdb->usermeta, [ 'user_id' => $user_id, 'meta_key' => $wpdb->base_prefix . '1_capabilities' ] );
}
}
/**
* Show welcome panel: false
*
* @see wp-admin/includes/screen.php
*/
update_user_meta( $user_id, 'show_welcome_panel', 0 );
}