author | ymh <ymh.work@gmail.com> |
Mon, 14 Oct 2019 18:30:03 +0200 | |
changeset 10 | 372f2766ea20 |
parent 9 | 177826044cd9 |
child 16 | a86126ab1dd4 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* WordPress Administration Scheme API |
|
4 |
* |
|
5 |
* Here we keep the DB structure and option values. |
|
6 |
* |
|
7 |
* @package WordPress |
|
8 |
* @subpackage Administration |
|
9 |
*/ |
|
10 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
11 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
12 |
* Declare these as global in case schema.php is included from a function. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
13 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
14 |
* @global wpdb $wpdb |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
15 |
* @global array $wp_queries |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
16 |
* @global string $charset_collate |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
17 |
*/ |
0 | 18 |
global $wpdb, $wp_queries, $charset_collate; |
19 |
||
20 |
/** |
|
21 |
* The database character collate. |
|
22 |
*/ |
|
23 |
$charset_collate = $wpdb->get_charset_collate(); |
|
24 |
||
25 |
/** |
|
26 |
* Retrieve the SQL for creating database tables. |
|
27 |
* |
|
28 |
* @since 3.3.0 |
|
29 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
30 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
31 |
* |
0 | 32 |
* @param string $scope Optional. The tables for which to retrieve SQL. Can be all, global, ms_global, or blog tables. Defaults to all. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
33 |
* @param int $blog_id Optional. The site ID for which to retrieve SQL. Default is the current site ID. |
0 | 34 |
* @return string The SQL needed to create the requested tables. |
35 |
*/ |
|
36 |
function wp_get_db_schema( $scope = 'all', $blog_id = null ) { |
|
37 |
global $wpdb; |
|
38 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
39 |
$charset_collate = $wpdb->get_charset_collate(); |
0 | 40 |
|
9 | 41 |
if ( $blog_id && $blog_id != $wpdb->blogid ) { |
0 | 42 |
$old_blog_id = $wpdb->set_blog_id( $blog_id ); |
9 | 43 |
} |
0 | 44 |
|
45 |
// Engage multisite if in the middle of turning it on from network.php. |
|
46 |
$is_multisite = is_multisite() || ( defined( 'WP_INSTALLING_NETWORK' ) && WP_INSTALLING_NETWORK ); |
|
47 |
||
5 | 48 |
/* |
49 |
* Indexes have a maximum size of 767 bytes. Historically, we haven't need to be concerned about that. |
|
50 |
* As of 4.2, however, we moved to utf8mb4, which uses 4 bytes per character. This means that an index which |
|
51 |
* used to have room for floor(767/3) = 255 characters, now only has room for floor(767/4) = 191 characters. |
|
52 |
*/ |
|
53 |
$max_index_length = 191; |
|
54 |
||
0 | 55 |
// Blog specific tables. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
56 |
$blog_tables = "CREATE TABLE $wpdb->termmeta ( |
9 | 57 |
meta_id bigint(20) unsigned NOT NULL auto_increment, |
58 |
term_id bigint(20) unsigned NOT NULL default '0', |
|
59 |
meta_key varchar(255) default NULL, |
|
60 |
meta_value longtext, |
|
61 |
PRIMARY KEY (meta_id), |
|
62 |
KEY term_id (term_id), |
|
63 |
KEY meta_key (meta_key($max_index_length)) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
64 |
) $charset_collate; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
65 |
CREATE TABLE $wpdb->terms ( |
0 | 66 |
term_id bigint(20) unsigned NOT NULL auto_increment, |
67 |
name varchar(200) NOT NULL default '', |
|
68 |
slug varchar(200) NOT NULL default '', |
|
69 |
term_group bigint(10) NOT NULL default 0, |
|
70 |
PRIMARY KEY (term_id), |
|
5 | 71 |
KEY slug (slug($max_index_length)), |
72 |
KEY name (name($max_index_length)) |
|
0 | 73 |
) $charset_collate; |
74 |
CREATE TABLE $wpdb->term_taxonomy ( |
|
75 |
term_taxonomy_id bigint(20) unsigned NOT NULL auto_increment, |
|
76 |
term_id bigint(20) unsigned NOT NULL default 0, |
|
77 |
taxonomy varchar(32) NOT NULL default '', |
|
78 |
description longtext NOT NULL, |
|
79 |
parent bigint(20) unsigned NOT NULL default 0, |
|
80 |
count bigint(20) NOT NULL default 0, |
|
81 |
PRIMARY KEY (term_taxonomy_id), |
|
82 |
UNIQUE KEY term_id_taxonomy (term_id,taxonomy), |
|
83 |
KEY taxonomy (taxonomy) |
|
84 |
) $charset_collate; |
|
85 |
CREATE TABLE $wpdb->term_relationships ( |
|
86 |
object_id bigint(20) unsigned NOT NULL default 0, |
|
87 |
term_taxonomy_id bigint(20) unsigned NOT NULL default 0, |
|
88 |
term_order int(11) NOT NULL default 0, |
|
89 |
PRIMARY KEY (object_id,term_taxonomy_id), |
|
90 |
KEY term_taxonomy_id (term_taxonomy_id) |
|
91 |
) $charset_collate; |
|
92 |
CREATE TABLE $wpdb->commentmeta ( |
|
9 | 93 |
meta_id bigint(20) unsigned NOT NULL auto_increment, |
94 |
comment_id bigint(20) unsigned NOT NULL default '0', |
|
95 |
meta_key varchar(255) default NULL, |
|
96 |
meta_value longtext, |
|
97 |
PRIMARY KEY (meta_id), |
|
98 |
KEY comment_id (comment_id), |
|
99 |
KEY meta_key (meta_key($max_index_length)) |
|
0 | 100 |
) $charset_collate; |
101 |
CREATE TABLE $wpdb->comments ( |
|
9 | 102 |
comment_ID bigint(20) unsigned NOT NULL auto_increment, |
103 |
comment_post_ID bigint(20) unsigned NOT NULL default '0', |
|
104 |
comment_author tinytext NOT NULL, |
|
105 |
comment_author_email varchar(100) NOT NULL default '', |
|
106 |
comment_author_url varchar(200) NOT NULL default '', |
|
107 |
comment_author_IP varchar(100) NOT NULL default '', |
|
108 |
comment_date datetime NOT NULL default '0000-00-00 00:00:00', |
|
109 |
comment_date_gmt datetime NOT NULL default '0000-00-00 00:00:00', |
|
110 |
comment_content text NOT NULL, |
|
111 |
comment_karma int(11) NOT NULL default '0', |
|
112 |
comment_approved varchar(20) NOT NULL default '1', |
|
113 |
comment_agent varchar(255) NOT NULL default '', |
|
114 |
comment_type varchar(20) NOT NULL default '', |
|
115 |
comment_parent bigint(20) unsigned NOT NULL default '0', |
|
116 |
user_id bigint(20) unsigned NOT NULL default '0', |
|
117 |
PRIMARY KEY (comment_ID), |
|
118 |
KEY comment_post_ID (comment_post_ID), |
|
119 |
KEY comment_approved_date_gmt (comment_approved,comment_date_gmt), |
|
120 |
KEY comment_date_gmt (comment_date_gmt), |
|
121 |
KEY comment_parent (comment_parent), |
|
122 |
KEY comment_author_email (comment_author_email(10)) |
|
0 | 123 |
) $charset_collate; |
124 |
CREATE TABLE $wpdb->links ( |
|
9 | 125 |
link_id bigint(20) unsigned NOT NULL auto_increment, |
126 |
link_url varchar(255) NOT NULL default '', |
|
127 |
link_name varchar(255) NOT NULL default '', |
|
128 |
link_image varchar(255) NOT NULL default '', |
|
129 |
link_target varchar(25) NOT NULL default '', |
|
130 |
link_description varchar(255) NOT NULL default '', |
|
131 |
link_visible varchar(20) NOT NULL default 'Y', |
|
132 |
link_owner bigint(20) unsigned NOT NULL default '1', |
|
133 |
link_rating int(11) NOT NULL default '0', |
|
134 |
link_updated datetime NOT NULL default '0000-00-00 00:00:00', |
|
135 |
link_rel varchar(255) NOT NULL default '', |
|
136 |
link_notes mediumtext NOT NULL, |
|
137 |
link_rss varchar(255) NOT NULL default '', |
|
138 |
PRIMARY KEY (link_id), |
|
139 |
KEY link_visible (link_visible) |
|
0 | 140 |
) $charset_collate; |
141 |
CREATE TABLE $wpdb->options ( |
|
9 | 142 |
option_id bigint(20) unsigned NOT NULL auto_increment, |
143 |
option_name varchar(191) NOT NULL default '', |
|
144 |
option_value longtext NOT NULL, |
|
145 |
autoload varchar(20) NOT NULL default 'yes', |
|
146 |
PRIMARY KEY (option_id), |
|
147 |
UNIQUE KEY option_name (option_name) |
|
0 | 148 |
) $charset_collate; |
149 |
CREATE TABLE $wpdb->postmeta ( |
|
9 | 150 |
meta_id bigint(20) unsigned NOT NULL auto_increment, |
151 |
post_id bigint(20) unsigned NOT NULL default '0', |
|
152 |
meta_key varchar(255) default NULL, |
|
153 |
meta_value longtext, |
|
154 |
PRIMARY KEY (meta_id), |
|
155 |
KEY post_id (post_id), |
|
156 |
KEY meta_key (meta_key($max_index_length)) |
|
0 | 157 |
) $charset_collate; |
158 |
CREATE TABLE $wpdb->posts ( |
|
9 | 159 |
ID bigint(20) unsigned NOT NULL auto_increment, |
160 |
post_author bigint(20) unsigned NOT NULL default '0', |
|
161 |
post_date datetime NOT NULL default '0000-00-00 00:00:00', |
|
162 |
post_date_gmt datetime NOT NULL default '0000-00-00 00:00:00', |
|
163 |
post_content longtext NOT NULL, |
|
164 |
post_title text NOT NULL, |
|
165 |
post_excerpt text NOT NULL, |
|
166 |
post_status varchar(20) NOT NULL default 'publish', |
|
167 |
comment_status varchar(20) NOT NULL default 'open', |
|
168 |
ping_status varchar(20) NOT NULL default 'open', |
|
169 |
post_password varchar(255) NOT NULL default '', |
|
170 |
post_name varchar(200) NOT NULL default '', |
|
171 |
to_ping text NOT NULL, |
|
172 |
pinged text NOT NULL, |
|
173 |
post_modified datetime NOT NULL default '0000-00-00 00:00:00', |
|
174 |
post_modified_gmt datetime NOT NULL default '0000-00-00 00:00:00', |
|
175 |
post_content_filtered longtext NOT NULL, |
|
176 |
post_parent bigint(20) unsigned NOT NULL default '0', |
|
177 |
guid varchar(255) NOT NULL default '', |
|
178 |
menu_order int(11) NOT NULL default '0', |
|
179 |
post_type varchar(20) NOT NULL default 'post', |
|
180 |
post_mime_type varchar(100) NOT NULL default '', |
|
181 |
comment_count bigint(20) NOT NULL default '0', |
|
182 |
PRIMARY KEY (ID), |
|
183 |
KEY post_name (post_name($max_index_length)), |
|
184 |
KEY type_status_date (post_type,post_status,post_date,ID), |
|
185 |
KEY post_parent (post_parent), |
|
186 |
KEY post_author (post_author) |
|
0 | 187 |
) $charset_collate;\n"; |
188 |
||
189 |
// Single site users table. The multisite flavor of the users table is handled below. |
|
190 |
$users_single_table = "CREATE TABLE $wpdb->users ( |
|
9 | 191 |
ID bigint(20) unsigned NOT NULL auto_increment, |
192 |
user_login varchar(60) NOT NULL default '', |
|
193 |
user_pass varchar(255) NOT NULL default '', |
|
194 |
user_nicename varchar(50) NOT NULL default '', |
|
195 |
user_email varchar(100) NOT NULL default '', |
|
196 |
user_url varchar(100) NOT NULL default '', |
|
197 |
user_registered datetime NOT NULL default '0000-00-00 00:00:00', |
|
198 |
user_activation_key varchar(255) NOT NULL default '', |
|
199 |
user_status int(11) NOT NULL default '0', |
|
200 |
display_name varchar(250) NOT NULL default '', |
|
201 |
PRIMARY KEY (ID), |
|
202 |
KEY user_login_key (user_login), |
|
203 |
KEY user_nicename (user_nicename), |
|
204 |
KEY user_email (user_email) |
|
0 | 205 |
) $charset_collate;\n"; |
206 |
||
207 |
// Multisite users table |
|
208 |
$users_multi_table = "CREATE TABLE $wpdb->users ( |
|
9 | 209 |
ID bigint(20) unsigned NOT NULL auto_increment, |
210 |
user_login varchar(60) NOT NULL default '', |
|
211 |
user_pass varchar(255) NOT NULL default '', |
|
212 |
user_nicename varchar(50) NOT NULL default '', |
|
213 |
user_email varchar(100) NOT NULL default '', |
|
214 |
user_url varchar(100) NOT NULL default '', |
|
215 |
user_registered datetime NOT NULL default '0000-00-00 00:00:00', |
|
216 |
user_activation_key varchar(255) NOT NULL default '', |
|
217 |
user_status int(11) NOT NULL default '0', |
|
218 |
display_name varchar(250) NOT NULL default '', |
|
219 |
spam tinyint(2) NOT NULL default '0', |
|
220 |
deleted tinyint(2) NOT NULL default '0', |
|
221 |
PRIMARY KEY (ID), |
|
222 |
KEY user_login_key (user_login), |
|
223 |
KEY user_nicename (user_nicename), |
|
224 |
KEY user_email (user_email) |
|
0 | 225 |
) $charset_collate;\n"; |
226 |
||
5 | 227 |
// Usermeta. |
0 | 228 |
$usermeta_table = "CREATE TABLE $wpdb->usermeta ( |
9 | 229 |
umeta_id bigint(20) unsigned NOT NULL auto_increment, |
230 |
user_id bigint(20) unsigned NOT NULL default '0', |
|
231 |
meta_key varchar(255) default NULL, |
|
232 |
meta_value longtext, |
|
233 |
PRIMARY KEY (umeta_id), |
|
234 |
KEY user_id (user_id), |
|
235 |
KEY meta_key (meta_key($max_index_length)) |
|
0 | 236 |
) $charset_collate;\n"; |
237 |
||
238 |
// Global tables |
|
9 | 239 |
if ( $is_multisite ) { |
0 | 240 |
$global_tables = $users_multi_table . $usermeta_table; |
9 | 241 |
} else { |
0 | 242 |
$global_tables = $users_single_table . $usermeta_table; |
9 | 243 |
} |
0 | 244 |
|
245 |
// Multisite global tables. |
|
246 |
$ms_global_tables = "CREATE TABLE $wpdb->blogs ( |
|
9 | 247 |
blog_id bigint(20) NOT NULL auto_increment, |
248 |
site_id bigint(20) NOT NULL default '0', |
|
249 |
domain varchar(200) NOT NULL default '', |
|
250 |
path varchar(100) NOT NULL default '', |
|
251 |
registered datetime NOT NULL default '0000-00-00 00:00:00', |
|
252 |
last_updated datetime NOT NULL default '0000-00-00 00:00:00', |
|
253 |
public tinyint(2) NOT NULL default '1', |
|
254 |
archived tinyint(2) NOT NULL default '0', |
|
255 |
mature tinyint(2) NOT NULL default '0', |
|
256 |
spam tinyint(2) NOT NULL default '0', |
|
257 |
deleted tinyint(2) NOT NULL default '0', |
|
258 |
lang_id int(11) NOT NULL default '0', |
|
259 |
PRIMARY KEY (blog_id), |
|
260 |
KEY domain (domain(50),path(5)), |
|
261 |
KEY lang_id (lang_id) |
|
0 | 262 |
) $charset_collate; |
263 |
CREATE TABLE $wpdb->blog_versions ( |
|
9 | 264 |
blog_id bigint(20) NOT NULL default '0', |
265 |
db_version varchar(20) NOT NULL default '', |
|
266 |
last_updated datetime NOT NULL default '0000-00-00 00:00:00', |
|
267 |
PRIMARY KEY (blog_id), |
|
268 |
KEY db_version (db_version) |
|
269 |
) $charset_collate; |
|
270 |
CREATE TABLE $wpdb->blogmeta ( |
|
271 |
meta_id bigint(20) unsigned NOT NULL auto_increment, |
|
272 |
blog_id bigint(20) NOT NULL default '0', |
|
273 |
meta_key varchar(255) default NULL, |
|
274 |
meta_value longtext, |
|
275 |
PRIMARY KEY (meta_id), |
|
276 |
KEY meta_key (meta_key($max_index_length)), |
|
277 |
KEY blog_id (blog_id) |
|
0 | 278 |
) $charset_collate; |
279 |
CREATE TABLE $wpdb->registration_log ( |
|
9 | 280 |
ID bigint(20) NOT NULL auto_increment, |
281 |
email varchar(255) NOT NULL default '', |
|
282 |
IP varchar(30) NOT NULL default '', |
|
283 |
blog_id bigint(20) NOT NULL default '0', |
|
284 |
date_registered datetime NOT NULL default '0000-00-00 00:00:00', |
|
285 |
PRIMARY KEY (ID), |
|
286 |
KEY IP (IP) |
|
0 | 287 |
) $charset_collate; |
288 |
CREATE TABLE $wpdb->site ( |
|
9 | 289 |
id bigint(20) NOT NULL auto_increment, |
290 |
domain varchar(200) NOT NULL default '', |
|
291 |
path varchar(100) NOT NULL default '', |
|
292 |
PRIMARY KEY (id), |
|
293 |
KEY domain (domain(140),path(51)) |
|
0 | 294 |
) $charset_collate; |
295 |
CREATE TABLE $wpdb->sitemeta ( |
|
9 | 296 |
meta_id bigint(20) NOT NULL auto_increment, |
297 |
site_id bigint(20) NOT NULL default '0', |
|
298 |
meta_key varchar(255) default NULL, |
|
299 |
meta_value longtext, |
|
300 |
PRIMARY KEY (meta_id), |
|
301 |
KEY meta_key (meta_key($max_index_length)), |
|
302 |
KEY site_id (site_id) |
|
0 | 303 |
) $charset_collate; |
304 |
CREATE TABLE $wpdb->signups ( |
|
9 | 305 |
signup_id bigint(20) NOT NULL auto_increment, |
306 |
domain varchar(200) NOT NULL default '', |
|
307 |
path varchar(100) NOT NULL default '', |
|
308 |
title longtext NOT NULL, |
|
309 |
user_login varchar(60) NOT NULL default '', |
|
310 |
user_email varchar(100) NOT NULL default '', |
|
311 |
registered datetime NOT NULL default '0000-00-00 00:00:00', |
|
312 |
activated datetime NOT NULL default '0000-00-00 00:00:00', |
|
313 |
active tinyint(1) NOT NULL default '0', |
|
314 |
activation_key varchar(50) NOT NULL default '', |
|
315 |
meta longtext, |
|
316 |
PRIMARY KEY (signup_id), |
|
317 |
KEY activation_key (activation_key), |
|
318 |
KEY user_email (user_email), |
|
319 |
KEY user_login_email (user_login,user_email), |
|
320 |
KEY domain_path (domain(140),path(51)) |
|
0 | 321 |
) $charset_collate;"; |
322 |
||
323 |
switch ( $scope ) { |
|
9 | 324 |
case 'blog': |
0 | 325 |
$queries = $blog_tables; |
326 |
break; |
|
9 | 327 |
case 'global': |
0 | 328 |
$queries = $global_tables; |
9 | 329 |
if ( $is_multisite ) { |
0 | 330 |
$queries .= $ms_global_tables; |
9 | 331 |
} |
0 | 332 |
break; |
9 | 333 |
case 'ms_global': |
0 | 334 |
$queries = $ms_global_tables; |
335 |
break; |
|
9 | 336 |
case 'all': |
0 | 337 |
default: |
338 |
$queries = $global_tables . $blog_tables; |
|
9 | 339 |
if ( $is_multisite ) { |
0 | 340 |
$queries .= $ms_global_tables; |
9 | 341 |
} |
0 | 342 |
break; |
343 |
} |
|
344 |
||
9 | 345 |
if ( isset( $old_blog_id ) ) { |
0 | 346 |
$wpdb->set_blog_id( $old_blog_id ); |
9 | 347 |
} |
0 | 348 |
|
349 |
return $queries; |
|
350 |
} |
|
351 |
||
352 |
// Populate for back compat. |
|
353 |
$wp_queries = wp_get_db_schema( 'all' ); |
|
354 |
||
355 |
/** |
|
356 |
* Create WordPress options and set the default values. |
|
357 |
* |
|
358 |
* @since 1.5.0 |
|
9 | 359 |
* @since 5.1.0 The $options parameter has been added. |
5 | 360 |
* |
361 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
362 |
* @global int $wp_db_version |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
363 |
* @global int $wp_current_db_version |
9 | 364 |
* |
365 |
* @param array $options Optional. Custom option $key => $value pairs to use. Default empty array. |
|
0 | 366 |
*/ |
9 | 367 |
function populate_options( array $options = array() ) { |
5 | 368 |
global $wpdb, $wp_db_version, $wp_current_db_version; |
0 | 369 |
|
370 |
$guessurl = wp_guess_url(); |
|
5 | 371 |
/** |
372 |
* Fires before creating WordPress options and populating their default values. |
|
373 |
* |
|
374 |
* @since 2.6.0 |
|
375 |
*/ |
|
376 |
do_action( 'populate_options' ); |
|
0 | 377 |
|
9 | 378 |
if ( ini_get( 'safe_mode' ) ) { |
0 | 379 |
// Safe mode can break mkdir() so use a flat structure by default. |
380 |
$uploads_use_yearmonth_folders = 0; |
|
381 |
} else { |
|
382 |
$uploads_use_yearmonth_folders = 1; |
|
383 |
} |
|
384 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
385 |
// If WP_DEFAULT_THEME doesn't exist, fall back to the latest core default theme. |
9 | 386 |
$stylesheet = WP_DEFAULT_THEME; |
387 |
$template = WP_DEFAULT_THEME; |
|
388 |
$theme = wp_get_theme( WP_DEFAULT_THEME ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
389 |
if ( ! $theme->exists() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
390 |
$theme = WP_Theme::get_core_default_theme(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
391 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
392 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
393 |
// If we can't find a core default theme, WP_DEFAULT_THEME is the best we can do. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
394 |
if ( $theme ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
395 |
$stylesheet = $theme->get_stylesheet(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
396 |
$template = $theme->get_template(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
397 |
} |
0 | 398 |
|
399 |
$timezone_string = ''; |
|
9 | 400 |
$gmt_offset = 0; |
401 |
/* |
|
402 |
* translators: default GMT offset or timezone string. Must be either a valid offset (-12 to 14) |
|
403 |
* or a valid timezone string (America/New_York). See https://secure.php.net/manual/en/timezones.php |
|
404 |
* for all timezone strings supported by PHP. |
|
405 |
*/ |
|
406 |
$offset_or_tz = _x( '0', 'default GMT offset or timezone string' ); // phpcs:ignore WordPress.WP.I18n.NoEmptyStrings |
|
407 |
if ( is_numeric( $offset_or_tz ) ) { |
|
0 | 408 |
$gmt_offset = $offset_or_tz; |
9 | 409 |
} elseif ( $offset_or_tz && in_array( $offset_or_tz, timezone_identifiers_list() ) ) { |
0 | 410 |
$timezone_string = $offset_or_tz; |
9 | 411 |
} |
0 | 412 |
|
9 | 413 |
$defaults = array( |
414 |
'siteurl' => $guessurl, |
|
415 |
'home' => $guessurl, |
|
416 |
'blogname' => __( 'My Site' ), |
|
417 |
/* translators: site tagline */ |
|
418 |
'blogdescription' => __( 'Just another WordPress site' ), |
|
419 |
'users_can_register' => 0, |
|
420 |
'admin_email' => 'you@example.com', |
|
421 |
/* translators: default start of the week. 0 = Sunday, 1 = Monday */ |
|
422 |
'start_of_week' => _x( '1', 'start of week' ), |
|
423 |
'use_balanceTags' => 0, |
|
424 |
'use_smilies' => 1, |
|
425 |
'require_name_email' => 1, |
|
426 |
'comments_notify' => 1, |
|
427 |
'posts_per_rss' => 10, |
|
428 |
'rss_use_excerpt' => 0, |
|
429 |
'mailserver_url' => 'mail.example.com', |
|
430 |
'mailserver_login' => 'login@example.com', |
|
431 |
'mailserver_pass' => 'password', |
|
432 |
'mailserver_port' => 110, |
|
433 |
'default_category' => 1, |
|
434 |
'default_comment_status' => 'open', |
|
435 |
'default_ping_status' => 'open', |
|
436 |
'default_pingback_flag' => 1, |
|
437 |
'posts_per_page' => 10, |
|
438 |
/* translators: default date format, see https://secure.php.net/date */ |
|
439 |
'date_format' => __( 'F j, Y' ), |
|
440 |
/* translators: default time format, see https://secure.php.net/date */ |
|
441 |
'time_format' => __( 'g:i a' ), |
|
442 |
/* translators: links last updated date format, see https://secure.php.net/date */ |
|
443 |
'links_updated_date_format' => __( 'F j, Y g:i a' ), |
|
444 |
'comment_moderation' => 0, |
|
445 |
'moderation_notify' => 1, |
|
446 |
'permalink_structure' => '', |
|
447 |
'rewrite_rules' => '', |
|
448 |
'hack_file' => 0, |
|
449 |
'blog_charset' => 'UTF-8', |
|
450 |
'moderation_keys' => '', |
|
451 |
'active_plugins' => array(), |
|
452 |
'category_base' => '', |
|
453 |
'ping_sites' => 'http://rpc.pingomatic.com/', |
|
454 |
'comment_max_links' => 2, |
|
455 |
'gmt_offset' => $gmt_offset, |
|
0 | 456 |
|
9 | 457 |
// 1.5 |
458 |
'default_email_category' => 1, |
|
459 |
'recently_edited' => '', |
|
460 |
'template' => $template, |
|
461 |
'stylesheet' => $stylesheet, |
|
462 |
'comment_whitelist' => 1, |
|
463 |
'blacklist_keys' => '', |
|
464 |
'comment_registration' => 0, |
|
465 |
'html_type' => 'text/html', |
|
0 | 466 |
|
9 | 467 |
// 1.5.1 |
468 |
'use_trackback' => 0, |
|
0 | 469 |
|
9 | 470 |
// 2.0 |
471 |
'default_role' => 'subscriber', |
|
472 |
'db_version' => $wp_db_version, |
|
0 | 473 |
|
9 | 474 |
// 2.0.1 |
475 |
'uploads_use_yearmonth_folders' => $uploads_use_yearmonth_folders, |
|
476 |
'upload_path' => '', |
|
0 | 477 |
|
9 | 478 |
// 2.1 |
479 |
'blog_public' => '1', |
|
480 |
'default_link_category' => 2, |
|
481 |
'show_on_front' => 'posts', |
|
0 | 482 |
|
9 | 483 |
// 2.2 |
484 |
'tag_base' => '', |
|
0 | 485 |
|
9 | 486 |
// 2.5 |
487 |
'show_avatars' => '1', |
|
488 |
'avatar_rating' => 'G', |
|
489 |
'upload_url_path' => '', |
|
490 |
'thumbnail_size_w' => 150, |
|
491 |
'thumbnail_size_h' => 150, |
|
492 |
'thumbnail_crop' => 1, |
|
493 |
'medium_size_w' => 300, |
|
494 |
'medium_size_h' => 300, |
|
0 | 495 |
|
9 | 496 |
// 2.6 |
497 |
'avatar_default' => 'mystery', |
|
0 | 498 |
|
9 | 499 |
// 2.7 |
500 |
'large_size_w' => 1024, |
|
501 |
'large_size_h' => 1024, |
|
502 |
'image_default_link_type' => 'none', |
|
503 |
'image_default_size' => '', |
|
504 |
'image_default_align' => '', |
|
505 |
'close_comments_for_old_posts' => 0, |
|
506 |
'close_comments_days_old' => 14, |
|
507 |
'thread_comments' => 1, |
|
508 |
'thread_comments_depth' => 5, |
|
509 |
'page_comments' => 0, |
|
510 |
'comments_per_page' => 50, |
|
511 |
'default_comments_page' => 'newest', |
|
512 |
'comment_order' => 'asc', |
|
513 |
'sticky_posts' => array(), |
|
514 |
'widget_categories' => array(), |
|
515 |
'widget_text' => array(), |
|
516 |
'widget_rss' => array(), |
|
517 |
'uninstall_plugins' => array(), |
|
0 | 518 |
|
9 | 519 |
// 2.8 |
520 |
'timezone_string' => $timezone_string, |
|
0 | 521 |
|
9 | 522 |
// 3.0 |
523 |
'page_for_posts' => 0, |
|
524 |
'page_on_front' => 0, |
|
0 | 525 |
|
9 | 526 |
// 3.1 |
527 |
'default_post_format' => 0, |
|
0 | 528 |
|
9 | 529 |
// 3.5 |
530 |
'link_manager_enabled' => 0, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
531 |
|
9 | 532 |
// 4.3.0 |
533 |
'finished_splitting_shared_terms' => 1, |
|
534 |
'site_icon' => 0, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
535 |
|
9 | 536 |
// 4.4.0 |
537 |
'medium_large_size_w' => 768, |
|
538 |
'medium_large_size_h' => 0, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
539 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
540 |
// 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
541 |
'wp_page_for_privacy_policy' => 0, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
542 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
543 |
// 4.9.8 |
9 | 544 |
'show_comments_cookies_opt_in' => 1, |
0 | 545 |
); |
546 |
||
547 |
// 3.3 |
|
548 |
if ( ! is_multisite() ) { |
|
9 | 549 |
$defaults['initial_db_version'] = ! empty( $wp_current_db_version ) && $wp_current_db_version < $wp_db_version |
0 | 550 |
? $wp_current_db_version : $wp_db_version; |
551 |
} |
|
552 |
||
553 |
// 3.0 multisite |
|
554 |
if ( is_multisite() ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
555 |
/* translators: site tagline */ |
9 | 556 |
$defaults['blogdescription'] = sprintf( __( 'Just another %s site' ), get_network()->site_name ); |
557 |
$defaults['permalink_structure'] = '/%year%/%monthnum%/%day%/%postname%/'; |
|
0 | 558 |
} |
559 |
||
9 | 560 |
$options = wp_parse_args( $options, $defaults ); |
561 |
||
0 | 562 |
// Set autoload to no for these options |
563 |
$fat_options = array( 'moderation_keys', 'recently_edited', 'blacklist_keys', 'uninstall_plugins' ); |
|
564 |
||
9 | 565 |
$keys = "'" . implode( "', '", array_keys( $options ) ) . "'"; |
566 |
$existing_options = $wpdb->get_col( "SELECT option_name FROM $wpdb->options WHERE option_name in ( $keys )" ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
0 | 567 |
|
568 |
$insert = ''; |
|
569 |
foreach ( $options as $option => $value ) { |
|
9 | 570 |
if ( in_array( $option, $existing_options ) ) { |
0 | 571 |
continue; |
9 | 572 |
} |
573 |
if ( in_array( $option, $fat_options ) ) { |
|
0 | 574 |
$autoload = 'no'; |
9 | 575 |
} else { |
0 | 576 |
$autoload = 'yes'; |
9 | 577 |
} |
0 | 578 |
|
9 | 579 |
if ( is_array( $value ) ) { |
580 |
$value = serialize( $value ); |
|
581 |
} |
|
582 |
if ( ! empty( $insert ) ) { |
|
0 | 583 |
$insert .= ', '; |
9 | 584 |
} |
585 |
$insert .= $wpdb->prepare( '(%s, %s, %s)', $option, $value, $autoload ); |
|
0 | 586 |
} |
587 |
||
9 | 588 |
if ( ! empty( $insert ) ) { |
589 |
$wpdb->query( "INSERT INTO $wpdb->options (option_name, option_value, autoload) VALUES " . $insert ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
590 |
} |
|
0 | 591 |
|
5 | 592 |
// In case it is set, but blank, update "home". |
9 | 593 |
if ( ! __get_option( 'home' ) ) { |
594 |
update_option( 'home', $guessurl ); |
|
595 |
} |
|
0 | 596 |
|
5 | 597 |
// Delete unused options. |
0 | 598 |
$unusedoptions = array( |
9 | 599 |
'blodotgsping_url', |
600 |
'bodyterminator', |
|
601 |
'emailtestonly', |
|
602 |
'phoneemail_separator', |
|
603 |
'smilies_directory', |
|
604 |
'subjectprefix', |
|
605 |
'use_bbcode', |
|
606 |
'use_blodotgsping', |
|
607 |
'use_phoneemail', |
|
608 |
'use_quicktags', |
|
609 |
'use_weblogsping', |
|
610 |
'weblogs_cache_file', |
|
611 |
'use_preview', |
|
612 |
'use_htmltrans', |
|
613 |
'smilies_directory', |
|
614 |
'fileupload_allowedusers', |
|
615 |
'use_phoneemail', |
|
616 |
'default_post_status', |
|
617 |
'default_post_category', |
|
618 |
'archive_mode', |
|
619 |
'time_difference', |
|
620 |
'links_minadminlevel', |
|
621 |
'links_use_adminlevels', |
|
622 |
'links_rating_type', |
|
623 |
'links_rating_char', |
|
624 |
'links_rating_ignore_zero', |
|
625 |
'links_rating_single_image', |
|
626 |
'links_rating_image0', |
|
627 |
'links_rating_image1', |
|
628 |
'links_rating_image2', |
|
629 |
'links_rating_image3', |
|
630 |
'links_rating_image4', |
|
631 |
'links_rating_image5', |
|
632 |
'links_rating_image6', |
|
633 |
'links_rating_image7', |
|
634 |
'links_rating_image8', |
|
635 |
'links_rating_image9', |
|
636 |
'links_recently_updated_time', |
|
637 |
'links_recently_updated_prepend', |
|
638 |
'links_recently_updated_append', |
|
639 |
'weblogs_cacheminutes', |
|
640 |
'comment_allowed_tags', |
|
641 |
'search_engine_friendly_urls', |
|
642 |
'default_geourl_lat', |
|
643 |
'default_geourl_lon', |
|
644 |
'use_default_geourl', |
|
645 |
'weblogs_xml_url', |
|
646 |
'new_users_can_blog', |
|
647 |
'_wpnonce', |
|
648 |
'_wp_http_referer', |
|
649 |
'Update', |
|
650 |
'action', |
|
651 |
'rich_editing', |
|
652 |
'autosave_interval', |
|
653 |
'deactivated_plugins', |
|
654 |
'can_compress_scripts', |
|
655 |
'page_uris', |
|
656 |
'update_core', |
|
657 |
'update_plugins', |
|
658 |
'update_themes', |
|
659 |
'doing_cron', |
|
660 |
'random_seed', |
|
661 |
'rss_excerpt_length', |
|
662 |
'secret', |
|
663 |
'use_linksupdate', |
|
664 |
'default_comment_status_page', |
|
665 |
'wporg_popular_tags', |
|
666 |
'what_to_show', |
|
667 |
'rss_language', |
|
668 |
'language', |
|
669 |
'enable_xmlrpc', |
|
670 |
'enable_app', |
|
671 |
'embed_autourls', |
|
672 |
'default_post_edit_rows', |
|
673 |
'gzipcompression', |
|
674 |
'advanced_edit', |
|
0 | 675 |
); |
9 | 676 |
foreach ( $unusedoptions as $option ) { |
677 |
delete_option( $option ); |
|
678 |
} |
|
0 | 679 |
|
5 | 680 |
// Delete obsolete magpie stuff. |
9 | 681 |
$wpdb->query( "DELETE FROM $wpdb->options WHERE option_name REGEXP '^rss_[0-9a-f]{32}(_ts)?$'" ); |
0 | 682 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
683 |
// Clear expired transients |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
684 |
delete_expired_transients( true ); |
0 | 685 |
} |
686 |
||
687 |
/** |
|
688 |
* Execute WordPress role creation for the various WordPress versions. |
|
689 |
* |
|
690 |
* @since 2.0.0 |
|
691 |
*/ |
|
692 |
function populate_roles() { |
|
693 |
populate_roles_160(); |
|
694 |
populate_roles_210(); |
|
695 |
populate_roles_230(); |
|
696 |
populate_roles_250(); |
|
697 |
populate_roles_260(); |
|
698 |
populate_roles_270(); |
|
699 |
populate_roles_280(); |
|
700 |
populate_roles_300(); |
|
701 |
} |
|
702 |
||
703 |
/** |
|
704 |
* Create the roles for WordPress 2.0 |
|
705 |
* |
|
706 |
* @since 2.0.0 |
|
707 |
*/ |
|
708 |
function populate_roles_160() { |
|
709 |
// Add roles |
|
710 |
||
9 | 711 |
add_role( 'administrator', 'Administrator' ); |
712 |
add_role( 'editor', 'Editor' ); |
|
713 |
add_role( 'author', 'Author' ); |
|
714 |
add_role( 'contributor', 'Contributor' ); |
|
715 |
add_role( 'subscriber', 'Subscriber' ); |
|
0 | 716 |
|
717 |
// Add caps for Administrator role |
|
9 | 718 |
$role = get_role( 'administrator' ); |
719 |
$role->add_cap( 'switch_themes' ); |
|
720 |
$role->add_cap( 'edit_themes' ); |
|
721 |
$role->add_cap( 'activate_plugins' ); |
|
722 |
$role->add_cap( 'edit_plugins' ); |
|
723 |
$role->add_cap( 'edit_users' ); |
|
724 |
$role->add_cap( 'edit_files' ); |
|
725 |
$role->add_cap( 'manage_options' ); |
|
726 |
$role->add_cap( 'moderate_comments' ); |
|
727 |
$role->add_cap( 'manage_categories' ); |
|
728 |
$role->add_cap( 'manage_links' ); |
|
729 |
$role->add_cap( 'upload_files' ); |
|
730 |
$role->add_cap( 'import' ); |
|
731 |
$role->add_cap( 'unfiltered_html' ); |
|
732 |
$role->add_cap( 'edit_posts' ); |
|
733 |
$role->add_cap( 'edit_others_posts' ); |
|
734 |
$role->add_cap( 'edit_published_posts' ); |
|
735 |
$role->add_cap( 'publish_posts' ); |
|
736 |
$role->add_cap( 'edit_pages' ); |
|
737 |
$role->add_cap( 'read' ); |
|
738 |
$role->add_cap( 'level_10' ); |
|
739 |
$role->add_cap( 'level_9' ); |
|
740 |
$role->add_cap( 'level_8' ); |
|
741 |
$role->add_cap( 'level_7' ); |
|
742 |
$role->add_cap( 'level_6' ); |
|
743 |
$role->add_cap( 'level_5' ); |
|
744 |
$role->add_cap( 'level_4' ); |
|
745 |
$role->add_cap( 'level_3' ); |
|
746 |
$role->add_cap( 'level_2' ); |
|
747 |
$role->add_cap( 'level_1' ); |
|
748 |
$role->add_cap( 'level_0' ); |
|
0 | 749 |
|
750 |
// Add caps for Editor role |
|
9 | 751 |
$role = get_role( 'editor' ); |
752 |
$role->add_cap( 'moderate_comments' ); |
|
753 |
$role->add_cap( 'manage_categories' ); |
|
754 |
$role->add_cap( 'manage_links' ); |
|
755 |
$role->add_cap( 'upload_files' ); |
|
756 |
$role->add_cap( 'unfiltered_html' ); |
|
757 |
$role->add_cap( 'edit_posts' ); |
|
758 |
$role->add_cap( 'edit_others_posts' ); |
|
759 |
$role->add_cap( 'edit_published_posts' ); |
|
760 |
$role->add_cap( 'publish_posts' ); |
|
761 |
$role->add_cap( 'edit_pages' ); |
|
762 |
$role->add_cap( 'read' ); |
|
763 |
$role->add_cap( 'level_7' ); |
|
764 |
$role->add_cap( 'level_6' ); |
|
765 |
$role->add_cap( 'level_5' ); |
|
766 |
$role->add_cap( 'level_4' ); |
|
767 |
$role->add_cap( 'level_3' ); |
|
768 |
$role->add_cap( 'level_2' ); |
|
769 |
$role->add_cap( 'level_1' ); |
|
770 |
$role->add_cap( 'level_0' ); |
|
0 | 771 |
|
772 |
// Add caps for Author role |
|
9 | 773 |
$role = get_role( 'author' ); |
774 |
$role->add_cap( 'upload_files' ); |
|
775 |
$role->add_cap( 'edit_posts' ); |
|
776 |
$role->add_cap( 'edit_published_posts' ); |
|
777 |
$role->add_cap( 'publish_posts' ); |
|
778 |
$role->add_cap( 'read' ); |
|
779 |
$role->add_cap( 'level_2' ); |
|
780 |
$role->add_cap( 'level_1' ); |
|
781 |
$role->add_cap( 'level_0' ); |
|
0 | 782 |
|
783 |
// Add caps for Contributor role |
|
9 | 784 |
$role = get_role( 'contributor' ); |
785 |
$role->add_cap( 'edit_posts' ); |
|
786 |
$role->add_cap( 'read' ); |
|
787 |
$role->add_cap( 'level_1' ); |
|
788 |
$role->add_cap( 'level_0' ); |
|
0 | 789 |
|
790 |
// Add caps for Subscriber role |
|
9 | 791 |
$role = get_role( 'subscriber' ); |
792 |
$role->add_cap( 'read' ); |
|
793 |
$role->add_cap( 'level_0' ); |
|
0 | 794 |
} |
795 |
||
796 |
/** |
|
797 |
* Create and modify WordPress roles for WordPress 2.1. |
|
798 |
* |
|
799 |
* @since 2.1.0 |
|
800 |
*/ |
|
801 |
function populate_roles_210() { |
|
9 | 802 |
$roles = array( 'administrator', 'editor' ); |
803 |
foreach ( $roles as $role ) { |
|
804 |
$role = get_role( $role ); |
|
805 |
if ( empty( $role ) ) { |
|
0 | 806 |
continue; |
9 | 807 |
} |
0 | 808 |
|
9 | 809 |
$role->add_cap( 'edit_others_pages' ); |
810 |
$role->add_cap( 'edit_published_pages' ); |
|
811 |
$role->add_cap( 'publish_pages' ); |
|
812 |
$role->add_cap( 'delete_pages' ); |
|
813 |
$role->add_cap( 'delete_others_pages' ); |
|
814 |
$role->add_cap( 'delete_published_pages' ); |
|
815 |
$role->add_cap( 'delete_posts' ); |
|
816 |
$role->add_cap( 'delete_others_posts' ); |
|
817 |
$role->add_cap( 'delete_published_posts' ); |
|
818 |
$role->add_cap( 'delete_private_posts' ); |
|
819 |
$role->add_cap( 'edit_private_posts' ); |
|
820 |
$role->add_cap( 'read_private_posts' ); |
|
821 |
$role->add_cap( 'delete_private_pages' ); |
|
822 |
$role->add_cap( 'edit_private_pages' ); |
|
823 |
$role->add_cap( 'read_private_pages' ); |
|
0 | 824 |
} |
825 |
||
9 | 826 |
$role = get_role( 'administrator' ); |
827 |
if ( ! empty( $role ) ) { |
|
828 |
$role->add_cap( 'delete_users' ); |
|
829 |
$role->add_cap( 'create_users' ); |
|
0 | 830 |
} |
831 |
||
9 | 832 |
$role = get_role( 'author' ); |
833 |
if ( ! empty( $role ) ) { |
|
834 |
$role->add_cap( 'delete_posts' ); |
|
835 |
$role->add_cap( 'delete_published_posts' ); |
|
0 | 836 |
} |
837 |
||
9 | 838 |
$role = get_role( 'contributor' ); |
839 |
if ( ! empty( $role ) ) { |
|
840 |
$role->add_cap( 'delete_posts' ); |
|
0 | 841 |
} |
842 |
} |
|
843 |
||
844 |
/** |
|
845 |
* Create and modify WordPress roles for WordPress 2.3. |
|
846 |
* |
|
847 |
* @since 2.3.0 |
|
848 |
*/ |
|
849 |
function populate_roles_230() { |
|
850 |
$role = get_role( 'administrator' ); |
|
851 |
||
9 | 852 |
if ( ! empty( $role ) ) { |
0 | 853 |
$role->add_cap( 'unfiltered_upload' ); |
854 |
} |
|
855 |
} |
|
856 |
||
857 |
/** |
|
858 |
* Create and modify WordPress roles for WordPress 2.5. |
|
859 |
* |
|
860 |
* @since 2.5.0 |
|
861 |
*/ |
|
862 |
function populate_roles_250() { |
|
863 |
$role = get_role( 'administrator' ); |
|
864 |
||
9 | 865 |
if ( ! empty( $role ) ) { |
0 | 866 |
$role->add_cap( 'edit_dashboard' ); |
867 |
} |
|
868 |
} |
|
869 |
||
870 |
/** |
|
871 |
* Create and modify WordPress roles for WordPress 2.6. |
|
872 |
* |
|
873 |
* @since 2.6.0 |
|
874 |
*/ |
|
875 |
function populate_roles_260() { |
|
876 |
$role = get_role( 'administrator' ); |
|
877 |
||
9 | 878 |
if ( ! empty( $role ) ) { |
0 | 879 |
$role->add_cap( 'update_plugins' ); |
880 |
$role->add_cap( 'delete_plugins' ); |
|
881 |
} |
|
882 |
} |
|
883 |
||
884 |
/** |
|
885 |
* Create and modify WordPress roles for WordPress 2.7. |
|
886 |
* |
|
887 |
* @since 2.7.0 |
|
888 |
*/ |
|
889 |
function populate_roles_270() { |
|
890 |
$role = get_role( 'administrator' ); |
|
891 |
||
9 | 892 |
if ( ! empty( $role ) ) { |
0 | 893 |
$role->add_cap( 'install_plugins' ); |
894 |
$role->add_cap( 'update_themes' ); |
|
895 |
} |
|
896 |
} |
|
897 |
||
898 |
/** |
|
899 |
* Create and modify WordPress roles for WordPress 2.8. |
|
900 |
* |
|
901 |
* @since 2.8.0 |
|
902 |
*/ |
|
903 |
function populate_roles_280() { |
|
904 |
$role = get_role( 'administrator' ); |
|
905 |
||
9 | 906 |
if ( ! empty( $role ) ) { |
0 | 907 |
$role->add_cap( 'install_themes' ); |
908 |
} |
|
909 |
} |
|
910 |
||
911 |
/** |
|
912 |
* Create and modify WordPress roles for WordPress 3.0. |
|
913 |
* |
|
914 |
* @since 3.0.0 |
|
915 |
*/ |
|
916 |
function populate_roles_300() { |
|
917 |
$role = get_role( 'administrator' ); |
|
918 |
||
9 | 919 |
if ( ! empty( $role ) ) { |
0 | 920 |
$role->add_cap( 'update_core' ); |
921 |
$role->add_cap( 'list_users' ); |
|
922 |
$role->add_cap( 'remove_users' ); |
|
923 |
$role->add_cap( 'promote_users' ); |
|
924 |
$role->add_cap( 'edit_theme_options' ); |
|
925 |
$role->add_cap( 'delete_themes' ); |
|
926 |
$role->add_cap( 'export' ); |
|
927 |
} |
|
928 |
} |
|
929 |
||
9 | 930 |
if ( ! function_exists( 'install_network' ) ) : |
931 |
/** |
|
932 |
* Install Network. |
|
933 |
* |
|
934 |
* @since 3.0.0 |
|
935 |
*/ |
|
936 |
function install_network() { |
|
937 |
if ( ! defined( 'WP_INSTALLING_NETWORK' ) ) { |
|
938 |
define( 'WP_INSTALLING_NETWORK', true ); |
|
939 |
} |
|
0 | 940 |
|
9 | 941 |
dbDelta( wp_get_db_schema( 'global' ) ); |
942 |
} |
|
0 | 943 |
endif; |
944 |
||
945 |
/** |
|
5 | 946 |
* Populate network settings. |
0 | 947 |
* |
948 |
* @since 3.0.0 |
|
949 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
950 |
* @global wpdb $wpdb |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
951 |
* @global object $current_site |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
952 |
* @global WP_Rewrite $wp_rewrite |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
953 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
954 |
* @param int $network_id ID of network to populate. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
955 |
* @param string $domain The domain name for the network (eg. "example.com"). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
956 |
* @param string $email Email address for the network administrator. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
957 |
* @param string $site_name The name of the network. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
958 |
* @param string $path Optional. The path to append to the network's domain name. Default '/'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
959 |
* @param bool $subdomain_install Optional. Whether the network is a subdomain installation or a subdirectory installation. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
960 |
* Default false, meaning the network is a subdirectory installation. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
961 |
* @return bool|WP_Error True on success, or WP_Error on warning (with the installation otherwise successful, |
5 | 962 |
* so the error code must be checked) or failure. |
0 | 963 |
*/ |
964 |
function populate_network( $network_id = 1, $domain = '', $email = '', $site_name = '', $path = '/', $subdomain_install = false ) { |
|
9 | 965 |
global $wpdb, $current_site, $wp_rewrite; |
0 | 966 |
|
967 |
$errors = new WP_Error(); |
|
9 | 968 |
if ( '' == $domain ) { |
0 | 969 |
$errors->add( 'empty_domain', __( 'You must provide a domain name.' ) ); |
9 | 970 |
} |
971 |
if ( '' == $site_name ) { |
|
0 | 972 |
$errors->add( 'empty_sitename', __( 'You must provide a name for your network of sites.' ) ); |
9 | 973 |
} |
0 | 974 |
|
5 | 975 |
// Check for network collision. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
976 |
$network_exists = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
977 |
if ( is_multisite() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
978 |
if ( get_network( (int) $network_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
979 |
$errors->add( 'siteid_exists', __( 'The network already exists.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
980 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
981 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
982 |
if ( $network_id == $wpdb->get_var( $wpdb->prepare( "SELECT id FROM $wpdb->site WHERE id = %d", $network_id ) ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
983 |
$errors->add( 'siteid_exists', __( 'The network already exists.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
984 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
985 |
} |
0 | 986 |
|
9 | 987 |
if ( ! is_email( $email ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
988 |
$errors->add( 'invalid_email', __( 'You must provide a valid email address.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
989 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
990 |
|
9 | 991 |
if ( $errors->has_errors() ) { |
992 |
return $errors; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
993 |
} |
0 | 994 |
|
995 |
if ( 1 == $network_id ) { |
|
9 | 996 |
$wpdb->insert( |
997 |
$wpdb->site, |
|
998 |
array( |
|
999 |
'domain' => $domain, |
|
1000 |
'path' => $path, |
|
1001 |
) |
|
1002 |
); |
|
0 | 1003 |
$network_id = $wpdb->insert_id; |
1004 |
} else { |
|
9 | 1005 |
$wpdb->insert( |
1006 |
$wpdb->site, |
|
1007 |
array( |
|
1008 |
'domain' => $domain, |
|
1009 |
'path' => $path, |
|
1010 |
'id' => $network_id, |
|
1011 |
) |
|
1012 |
); |
|
0 | 1013 |
} |
1014 |
||
9 | 1015 |
populate_network_meta( |
1016 |
$network_id, |
|
1017 |
array( |
|
1018 |
'admin_email' => $email, |
|
1019 |
'site_name' => $site_name, |
|
1020 |
'subdomain_install' => $subdomain_install, |
|
1021 |
) |
|
5 | 1022 |
); |
1023 |
||
9 | 1024 |
$site_user = get_userdata( (int) $wpdb->get_var( $wpdb->prepare( "SELECT meta_value FROM $wpdb->sitemeta WHERE meta_key = %s AND site_id = %d", 'admin_user_id', $network_id ) ) ); |
0 | 1025 |
|
5 | 1026 |
/* |
1027 |
* When upgrading from single to multisite, assume the current site will |
|
1028 |
* become the main site of the network. When using populate_network() |
|
1029 |
* to create another network in an existing multisite environment, skip |
|
1030 |
* these steps since the main site of the new network has not yet been |
|
1031 |
* created. |
|
1032 |
*/ |
|
0 | 1033 |
if ( ! is_multisite() ) { |
9 | 1034 |
$current_site = new stdClass; |
1035 |
$current_site->domain = $domain; |
|
1036 |
$current_site->path = $path; |
|
0 | 1037 |
$current_site->site_name = ucfirst( $domain ); |
9 | 1038 |
$wpdb->insert( |
1039 |
$wpdb->blogs, |
|
1040 |
array( |
|
1041 |
'site_id' => $network_id, |
|
1042 |
'blog_id' => 1, |
|
1043 |
'domain' => $domain, |
|
1044 |
'path' => $path, |
|
1045 |
'registered' => current_time( 'mysql' ), |
|
1046 |
) |
|
1047 |
); |
|
1048 |
$current_site->blog_id = $wpdb->insert_id; |
|
0 | 1049 |
update_user_meta( $site_user->ID, 'source_domain', $domain ); |
9 | 1050 |
update_user_meta( $site_user->ID, 'primary_blog', $current_site->blog_id ); |
0 | 1051 |
|
9 | 1052 |
if ( $subdomain_install ) { |
0 | 1053 |
$wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); |
9 | 1054 |
} else { |
0 | 1055 |
$wp_rewrite->set_permalink_structure( '/blog/%year%/%monthnum%/%day%/%postname%/' ); |
9 | 1056 |
} |
0 | 1057 |
|
1058 |
flush_rewrite_rules(); |
|
1059 |
||
9 | 1060 |
if ( ! $subdomain_install ) { |
0 | 1061 |
return true; |
9 | 1062 |
} |
0 | 1063 |
|
1064 |
$vhost_ok = false; |
|
9 | 1065 |
$errstr = ''; |
0 | 1066 |
$hostname = substr( md5( time() ), 0, 6 ) . '.' . $domain; // Very random hostname! |
9 | 1067 |
$page = wp_remote_get( |
1068 |
'http://' . $hostname, |
|
1069 |
array( |
|
1070 |
'timeout' => 5, |
|
1071 |
'httpversion' => '1.1', |
|
1072 |
) |
|
1073 |
); |
|
1074 |
if ( is_wp_error( $page ) ) { |
|
0 | 1075 |
$errstr = $page->get_error_message(); |
9 | 1076 |
} elseif ( 200 == wp_remote_retrieve_response_code( $page ) ) { |
0 | 1077 |
$vhost_ok = true; |
9 | 1078 |
} |
0 | 1079 |
|
1080 |
if ( ! $vhost_ok ) { |
|
1081 |
$msg = '<p><strong>' . __( 'Warning! Wildcard DNS may not be configured correctly!' ) . '</strong></p>'; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1082 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1083 |
$msg .= '<p>' . sprintf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1084 |
/* translators: %s: host name */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1085 |
__( 'The installer attempted to contact a random hostname (%s) on your domain.' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1086 |
'<code>' . $hostname . '</code>' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1087 |
); |
9 | 1088 |
if ( ! empty( $errstr ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1089 |
/* translators: %s: error message */ |
0 | 1090 |
$msg .= ' ' . sprintf( __( 'This resulted in an error message: %s' ), '<code>' . $errstr . '</code>' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1091 |
} |
0 | 1092 |
$msg .= '</p>'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1093 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1094 |
$msg .= '<p>' . sprintf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1095 |
/* translators: %s: asterisk symbol (*) */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1096 |
__( 'To use a subdomain configuration, you must have a wildcard entry in your DNS. This usually means adding a %s hostname record pointing at your web server in your DNS configuration tool.' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1097 |
'<code>*</code>' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1098 |
) . '</p>'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1099 |
|
0 | 1100 |
$msg .= '<p>' . __( 'You can still use your site but any subdomain you create may not be accessible. If you know your DNS is correct, ignore this message.' ) . '</p>'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1101 |
|
0 | 1102 |
return new WP_Error( 'no_wildcard_dns', $msg ); |
1103 |
} |
|
1104 |
} |
|
1105 |
||
1106 |
return true; |
|
1107 |
} |
|
9 | 1108 |
|
1109 |
/** |
|
1110 |
* Creates WordPress network meta and sets the default values. |
|
1111 |
* |
|
1112 |
* @since 5.1.0 |
|
1113 |
* |
|
1114 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
1115 |
* @global int $wp_db_version WordPress database version. |
|
1116 |
* |
|
1117 |
* @param int $network_id Network ID to populate meta for. |
|
1118 |
* @param array $meta Optional. Custom meta $key => $value pairs to use. Default empty array. |
|
1119 |
*/ |
|
1120 |
function populate_network_meta( $network_id, array $meta = array() ) { |
|
1121 |
global $wpdb, $wp_db_version; |
|
1122 |
||
1123 |
$network_id = (int) $network_id; |
|
1124 |
||
1125 |
$email = ! empty( $meta['admin_email'] ) ? $meta['admin_email'] : ''; |
|
1126 |
$subdomain_install = isset( $meta['subdomain_install'] ) ? (int) $meta['subdomain_install'] : 0; |
|
1127 |
||
1128 |
// If a user with the provided email does not exist, default to the current user as the new network admin. |
|
1129 |
$site_user = ! empty( $email ) ? get_user_by( 'email', $email ) : false; |
|
1130 |
if ( false === $site_user ) { |
|
1131 |
$site_user = wp_get_current_user(); |
|
1132 |
} |
|
1133 |
||
1134 |
if ( empty( $email ) ) { |
|
1135 |
$email = $site_user->user_email; |
|
1136 |
} |
|
1137 |
||
1138 |
$template = get_option( 'template' ); |
|
1139 |
$stylesheet = get_option( 'stylesheet' ); |
|
1140 |
$allowed_themes = array( $stylesheet => true ); |
|
1141 |
||
1142 |
if ( $template != $stylesheet ) { |
|
1143 |
$allowed_themes[ $template ] = true; |
|
1144 |
} |
|
1145 |
||
1146 |
if ( WP_DEFAULT_THEME != $stylesheet && WP_DEFAULT_THEME != $template ) { |
|
1147 |
$allowed_themes[ WP_DEFAULT_THEME ] = true; |
|
1148 |
} |
|
1149 |
||
1150 |
// If WP_DEFAULT_THEME doesn't exist, also whitelist the latest core default theme. |
|
1151 |
if ( ! wp_get_theme( WP_DEFAULT_THEME )->exists() ) { |
|
1152 |
$core_default = WP_Theme::get_core_default_theme(); |
|
1153 |
if ( $core_default ) { |
|
1154 |
$allowed_themes[ $core_default->get_stylesheet() ] = true; |
|
1155 |
} |
|
1156 |
} |
|
1157 |
||
1158 |
wp_cache_delete( 'networks_have_paths', 'site-options' ); |
|
1159 |
||
1160 |
if ( ! is_multisite() ) { |
|
1161 |
$site_admins = array( $site_user->user_login ); |
|
1162 |
$users = get_users( |
|
1163 |
array( |
|
1164 |
'fields' => array( 'user_login' ), |
|
1165 |
'role' => 'administrator', |
|
1166 |
) |
|
1167 |
); |
|
1168 |
if ( $users ) { |
|
1169 |
foreach ( $users as $user ) { |
|
1170 |
$site_admins[] = $user->user_login; |
|
1171 |
} |
|
1172 |
||
1173 |
$site_admins = array_unique( $site_admins ); |
|
1174 |
} |
|
1175 |
} else { |
|
1176 |
$site_admins = get_site_option( 'site_admins' ); |
|
1177 |
} |
|
1178 |
||
1179 |
/* translators: Do not translate USERNAME, SITE_NAME, BLOG_URL, PASSWORD: those are placeholders. */ |
|
1180 |
$welcome_email = __( |
|
1181 |
'Howdy USERNAME, |
|
1182 |
||
1183 |
Your new SITE_NAME site has been successfully set up at: |
|
1184 |
BLOG_URL |
|
1185 |
||
1186 |
You can log in to the administrator account with the following information: |
|
1187 |
||
1188 |
Username: USERNAME |
|
1189 |
Password: PASSWORD |
|
1190 |
Log in here: BLOG_URLwp-login.php |
|
1191 |
||
1192 |
We hope you enjoy your new site. Thanks! |
|
1193 |
||
1194 |
--The Team @ SITE_NAME' |
|
1195 |
); |
|
1196 |
||
1197 |
$misc_exts = array( |
|
1198 |
// Images. |
|
1199 |
'jpg', |
|
1200 |
'jpeg', |
|
1201 |
'png', |
|
1202 |
'gif', |
|
1203 |
// Video. |
|
1204 |
'mov', |
|
1205 |
'avi', |
|
1206 |
'mpg', |
|
1207 |
'3gp', |
|
1208 |
'3g2', |
|
1209 |
// "audio". |
|
1210 |
'midi', |
|
1211 |
'mid', |
|
1212 |
// Miscellaneous. |
|
1213 |
'pdf', |
|
1214 |
'doc', |
|
1215 |
'ppt', |
|
1216 |
'odt', |
|
1217 |
'pptx', |
|
1218 |
'docx', |
|
1219 |
'pps', |
|
1220 |
'ppsx', |
|
1221 |
'xls', |
|
1222 |
'xlsx', |
|
1223 |
'key', |
|
1224 |
); |
|
1225 |
$audio_exts = wp_get_audio_extensions(); |
|
1226 |
$video_exts = wp_get_video_extensions(); |
|
1227 |
$upload_filetypes = array_unique( array_merge( $misc_exts, $audio_exts, $video_exts ) ); |
|
1228 |
||
1229 |
$sitemeta = array( |
|
1230 |
'site_name' => __( 'My Network' ), |
|
1231 |
'admin_email' => $email, |
|
1232 |
'admin_user_id' => $site_user->ID, |
|
1233 |
'registration' => 'none', |
|
1234 |
'upload_filetypes' => implode( ' ', $upload_filetypes ), |
|
1235 |
'blog_upload_space' => 100, |
|
1236 |
'fileupload_maxk' => 1500, |
|
1237 |
'site_admins' => $site_admins, |
|
1238 |
'allowedthemes' => $allowed_themes, |
|
1239 |
'illegal_names' => array( 'www', 'web', 'root', 'admin', 'main', 'invite', 'administrator', 'files' ), |
|
1240 |
'wpmu_upgrade_site' => $wp_db_version, |
|
1241 |
'welcome_email' => $welcome_email, |
|
1242 |
/* translators: %s: site link */ |
|
1243 |
'first_post' => __( 'Welcome to %s. This is your first post. Edit or delete it, then start writing!' ), |
|
1244 |
// @todo - network admins should have a method of editing the network siteurl (used for cookie hash) |
|
1245 |
'siteurl' => get_option( 'siteurl' ) . '/', |
|
1246 |
'add_new_users' => '0', |
|
1247 |
'upload_space_check_disabled' => is_multisite() ? get_site_option( 'upload_space_check_disabled' ) : '1', |
|
1248 |
'subdomain_install' => $subdomain_install, |
|
1249 |
'global_terms_enabled' => global_terms_enabled() ? '1' : '0', |
|
1250 |
'ms_files_rewriting' => is_multisite() ? get_site_option( 'ms_files_rewriting' ) : '0', |
|
1251 |
'initial_db_version' => get_option( 'initial_db_version' ), |
|
1252 |
'active_sitewide_plugins' => array(), |
|
1253 |
'WPLANG' => get_locale(), |
|
1254 |
); |
|
1255 |
if ( ! $subdomain_install ) { |
|
1256 |
$sitemeta['illegal_names'][] = 'blog'; |
|
1257 |
} |
|
1258 |
||
1259 |
$sitemeta = wp_parse_args( $meta, $sitemeta ); |
|
1260 |
||
1261 |
/** |
|
1262 |
* Filters meta for a network on creation. |
|
1263 |
* |
|
1264 |
* @since 3.7.0 |
|
1265 |
* |
|
1266 |
* @param array $sitemeta Associative array of network meta keys and values to be inserted. |
|
1267 |
* @param int $network_id ID of network to populate. |
|
1268 |
*/ |
|
1269 |
$sitemeta = apply_filters( 'populate_network_meta', $sitemeta, $network_id ); |
|
1270 |
||
1271 |
$insert = ''; |
|
1272 |
foreach ( $sitemeta as $meta_key => $meta_value ) { |
|
1273 |
if ( is_array( $meta_value ) ) { |
|
1274 |
$meta_value = serialize( $meta_value ); |
|
1275 |
} |
|
1276 |
if ( ! empty( $insert ) ) { |
|
1277 |
$insert .= ', '; |
|
1278 |
} |
|
1279 |
$insert .= $wpdb->prepare( '( %d, %s, %s)', $network_id, $meta_key, $meta_value ); |
|
1280 |
} |
|
1281 |
$wpdb->query( "INSERT INTO $wpdb->sitemeta ( site_id, meta_key, meta_value ) VALUES " . $insert ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
1282 |
} |
|
1283 |
||
1284 |
/** |
|
1285 |
* Creates WordPress site meta and sets the default values. |
|
1286 |
* |
|
1287 |
* @since 5.1.0 |
|
1288 |
* |
|
1289 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
1290 |
* |
|
1291 |
* @param int $site_id Site ID to populate meta for. |
|
1292 |
* @param array $meta Optional. Custom meta $key => $value pairs to use. Default empty array. |
|
1293 |
*/ |
|
1294 |
function populate_site_meta( $site_id, array $meta = array() ) { |
|
1295 |
global $wpdb; |
|
1296 |
||
1297 |
$site_id = (int) $site_id; |
|
1298 |
||
1299 |
if ( ! is_site_meta_supported() ) { |
|
1300 |
return; |
|
1301 |
} |
|
1302 |
||
1303 |
if ( empty( $meta ) ) { |
|
1304 |
return; |
|
1305 |
} |
|
1306 |
||
1307 |
/** |
|
1308 |
* Filters meta for a site on creation. |
|
1309 |
* |
|
1310 |
* @since 5.2.0 |
|
1311 |
* |
|
1312 |
* @param array $meta Associative array of site meta keys and values to be inserted. |
|
1313 |
* @param int $site_id ID of site to populate. |
|
1314 |
*/ |
|
1315 |
$site_meta = apply_filters( 'populate_site_meta', $meta, $site_id ); |
|
1316 |
||
1317 |
$insert = ''; |
|
1318 |
foreach ( $site_meta as $meta_key => $meta_value ) { |
|
1319 |
if ( is_array( $meta_value ) ) { |
|
1320 |
$meta_value = serialize( $meta_value ); |
|
1321 |
} |
|
1322 |
if ( ! empty( $insert ) ) { |
|
1323 |
$insert .= ', '; |
|
1324 |
} |
|
1325 |
$insert .= $wpdb->prepare( '( %d, %s, %s)', $site_id, $meta_key, $meta_value ); |
|
1326 |
} |
|
1327 |
||
1328 |
$wpdb->query( "INSERT INTO $wpdb->blogmeta ( blog_id, meta_key, meta_value ) VALUES " . $insert ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
1329 |
||
1330 |
wp_cache_delete( $site_id, 'blog_meta' ); |
|
1331 |
wp_cache_set_sites_last_changed(); |
|
1332 |
} |