mirrored from git://develop.git.wordpress.org/
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
Copy pathupgrade.php
3530 lines (3065 loc) · 107 KB
/
upgrade.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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* WordPress Upgrade API
*
* Most of the functions are pluggable and can be overwritten.
*
* @package WordPress
* @subpackage Administration
*/
/** Include user installation customization script. */
if ( file_exists( WP_CONTENT_DIR . '/install.php' ) ) {
require WP_CONTENT_DIR . '/install.php';
}
/** WordPress Administration API */
require_once ABSPATH . 'wp-admin/includes/admin.php';
/** WordPress Schema API */
require_once ABSPATH . 'wp-admin/includes/schema.php';
if ( ! function_exists( 'wp_install' ) ) :
/**
* Installs the site.
*
* Runs the required functions to set up and populate the database,
* including primary admin user and initial options.
*
* @since 2.1.0
*
* @param string $blog_title Site title.
* @param string $user_name User's username.
* @param string $user_email User's email.
* @param bool $public Whether site 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 {
* Data for the newly installed site.
*
* @type string $url The URL of the site.
* @type int $user_id The ID of the site owner.
* @type string $password The password of the site owner, if their user account didn't already exist.
* @type string $password_message The explanatory message regarding the password.
* }
*/
function wp_install( $blog_title, $user_name, $user_email, $public, $deprecated = '', $user_password = '', $language = '' ) {
if ( ! empty( $deprecated ) ) {
_deprecated_argument( __FUNCTION__, '2.6.0' );
}
wp_check_mysql_version();
wp_cache_flush();
make_db_current_silent();
populate_options();
populate_roles();
update_option( 'blogname', $blog_title );
update_option( 'admin_email', $user_email );
update_option( 'blog_public', $public );
// Freshness of site - in the future, this could get more specific about actions taken, perhaps.
update_option( 'fresh_site', 1 );
if ( $language ) {
update_option( 'WPLANG', $language );
}
$guessurl = wp_guess_url();
update_option( 'siteurl', $guessurl );
// If not a public site, 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 sites. Just set the role in that case.
*/
$user_id = username_exists( $user_name );
$user_password = trim( $user_password );
$email_password = false;
$user_created = 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_meta( $user_id, 'default_password_nag', true );
$email_password = true;
$user_created = 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 );
$user_created = true;
} else {
$message = __( 'User already exists. Password inherited.' );
}
$user = new WP_User( $user_id );
$user->set_role( 'administrator' );
if ( $user_created ) {
$user->user_url = $guessurl;
wp_update_user( $user );
}
wp_install_defaults( $user_id );
wp_install_maybe_enable_pretty_permalinks();
flush_rewrite_rules();
wp_new_blog_notification( $blog_title, $guessurl, $user_id, ( $email_password ? $user_password : __( 'The password you chose during installation.' ) ) );
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 array(
'url' => $guessurl,
'user_id' => $user_id,
'password' => $user_password,
'password_message' => $message,
);
}
endif;
if ( ! function_exists( 'wp_install_defaults' ) ) :
/**
* 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 2.1.0
*
* @global wpdb $wpdb WordPress database abstraction object.
* @global WP_Rewrite $wp_rewrite WordPress rewrite component.
* @global string $table_prefix
*
* @param int $user_id User ID.
*/
function wp_install_defaults( $user_id ) {
global $wpdb, $wp_rewrite, $table_prefix;
// Default category.
$cat_name = __( 'Uncategorized' );
/* translators: Default category slug. */
$cat_slug = sanitize_title( _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,
array(
'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,
array(
'term_id' => $cat_id,
'name' => $cat_name,
'slug' => $cat_slug,
'term_group' => 0,
)
);
$wpdb->insert(
$wpdb->term_taxonomy,
array(
'term_id' => $cat_id,
'taxonomy' => 'category',
'description' => '',
'parent' => 0,
'count' => 1,
)
);
$cat_tt_id = $wpdb->insert_id;
// First post.
$now = current_time( 'mysql' );
$now_gmt = current_time( 'mysql', 1 );
$first_post_guid = get_option( 'home' ) . '/?p=1';
if ( is_multisite() ) {
$first_post = get_site_option( 'first_post' );
if ( ! $first_post ) {
$first_post = "<!-- wp:paragraph -->\n<p>" .
/* translators: First post content. %s: Site link. */
__( 'Welcome to %s. This is your first post. Edit or delete it, then start writing!' ) .
"</p>\n<!-- /wp:paragraph -->";
}
$first_post = sprintf(
$first_post,
sprintf( '<a href="%s">%s</a>', esc_url( network_home_url() ), get_network()->site_name )
);
// Back-compat for pre-4.4.
$first_post = str_replace( 'SITE_URL', esc_url( network_home_url() ), $first_post );
$first_post = str_replace( 'SITE_NAME', get_network()->site_name, $first_post );
} else {
$first_post = "<!-- wp:paragraph -->\n<p>" .
/* translators: First post content. %s: Site link. */
__( 'Welcome to WordPress. This is your first post. Edit or delete it, then start writing!' ) .
"</p>\n<!-- /wp:paragraph -->";
}
$wpdb->insert(
$wpdb->posts,
array(
'post_author' => $user_id,
'post_date' => $now,
'post_date_gmt' => $now_gmt,
'post_content' => $first_post,
'post_excerpt' => '',
'post_title' => __( 'Hello world!' ),
/* translators: Default post slug. */
'post_name' => sanitize_title( _x( 'hello-world', 'Default post slug' ) ),
'post_modified' => $now,
'post_modified_gmt' => $now_gmt,
'guid' => $first_post_guid,
'comment_count' => 1,
'to_ping' => '',
'pinged' => '',
'post_content_filtered' => '',
)
);
$wpdb->insert(
$wpdb->term_relationships,
array(
'term_taxonomy_id' => $cat_tt_id,
'object_id' => 1,
)
);
// Default comment.
if ( is_multisite() ) {
$first_comment_author = get_site_option( 'first_comment_author' );
$first_comment_email = get_site_option( 'first_comment_email' );
$first_comment_url = get_site_option( 'first_comment_url', network_home_url() );
$first_comment = get_site_option( 'first_comment' );
}
$first_comment_author = ! empty( $first_comment_author ) ? $first_comment_author : __( 'A WordPress Commenter' );
$first_comment_email = ! empty( $first_comment_email ) ? $first_comment_email : '[email protected]';
$first_comment_url = ! empty( $first_comment_url ) ? $first_comment_url : 'https://wordpress.org/';
$first_comment = ! empty( $first_comment ) ? $first_comment : __(
'Hi, this is a comment.
To get started with moderating, editing, and deleting comments, please visit the Comments screen in the dashboard.
Commenter avatars come from <a href="https://gravatar.com">Gravatar</a>.'
);
$wpdb->insert(
$wpdb->comments,
array(
'comment_post_ID' => 1,
'comment_author' => $first_comment_author,
'comment_author_email' => $first_comment_email,
'comment_author_url' => $first_comment_url,
'comment_date' => $now,
'comment_date_gmt' => $now_gmt,
'comment_content' => $first_comment,
'comment_type' => 'comment',
)
);
// First page.
if ( is_multisite() ) {
$first_page = get_site_option( 'first_page' );
}
if ( empty( $first_page ) ) {
$first_page = "<!-- wp:paragraph -->\n<p>";
/* translators: First page content. */
$first_page .= __( "This is an example page. It's different from a blog post because it will stay in one place and will show up in your site navigation (in most themes). Most people start with an About page that introduces them to potential site visitors. It might say something like this:" );
$first_page .= "</p>\n<!-- /wp:paragraph -->\n\n";
$first_page .= "<!-- wp:quote -->\n<blockquote class=\"wp-block-quote\"><p>";
/* translators: First page content. */
$first_page .= __( "Hi there! I'm a bike messenger by day, aspiring actor by night, and this is my website. I live in Los Angeles, have a great dog named Jack, and I like piña coladas. (And gettin' caught in the rain.)" );
$first_page .= "</p></blockquote>\n<!-- /wp:quote -->\n\n";
$first_page .= "<!-- wp:paragraph -->\n<p>";
/* translators: First page content. */
$first_page .= __( '...or something like this:' );
$first_page .= "</p>\n<!-- /wp:paragraph -->\n\n";
$first_page .= "<!-- wp:quote -->\n<blockquote class=\"wp-block-quote\"><p>";
/* translators: First page content. */
$first_page .= __( 'The XYZ Doohickey Company was founded in 1971, and has been providing quality doohickeys to the public ever since. Located in Gotham City, XYZ employs over 2,000 people and does all kinds of awesome things for the Gotham community.' );
$first_page .= "</p></blockquote>\n<!-- /wp:quote -->\n\n";
$first_page .= "<!-- wp:paragraph -->\n<p>";
$first_page .= sprintf(
/* translators: First page content. %s: Site admin URL. */
__( 'As a new WordPress user, you should go to <a href="%s">your dashboard</a> to delete this page and create new pages for your content. Have fun!' ),
admin_url()
);
$first_page .= "</p>\n<!-- /wp:paragraph -->";
}
$first_post_guid = get_option( 'home' ) . '/?page_id=2';
$wpdb->insert(
$wpdb->posts,
array(
'post_author' => $user_id,
'post_date' => $now,
'post_date_gmt' => $now_gmt,
'post_content' => $first_page,
'post_excerpt' => '',
'comment_status' => 'closed',
'post_title' => __( 'Sample Page' ),
/* translators: Default page slug. */
'post_name' => __( 'sample-page' ),
'post_modified' => $now,
'post_modified_gmt' => $now_gmt,
'guid' => $first_post_guid,
'post_type' => 'page',
'to_ping' => '',
'pinged' => '',
'post_content_filtered' => '',
)
);
$wpdb->insert(
$wpdb->postmeta,
array(
'post_id' => 2,
'meta_key' => '_wp_page_template',
'meta_value' => 'default',
)
);
// Privacy Policy page.
if ( is_multisite() ) {
// Disable by default unless the suggested content is provided.
$privacy_policy_content = get_site_option( 'default_privacy_policy_content' );
} else {
if ( ! class_exists( 'WP_Privacy_Policy_Content' ) ) {
include_once ABSPATH . 'wp-admin/includes/class-wp-privacy-policy-content.php';
}
$privacy_policy_content = WP_Privacy_Policy_Content::get_default_content();
}
if ( ! empty( $privacy_policy_content ) ) {
$privacy_policy_guid = get_option( 'home' ) . '/?page_id=3';
$wpdb->insert(
$wpdb->posts,
array(
'post_author' => $user_id,
'post_date' => $now,
'post_date_gmt' => $now_gmt,
'post_content' => $privacy_policy_content,
'post_excerpt' => '',
'comment_status' => 'closed',
'post_title' => __( 'Privacy Policy' ),
/* translators: Privacy Policy page slug. */
'post_name' => __( 'privacy-policy' ),
'post_modified' => $now,
'post_modified_gmt' => $now_gmt,
'guid' => $privacy_policy_guid,
'post_type' => 'page',
'post_status' => 'draft',
'to_ping' => '',
'pinged' => '',
'post_content_filtered' => '',
)
);
$wpdb->insert(
$wpdb->postmeta,
array(
'post_id' => 3,
'meta_key' => '_wp_page_template',
'meta_value' => 'default',
)
);
update_option( 'wp_page_for_privacy_policy', 3 );
}
// Set up default widgets for default theme.
update_option(
'widget_block',
array(
2 => array( 'content' => '<!-- wp:search /-->' ),
3 => array( 'content' => '<!-- wp:group --><div class="wp-block-group"><!-- wp:heading --><h2>' . __( 'Recent Posts' ) . '</h2><!-- /wp:heading --><!-- wp:latest-posts /--></div><!-- /wp:group -->' ),
4 => array( 'content' => '<!-- wp:group --><div class="wp-block-group"><!-- wp:heading --><h2>' . __( 'Recent Comments' ) . '</h2><!-- /wp:heading --><!-- wp:latest-comments {"displayAvatar":false,"displayDate":false,"displayExcerpt":false} /--></div><!-- /wp:group -->' ),
5 => array( 'content' => '<!-- wp:group --><div class="wp-block-group"><!-- wp:heading --><h2>' . __( 'Archives' ) . '</h2><!-- /wp:heading --><!-- wp:archives /--></div><!-- /wp:group -->' ),
6 => array( 'content' => '<!-- wp:group --><div class="wp-block-group"><!-- wp:heading --><h2>' . __( 'Categories' ) . '</h2><!-- /wp:heading --><!-- wp:categories /--></div><!-- /wp:group -->' ),
'_multiwidget' => 1,
)
);
update_option(
'sidebars_widgets',
array(
'wp_inactive_widgets' => array(),
'sidebar-1' => array(
0 => 'block-2',
1 => 'block-3',
2 => 'block-4',
),
'sidebar-2' => array(
0 => 'block-5',
1 => 'block-6',
),
'array_version' => 3,
)
);
if ( ! is_multisite() ) {
update_user_meta( $user_id, 'show_welcome_panel', 1 );
} elseif ( ! is_super_admin( $user_id ) && ! metadata_exists( 'user', $user_id, 'show_welcome_panel' ) ) {
update_user_meta( $user_id, 'show_welcome_panel', 2 );
}
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, array( 'option_value' => $user->user_email ), array( '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 ( ! is_super_admin( $user_id ) && 1 != $user_id ) {
$wpdb->delete(
$wpdb->usermeta,
array(
'user_id' => $user_id,
'meta_key' => $wpdb->base_prefix . '1_capabilities',
)
);
}
}
}
endif;
/**
* Maybe enable pretty permalinks on installation.
*
* If after enabling pretty permalinks don't work, fallback to query-string permalinks.
*
* @since 4.2.0
*
* @global WP_Rewrite $wp_rewrite WordPress rewrite component.
*
* @return bool Whether pretty permalinks are enabled. False otherwise.
*/
function wp_install_maybe_enable_pretty_permalinks() {
global $wp_rewrite;
// Bail if a permalink structure is already enabled.
if ( get_option( 'permalink_structure' ) ) {
return true;
}
/*
* The Permalink structures to attempt.
*
* The first is designed for mod_rewrite or nginx rewriting.
*
* The second is PATHINFO-based permalinks for web server configurations
* without a true rewrite module enabled.
*/
$permalink_structures = array(
'/%year%/%monthnum%/%day%/%postname%/',
'/index.php/%year%/%monthnum%/%day%/%postname%/',
);
foreach ( (array) $permalink_structures as $permalink_structure ) {
$wp_rewrite->set_permalink_structure( $permalink_structure );
/*
* Flush rules with the hard option to force refresh of the web-server's
* rewrite config file (e.g. .htaccess or web.config).
*/
$wp_rewrite->flush_rules( true );
$test_url = '';
// Test against a real WordPress post.
$first_post = get_page_by_path( sanitize_title( _x( 'hello-world', 'Default post slug' ) ), OBJECT, 'post' );
if ( $first_post ) {
$test_url = get_permalink( $first_post->ID );
}
/*
* Send a request to the site, and check whether
* the 'x-pingback' header is returned as expected.
*
* Uses wp_remote_get() instead of wp_remote_head() because web servers
* can block head requests.
*/
$response = wp_remote_get( $test_url, array( 'timeout' => 5 ) );
$x_pingback_header = wp_remote_retrieve_header( $response, 'x-pingback' );
$pretty_permalinks = $x_pingback_header && get_bloginfo( 'pingback_url' ) === $x_pingback_header;
if ( $pretty_permalinks ) {
return true;
}
}
/*
* If it makes it this far, pretty permalinks failed.
* Fallback to query-string permalinks.
*/
$wp_rewrite->set_permalink_structure( '' );
$wp_rewrite->flush_rules( true );
return false;
}
if ( ! function_exists( 'wp_new_blog_notification' ) ) :
/**
* Notifies the site admin that the installation of WordPress is complete.
*
* Sends an email to the new administrator that the installation is complete
* and provides them with a record of their login credentials.
*
* @since 2.1.0
*
* @param string $blog_title Site title.
* @param string $blog_url Site URL.
* @param int $user_id Administrator's user ID.
* @param string $password Administrator's password. Note that a placeholder message is
* usually passed instead of the actual password.
*/
function wp_new_blog_notification( $blog_title, $blog_url, $user_id, $password ) {
$user = new WP_User( $user_id );
$email = $user->user_email;
$name = $user->user_login;
$login_url = wp_login_url();
$message = sprintf(
/* translators: New site notification email. 1: New site URL, 2: User login, 3: User password or password reset link, 4: Login URL. */
__(
'Your new WordPress site has been successfully set up at:
%1$s
You can log in to the administrator account with the following information:
Username: %2$s
Password: %3$s
Log in here: %4$s
We hope you enjoy your new site. Thanks!
--The WordPress Team
https://wordpress.org/
'
),
$blog_url,
$name,
$password,
$login_url
);
$installed_email = array(
'to' => $email,
'subject' => __( 'New WordPress Site' ),
'message' => $message,
'headers' => '',
);
/**
* Filters the contents of the email sent to the site administrator when WordPress is installed.
*
* @since 5.6.0
*
* @param array $installed_email {
* Used to build wp_mail().
*
* @type string $to The email address of the recipient.
* @type string $subject The subject of the email.
* @type string $message The content of the email.
* @type string $headers Headers.
* }
* @param WP_User $user The site administrator user object.
* @param string $blog_title The site title.
* @param string $blog_url The site URL.
* @param string $password The site administrator's password. Note that a placeholder message
* is usually passed instead of the user's actual password.
*/
$installed_email = apply_filters( 'wp_installed_email', $installed_email, $user, $blog_title, $blog_url, $password );
wp_mail(
$installed_email['to'],
$installed_email['subject'],
$installed_email['message'],
$installed_email['headers']
);
}
endif;
if ( ! function_exists( 'wp_upgrade' ) ) :
/**
* Runs WordPress Upgrade functions.
*
* Upgrades the database if needed during a site update.
*
* @since 2.1.0
*
* @global int $wp_current_db_version The old (current) database version.
* @global int $wp_db_version The new database version.
* @global wpdb $wpdb WordPress database abstraction object.
*/
function wp_upgrade() {
global $wp_current_db_version, $wp_db_version, $wpdb;
$wp_current_db_version = __get_option( 'db_version' );
// We are up to date. Nothing to do.
if ( $wp_db_version == $wp_current_db_version ) {
return;
}
if ( ! is_blog_installed() ) {
return;
}
wp_check_mysql_version();
wp_cache_flush();
pre_schema_upgrade();
make_db_current_silent();
upgrade_all();
if ( is_multisite() && is_main_site() ) {
upgrade_network();
}
wp_cache_flush();
if ( is_multisite() ) {
update_site_meta( get_current_blog_id(), 'db_version', $wp_db_version );
update_site_meta( get_current_blog_id(), 'db_last_updated', microtime() );
}
/**
* Fires after a site is fully upgraded.
*
* @since 3.9.0
*
* @param int $wp_db_version The new $wp_db_version.
* @param int $wp_current_db_version The old (current) $wp_db_version.
*/
do_action( 'wp_upgrade', $wp_db_version, $wp_current_db_version );
}
endif;
/**
* Functions to be called in installation and upgrade scripts.
*
* Contains conditional checks to determine which upgrade scripts to run,
* based on database version and WP version being updated-to.
*
* @ignore
* @since 1.0.1
*
* @global int $wp_current_db_version The old (current) database version.
* @global int $wp_db_version The new database version.
*/
function upgrade_all() {
global $wp_current_db_version, $wp_db_version;
$wp_current_db_version = __get_option( 'db_version' );
// We are up to date. Nothing to do.
if ( $wp_db_version == $wp_current_db_version ) {
return;
}
// If the version is not set in the DB, try to guess the version.
if ( empty( $wp_current_db_version ) ) {
$wp_current_db_version = 0;
// If the template option exists, we have 1.5.
$template = __get_option( 'template' );
if ( ! empty( $template ) ) {
$wp_current_db_version = 2541;
}
}
if ( $wp_current_db_version < 6039 ) {
upgrade_230_options_table();
}
populate_options();
if ( $wp_current_db_version < 2541 ) {
upgrade_100();
upgrade_101();
upgrade_110();
upgrade_130();
}
if ( $wp_current_db_version < 3308 ) {
upgrade_160();
}
if ( $wp_current_db_version < 4772 ) {
upgrade_210();
}
if ( $wp_current_db_version < 4351 ) {
upgrade_old_slugs();
}
if ( $wp_current_db_version < 5539 ) {
upgrade_230();
}
if ( $wp_current_db_version < 6124 ) {
upgrade_230_old_tables();
}
if ( $wp_current_db_version < 7499 ) {
upgrade_250();
}
if ( $wp_current_db_version < 7935 ) {
upgrade_252();
}
if ( $wp_current_db_version < 8201 ) {
upgrade_260();
}
if ( $wp_current_db_version < 8989 ) {
upgrade_270();
}
if ( $wp_current_db_version < 10360 ) {
upgrade_280();
}
if ( $wp_current_db_version < 11958 ) {
upgrade_290();
}
if ( $wp_current_db_version < 15260 ) {
upgrade_300();
}
if ( $wp_current_db_version < 19389 ) {
upgrade_330();
}
if ( $wp_current_db_version < 20080 ) {
upgrade_340();
}
if ( $wp_current_db_version < 22422 ) {
upgrade_350();
}
if ( $wp_current_db_version < 25824 ) {
upgrade_370();
}
if ( $wp_current_db_version < 26148 ) {
upgrade_372();
}
if ( $wp_current_db_version < 26691 ) {
upgrade_380();
}
if ( $wp_current_db_version < 29630 ) {
upgrade_400();
}
if ( $wp_current_db_version < 33055 ) {
upgrade_430();
}
if ( $wp_current_db_version < 33056 ) {
upgrade_431();
}
if ( $wp_current_db_version < 35700 ) {
upgrade_440();
}
if ( $wp_current_db_version < 36686 ) {
upgrade_450();
}
if ( $wp_current_db_version < 37965 ) {
upgrade_460();
}
if ( $wp_current_db_version < 44719 ) {
upgrade_510();
}
if ( $wp_current_db_version < 45744 ) {
upgrade_530();
}
if ( $wp_current_db_version < 48575 ) {
upgrade_550();
}
if ( $wp_current_db_version < 49752 ) {
upgrade_560();
}
if ( $wp_current_db_version < 51917 ) {
upgrade_590();
}
maybe_disable_link_manager();
maybe_disable_automattic_widgets();
update_option( 'db_version', $wp_db_version );
update_option( 'db_upgraded', true );
}
/**
* Execute changes made in WordPress 1.0.
*
* @ignore
* @since 1.0.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*/
function upgrade_100() {
global $wpdb;
// Get the title and ID of every post, post_name to check if it already has a value.
$posts = $wpdb->get_results( "SELECT ID, post_title, post_name FROM $wpdb->posts WHERE post_name = ''" );
if ( $posts ) {
foreach ( $posts as $post ) {
if ( '' === $post->post_name ) {
$newtitle = sanitize_title( $post->post_title );
$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_name = %s WHERE ID = %d", $newtitle, $post->ID ) );
}
}
}
$categories = $wpdb->get_results( "SELECT cat_ID, cat_name, category_nicename FROM $wpdb->categories" );
foreach ( $categories as $category ) {
if ( '' === $category->category_nicename ) {
$newtitle = sanitize_title( $category->cat_name );
$wpdb->update( $wpdb->categories, array( 'category_nicename' => $newtitle ), array( 'cat_ID' => $category->cat_ID ) );
}
}
$sql = "UPDATE $wpdb->options
SET option_value = REPLACE(option_value, 'wp-links/links-images/', 'wp-images/links/')
WHERE option_name LIKE %s
AND option_value LIKE %s";
$wpdb->query( $wpdb->prepare( $sql, $wpdb->esc_like( 'links_rating_image' ) . '%', $wpdb->esc_like( 'wp-links/links-images/' ) . '%' ) );
$done_ids = $wpdb->get_results( "SELECT DISTINCT post_id FROM $wpdb->post2cat" );
if ( $done_ids ) :
$done_posts = array();
foreach ( $done_ids as $done_id ) :
$done_posts[] = $done_id->post_id;
endforeach;
$catwhere = ' AND ID NOT IN (' . implode( ',', $done_posts ) . ')';
else :
$catwhere = '';
endif;
$allposts = $wpdb->get_results( "SELECT ID, post_category FROM $wpdb->posts WHERE post_category != '0' $catwhere" );
if ( $allposts ) :
foreach ( $allposts as $post ) {
// Check to see if it's already been imported.
$cat = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->post2cat WHERE post_id = %d AND category_id = %d", $post->ID, $post->post_category ) );
if ( ! $cat && 0 != $post->post_category ) { // If there's no result.
$wpdb->insert(
$wpdb->post2cat,
array(
'post_id' => $post->ID,
'category_id' => $post->post_category,
)
);
}
}
endif;
}
/**
* Execute changes made in WordPress 1.0.1.
*
* @ignore
* @since 1.0.1
*
* @global wpdb $wpdb WordPress database abstraction object.
*/
function upgrade_101() {
global $wpdb;
// Clean up indices, add a few.
add_clean_index( $wpdb->posts, 'post_name' );
add_clean_index( $wpdb->posts, 'post_status' );
add_clean_index( $wpdb->categories, 'category_nicename' );
add_clean_index( $wpdb->comments, 'comment_approved' );
add_clean_index( $wpdb->comments, 'comment_post_ID' );
add_clean_index( $wpdb->links, 'link_category' );
add_clean_index( $wpdb->links, 'link_visible' );
}
/**
* Execute changes made in WordPress 1.2.
*
* @ignore
* @since 1.2.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*/
function upgrade_110() {
global $wpdb;
// Set user_nicename.
$users = $wpdb->get_results( "SELECT ID, user_nickname, user_nicename FROM $wpdb->users" );
foreach ( $users as $user ) {
if ( '' === $user->user_nicename ) {
$newname = sanitize_title( $user->user_nickname );
$wpdb->update( $wpdb->users, array( 'user_nicename' => $newname ), array( 'ID' => $user->ID ) );
}
}
$users = $wpdb->get_results( "SELECT ID, user_pass from $wpdb->users" );
foreach ( $users as $row ) {
if ( ! preg_match( '/^[A-Fa-f0-9]{32}$/', $row->user_pass ) ) {
$wpdb->update( $wpdb->users, array( 'user_pass' => md5( $row->user_pass ) ), array( 'ID' => $row->ID ) );
}
}
// Get the GMT offset, we'll use that later on.
$all_options = get_alloptions_110();
$time_difference = $all_options->time_difference;
$server_time = time() + gmdate( 'Z' );
$weblogger_time = $server_time + $time_difference * HOUR_IN_SECONDS;
$gmt_time = time();
$diff_gmt_server = ( $gmt_time - $server_time ) / HOUR_IN_SECONDS;
$diff_weblogger_server = ( $weblogger_time - $server_time ) / HOUR_IN_SECONDS;
$diff_gmt_weblogger = $diff_gmt_server - $diff_weblogger_server;
$gmt_offset = -$diff_gmt_weblogger;
// Add a gmt_offset option, with value $gmt_offset.
add_option( 'gmt_offset', $gmt_offset );
/*
* Check if we already set the GMT fields. If we did, then
* MAX(post_date_gmt) can't be '0000-00-00 00:00:00'.
* <michel_v> I just slapped myself silly for not thinking about it earlier.
*/
$got_gmt_fields = ( '0000-00-00 00:00:00' !== $wpdb->get_var( "SELECT MAX(post_date_gmt) FROM $wpdb->posts" ) );
if ( ! $got_gmt_fields ) {
// Add or subtract time to all dates, to get GMT dates.
$add_hours = (int) $diff_gmt_weblogger;
$add_minutes = (int) ( 60 * ( $diff_gmt_weblogger - $add_hours ) );
$wpdb->query( "UPDATE $wpdb->posts SET post_date_gmt = DATE_ADD(post_date, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)" );
$wpdb->query( "UPDATE $wpdb->posts SET post_modified = post_date" );
$wpdb->query( "UPDATE $wpdb->posts SET post_modified_gmt = DATE_ADD(post_modified, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE) WHERE post_modified != '0000-00-00 00:00:00'" );
$wpdb->query( "UPDATE $wpdb->comments SET comment_date_gmt = DATE_ADD(comment_date, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)" );
$wpdb->query( "UPDATE $wpdb->users SET user_registered = DATE_ADD(user_registered, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)" );
}
}
/**
* Execute changes made in WordPress 1.5.
*