diff -r 490d5cc509ed -r cf61fcea0001 wp/wp-admin/includes/upgrade.php --- a/wp/wp-admin/includes/upgrade.php Tue Jun 09 11:14:17 2015 +0000 +++ b/wp/wp-admin/includes/upgrade.php Mon Oct 14 17:39:30 2019 +0200 @@ -8,7 +8,7 @@ * @subpackage Administration */ -/** Include user install customize script. */ +/** Include user installation customization script. */ if ( file_exists(WP_CONTENT_DIR . '/install.php') ) require (WP_CONTENT_DIR . '/install.php'); @@ -27,10 +27,10 @@ * * @since 2.1.0 * - * @param string $blog_title Blog title. + * @param string $blog_title Site title. * @param string $user_name User's username. * @param string $user_email User's email. - * @param bool $public Whether blog is public. + * @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. @@ -38,7 +38,7 @@ */ function wp_install( $blog_title, $user_name, $user_email, $public, $deprecated = '', $user_password = '', $language = '' ) { if ( !empty( $deprecated ) ) - _deprecated_argument( __FUNCTION__, '2.6' ); + _deprecated_argument( __FUNCTION__, '2.6.0' ); wp_check_mysql_version(); wp_cache_flush(); @@ -50,6 +50,9 @@ 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 ); } @@ -64,7 +67,7 @@ /* * Create default user. If the user already exists, the user tables are - * being shared among blogs. Just set the role in that case. + * being shared among sites. Just set the role in that case. */ $user_id = username_exists($user_name); $user_password = trim($user_password); @@ -92,7 +95,7 @@ flush_rewrite_rules(); - wp_new_blog_notification($blog_title, $guessurl, $user_id, ($email_password ? $user_password : __('The password you chose during the install.') ) ); + wp_new_blog_notification($blog_title, $guessurl, $user_id, ($email_password ? $user_password : __('The password you chose during installation.') ) ); wp_cache_flush(); @@ -118,6 +121,10 @@ * * @since 2.1.0 * + * @global wpdb $wpdb + * @global WP_Rewrite $wp_rewrite + * @global string $table_prefix + * * @param int $user_id User ID. */ function wp_install_defaults( $user_id ) { @@ -151,86 +158,146 @@ if ( is_multisite() ) { $first_post = get_site_option( 'first_post' ); - if ( empty($first_post) ) - $first_post = __( 'Welcome to SITE_NAME. This is your first post. Edit or delete it, then start blogging!' ); - - $first_post = str_replace( "SITE_URL", esc_url( network_home_url() ), $first_post ); - $first_post = str_replace( "SITE_NAME", get_current_site()->site_name, $first_post ); + if ( ! $first_post ) { + /* translators: %s: site link */ + $first_post = __( 'Welcome to %s. This is your first post. Edit or delete it, then start blogging!' ); + } + + $first_post = sprintf( $first_post, + sprintf( '%s', 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 = __('Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!'); + $first_post = __( 'Welcome to WordPress. This is your first post. Edit or delete it, then start writing!' ); } $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' => '' - )); + '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 - $first_comment_author = __('Mr WordPress'); - $first_comment_url = 'https://wordpress.org/'; - $first_comment = __('Hi, this is a comment. -To delete a comment, just log in and view the post's comments. There you will have the option to edit or delete them.'); if ( is_multisite() ) { - $first_comment_author = get_site_option( 'first_comment_author', $first_comment_author ); + $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 ); + $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 : 'wapuu@wordpress.example'; + $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 Gravatar.' ); $wpdb->insert( $wpdb->comments, array( - 'comment_post_ID' => 1, - 'comment_author' => $first_comment_author, - 'comment_author_email' => '', - 'comment_author_url' => $first_comment_url, - 'comment_date' => $now, - 'comment_date_gmt' => $now_gmt, - 'comment_content' => $first_comment - )); + '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 + )); // First Page - $first_page = sprintf( __( "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: - -
Hi there! I'm a bike messenger by day, aspiring actor by night, and this is my blog. I live in Los Angeles, have a great dog named Jack, and I like piña coladas. (And gettin' caught in the rain.)+ if ( is_multisite() ) + $first_page = get_site_option( 'first_page' ); + + $first_page = ! empty( $first_page ) ? $first_page : sprintf( __( "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: + +
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.)...or something like this:
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.As a new WordPress user, you should go to your dashboard to delete this page and create new pages for your content. Have fun!" ), admin_url() ); - if ( is_multisite() ) - $first_page = get_site_option( 'first_page', $first_page ); + $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' => '', - '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' => '' - )); + '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/misc.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_search', array ( 2 => array ( 'title' => '' ), '_multiwidget' => 1 ) ); update_option( 'widget_recent-posts', array ( 2 => array ( 'title' => '', 'number' => 5 ), '_multiwidget' => 1 ) ); @@ -238,8 +305,7 @@ update_option( 'widget_archives', array ( 2 => array ( 'title' => '', 'count' => 0, 'dropdown' => 0 ), '_multiwidget' => 1 ) ); update_option( 'widget_categories', array ( 2 => array ( 'title' => '', 'count' => 0, 'hierarchical' => 0, 'dropdown' => 0 ), '_multiwidget' => 1 ) ); update_option( 'widget_meta', array ( 2 => array ( 'title' => '' ), '_multiwidget' => 1 ) ); - update_option( 'sidebars_widgets', array ( 'wp_inactive_widgets' => array (), 'sidebar-1' => array ( 0 => 'search-2', 1 => 'recent-posts-2', 2 => 'recent-comments-2', 3 => 'archives-2', 4 => 'categories-2', 5 => 'meta-2', ), 'array_version' => 3 ) ); - + update_option( 'sidebars_widgets', array( 'wp_inactive_widgets' => array(), 'sidebar-1' => array( 0 => 'search-2', 1 => 'recent-posts-2', 2 => 'recent-comments-2', 3 => 'archives-2', 4 => 'categories-2', 5 => 'meta-2' ), 'sidebar-2' => array(), 'sidebar-3' => array(), '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' ) ) @@ -265,7 +331,7 @@ endif; /** - * Maybe enable pretty permalinks on install. + * Maybe enable pretty permalinks on installation. * * If after enabling pretty permalinks don't work, fallback to query-string permalinks. * @@ -305,11 +371,12 @@ */ $wp_rewrite->flush_rules( true ); - // Test against a real WordPress Post, or if none were created, a random 404 page. - $test_url = get_permalink( 1 ); - - if ( ! $test_url ) { - $test_url = home_url( '/wordpress-check-for-rewrites/' ); + $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 ); } /* @@ -347,8 +414,8 @@ * * @since 2.1.0 * - * @param string $blog_title Blog title. - * @param string $blog_url Blog url. + * @param string $blog_title Site title. + * @param string $blog_url Site url. * @param int $user_id User ID. * @param string $password User's Password. */ @@ -357,6 +424,7 @@ $email = $user->user_email; $name = $user->user_login; $login_url = wp_login_url(); + /* translators: New site notification email. 1: New site URL, 2: User login, 3: User password or password reset link, 4: Login URL */ $message = sprintf( __( "Your new WordPress site has been successfully set up at: %1\$s @@ -385,7 +453,9 @@ * * @since 2.1.0 * - * @return null If no update is necessary or site isn't completely installed, null. + * @global int $wp_current_db_version + * @global int $wp_db_version + * @global wpdb $wpdb WordPress database abstraction object. */ function wp_upgrade() { global $wp_current_db_version, $wp_db_version, $wpdb; @@ -409,10 +479,13 @@ wp_cache_flush(); if ( is_multisite() ) { - if ( $wpdb->get_row( "SELECT blog_id FROM {$wpdb->blog_versions} WHERE blog_id = '{$wpdb->blogid}'" ) ) - $wpdb->query( "UPDATE {$wpdb->blog_versions} SET db_version = '{$wp_db_version}' WHERE blog_id = '{$wpdb->blogid}'" ); - else - $wpdb->query( "INSERT INTO {$wpdb->blog_versions} ( `blog_id` , `db_version` , `last_updated` ) VALUES ( '{$wpdb->blogid}', '{$wp_db_version}', NOW());" ); + $site_id = get_current_blog_id(); + + if ( $wpdb->get_row( $wpdb->prepare( "SELECT blog_id FROM {$wpdb->blog_versions} WHERE blog_id = %d", $site_id ) ) ) { + $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->blog_versions} SET db_version = %d WHERE blog_id = %d", $wp_db_version, $site_id ) ); + } else { + $wpdb->query( $wpdb->prepare( "INSERT INTO {$wpdb->blog_versions} ( `blog_id` , `db_version` , `last_updated` ) VALUES ( %d, %d, NOW() );", $site_id, $wp_db_version ) ); + } } /** @@ -428,14 +501,16 @@ endif; /** - * Functions to be called in install and upgrade scripts. + * 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 * - * @return null If no update is necessary, null. + * @global int $wp_current_db_version + * @global int $wp_db_version */ function upgrade_all() { global $wp_current_db_version, $wp_db_version; @@ -524,14 +599,20 @@ if ( $wp_current_db_version < 29630 ) upgrade_400(); - // Don't harsh my mellow. upgrade_422() must be called before - // upgrade_420() to catch bad comments prior to any auto-expansion of - // MySQL column widths. - if ( $wp_current_db_version < 31534 ) - upgrade_422(); - - if ( $wp_current_db_version < 31351 ) - upgrade_420(); + 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(); maybe_disable_link_manager(); @@ -544,7 +625,10 @@ /** * Execute changes made in WordPress 1.0. * + * @ignore * @since 1.0.0 + * + * @global wpdb $wpdb WordPress database abstraction object. */ function upgrade_100() { global $wpdb; @@ -552,7 +636,7 @@ // 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) { + 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) ); @@ -600,7 +684,10 @@ /** * 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; @@ -618,7 +705,10 @@ /** * Execute changes made in WordPress 1.2. * + * @ignore * @since 1.2.0 + * + * @global wpdb $wpdb WordPress database abstraction object. */ function upgrade_110() { global $wpdb; @@ -678,7 +768,10 @@ /** * Execute changes made in WordPress 1.5. * + * @ignore * @since 1.5.0 + * + * @global wpdb $wpdb WordPress database abstraction object. */ function upgrade_130() { global $wpdb; @@ -686,7 +779,7 @@ // Remove extraneous backslashes. $posts = $wpdb->get_results("SELECT ID, post_title, post_content, post_excerpt, guid, post_date, post_name, post_status, post_author FROM $wpdb->posts"); if ($posts) { - foreach($posts as $post) { + foreach ($posts as $post) { $post_content = addslashes(deslash($post->post_content)); $post_title = addslashes(deslash($post->post_title)); $post_excerpt = addslashes(deslash($post->post_excerpt)); @@ -703,7 +796,7 @@ // Remove extraneous backslashes. $comments = $wpdb->get_results("SELECT comment_ID, comment_author, comment_content FROM $wpdb->comments"); if ($comments) { - foreach($comments as $comment) { + foreach ($comments as $comment) { $comment_content = deslash($comment->comment_content); $comment_author = deslash($comment->comment_author); @@ -714,7 +807,7 @@ // Remove extraneous backslashes. $links = $wpdb->get_results("SELECT link_id, link_name, link_description FROM $wpdb->links"); if ($links) { - foreach($links as $link) { + foreach ($links as $link) { $link_name = deslash($link->link_name); $link_description = deslash($link->link_description); @@ -762,7 +855,11 @@ /** * Execute changes made in WordPress 2.0. * + * @ignore * @since 2.0.0 + * + * @global wpdb $wpdb WordPress database abstraction object. + * @global int $wp_current_db_version */ function upgrade_160() { global $wpdb, $wp_current_db_version; @@ -845,7 +942,11 @@ /** * Execute changes made in WordPress 2.1. * + * @ignore * @since 2.1.0 + * + * @global wpdb $wpdb WordPress database abstraction object. + * @global int $wp_current_db_version */ function upgrade_210() { global $wpdb, $wp_current_db_version; @@ -889,7 +990,11 @@ /** * Execute changes made in WordPress 2.3. * + * @ignore * @since 2.3.0 + * + * @global wpdb $wpdb WordPress database abstraction object. + * @global int $wp_current_db_version */ function upgrade_230() { global $wp_current_db_version, $wpdb; @@ -1065,7 +1170,10 @@ /** * Remove old options from the database. * + * @ignore * @since 2.3.0 + * + * @global wpdb $wpdb WordPress database abstraction object. */ function upgrade_230_options_table() { global $wpdb; @@ -1079,7 +1187,10 @@ /** * Remove old categories, link2cat, and post2cat database tables. * + * @ignore * @since 2.3.0 + * + * @global wpdb $wpdb WordPress database abstraction object. */ function upgrade_230_old_tables() { global $wpdb; @@ -1091,7 +1202,10 @@ /** * Upgrade old slugs made in version 2.2. * + * @ignore * @since 2.2.0 + * + * @global wpdb $wpdb WordPress database abstraction object. */ function upgrade_old_slugs() { // Upgrade people who were using the Redirect Old Slugs plugin. @@ -1102,7 +1216,10 @@ /** * Execute changes made in WordPress 2.5.0. * + * @ignore * @since 2.5.0 + * + * @global int $wp_current_db_version */ function upgrade_250() { global $wp_current_db_version; @@ -1116,7 +1233,10 @@ /** * Execute changes made in WordPress 2.5.2. * + * @ignore * @since 2.5.2 + * + * @global wpdb $wpdb WordPress database abstraction object. */ function upgrade_252() { global $wpdb; @@ -1127,7 +1247,10 @@ /** * Execute changes made in WordPress 2.6. * + * @ignore * @since 2.6.0 + * + * @global int $wp_current_db_version */ function upgrade_260() { global $wp_current_db_version; @@ -1139,7 +1262,11 @@ /** * Execute changes made in WordPress 2.7. * + * @ignore * @since 2.7.0 + * + * @global wpdb $wpdb WordPress database abstraction object. + * @global int $wp_current_db_version */ function upgrade_270() { global $wpdb, $wp_current_db_version; @@ -1155,7 +1282,11 @@ /** * Execute changes made in WordPress 2.8. * + * @ignore * @since 2.8.0 + * + * @global int $wp_current_db_version + * @global wpdb $wpdb WordPress database abstraction object. */ function upgrade_280() { global $wp_current_db_version, $wpdb; @@ -1165,7 +1296,7 @@ if ( is_multisite() ) { $start = 0; while( $rows = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options ORDER BY option_id LIMIT $start, 20" ) ) { - foreach( $rows as $row ) { + foreach ( $rows as $row ) { $value = $row->option_value; if ( !@unserialize( $value ) ) $value = stripslashes( $value ); @@ -1175,14 +1306,17 @@ } $start += 20; } - refresh_blog_details( $wpdb->blogid ); + clean_blog_cache( get_current_blog_id() ); } } /** * Execute changes made in WordPress 2.9. * + * @ignore * @since 2.9.0 + * + * @global int $wp_current_db_version */ function upgrade_290() { global $wp_current_db_version; @@ -1199,7 +1333,11 @@ /** * Execute changes made in WordPress 3.0. * + * @ignore * @since 3.0.0 + * + * @global int $wp_current_db_version + * @global wpdb $wpdb WordPress database abstraction object. */ function upgrade_300() { global $wp_current_db_version, $wpdb; @@ -1211,7 +1349,7 @@ add_site_option( 'siteurl', '' ); // 3.0 screen options key name changes. - if ( is_main_site() && !defined('DO_NOT_UPGRADE_GLOBAL_TABLES') ) { + if ( wp_should_upgrade_global_tables() ) { $sql = "DELETE FROM $wpdb->usermeta WHERE meta_key LIKE %s OR meta_key LIKE %s @@ -1241,12 +1379,18 @@ /** * Execute changes made in WordPress 3.3. * + * @ignore * @since 3.3.0 + * + * @global int $wp_current_db_version + * @global wpdb $wpdb + * @global array $wp_registered_widgets + * @global array $sidebars_widgets */ function upgrade_330() { global $wp_current_db_version, $wpdb, $wp_registered_widgets, $sidebars_widgets; - if ( $wp_current_db_version < 19061 && is_main_site() && ! defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) ) { + if ( $wp_current_db_version < 19061 && wp_should_upgrade_global_tables() ) { $wpdb->query( "DELETE FROM $wpdb->usermeta WHERE meta_key IN ('show_admin_bar_admin', 'plugins_last_view')" ); } @@ -1310,7 +1454,11 @@ /** * Execute changes made in WordPress 3.4. * + * @ignore * @since 3.4.0 + * + * @global int $wp_current_db_version + * @global wpdb $wpdb */ function upgrade_340() { global $wp_current_db_version, $wpdb; @@ -1327,7 +1475,7 @@ $wpdb->show_errors(); } - if ( $wp_current_db_version < 20022 && is_main_site() && ! defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) ) { + if ( $wp_current_db_version < 20022 && wp_should_upgrade_global_tables() ) { $wpdb->query( "DELETE FROM $wpdb->usermeta WHERE meta_key = 'themes_last_view'" ); } @@ -1343,7 +1491,11 @@ /** * Execute changes made in WordPress 3.5. * + * @ignore * @since 3.5.0 + * + * @global int $wp_current_db_version + * @global wpdb $wpdb */ function upgrade_350() { global $wp_current_db_version, $wpdb; @@ -1351,7 +1503,7 @@ if ( $wp_current_db_version < 22006 && $wpdb->get_var( "SELECT link_id FROM $wpdb->links LIMIT 1" ) ) update_option( 'link_manager_enabled', 1 ); // Previously set to 0 by populate_options() - if ( $wp_current_db_version < 21811 && is_main_site() && ! defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) ) { + if ( $wp_current_db_version < 21811 && wp_should_upgrade_global_tables() ) { $meta_keys = array(); foreach ( array_merge( get_post_types(), get_taxonomies() ) as $name ) { if ( false !== strpos( $name, '-' ) ) @@ -1370,7 +1522,10 @@ /** * Execute changes made in WordPress 3.7. * + * @ignore * @since 3.7.0 + * + * @global int $wp_current_db_version */ function upgrade_370() { global $wp_current_db_version; @@ -1381,8 +1536,11 @@ /** * Execute changes made in WordPress 3.7.2. * + * @ignore * @since 3.7.2 * @since 3.8.0 + * + * @global int $wp_current_db_version */ function upgrade_372() { global $wp_current_db_version; @@ -1393,7 +1551,10 @@ /** * Execute changes made in WordPress 3.8.0. * + * @ignore * @since 3.8.0 + * + * @global int $wp_current_db_version */ function upgrade_380() { global $wp_current_db_version; @@ -1405,7 +1566,10 @@ /** * Execute changes made in WordPress 4.0.0. * + * @ignore * @since 4.0.0 + * + * @global int $wp_current_db_version */ function upgrade_400() { global $wp_current_db_version; @@ -1423,16 +1587,45 @@ /** * Execute changes made in WordPress 4.2.0. * + * @ignore * @since 4.2.0 + * + * @global int $wp_current_db_version + * @global wpdb $wpdb */ -function upgrade_420() { +function upgrade_420() {} + +/** + * Executes changes made in WordPress 4.3.0. + * + * @ignore + * @since 4.3.0 + * + * @global int $wp_current_db_version Current version. + * @global wpdb $wpdb WordPress database abstraction object. + */ +function upgrade_430() { global $wp_current_db_version, $wpdb; - if ( $wp_current_db_version < 31351 && $wpdb->charset === 'utf8mb4' ) { + if ( $wp_current_db_version < 32364 ) { + upgrade_430_fix_comments(); + } + + // Shared terms are split in a separate process. + if ( $wp_current_db_version < 32814 ) { + update_option( 'finished_splitting_shared_terms', 0 ); + wp_schedule_single_event( time() + ( 1 * MINUTE_IN_SECONDS ), 'wp_split_shared_term_batch' ); + } + + if ( $wp_current_db_version < 33055 && 'utf8mb4' === $wpdb->charset ) { if ( is_multisite() ) { $tables = $wpdb->tables( 'blog' ); } else { $tables = $wpdb->tables( 'all' ); + if ( ! wp_should_upgrade_global_tables() ) { + $global_tables = $wpdb->tables( 'global' ); + $tables = array_diff_assoc( $tables, $global_tables ); + } } foreach ( $tables as $table ) { @@ -1442,57 +1635,148 @@ } /** - * Execute changes made in WordPress 4.2.1. + * Executes comments changes made in WordPress 4.3.0. + * + * @ignore + * @since 4.3.0 * - * @since 4.2.1 + * @global int $wp_current_db_version Current version. + * @global wpdb $wpdb WordPress database abstraction object. */ -function upgrade_421() { +function upgrade_430_fix_comments() { + global $wp_current_db_version, $wpdb; + + $content_length = $wpdb->get_col_length( $wpdb->comments, 'comment_content' ); + + if ( is_wp_error( $content_length ) ) { + return; + } + + if ( false === $content_length ) { + $content_length = array( + 'type' => 'byte', + 'length' => 65535, + ); + } elseif ( ! is_array( $content_length ) ) { + $length = (int) $content_length > 0 ? (int) $content_length : 65535; + $content_length = array( + 'type' => 'byte', + 'length' => $length + ); + } + + if ( 'byte' !== $content_length['type'] || 0 === $content_length['length'] ) { + // Sites with malformed DB schemas are on their own. + return; + } + + $allowed_length = intval( $content_length['length'] ) - 10; + + $comments = $wpdb->get_results( + "SELECT `comment_ID` FROM `{$wpdb->comments}` + WHERE `comment_date_gmt` > '2015-04-26' + AND LENGTH( `comment_content` ) >= {$allowed_length} + AND ( `comment_content` LIKE '%<%' OR `comment_content` LIKE '%>%' )" + ); + + foreach ( $comments as $comment ) { + wp_delete_comment( $comment->comment_ID, true ); + } +} + +/** + * Executes changes made in WordPress 4.3.1. + * + * @ignore + * @since 4.3.1 + */ +function upgrade_431() { + // Fix incorrect cron entries for term splitting + $cron_array = _get_cron_array(); + if ( isset( $cron_array['wp_batch_split_terms'] ) ) { + unset( $cron_array['wp_batch_split_terms'] ); + _set_cron_array( $cron_array ); + } } /** - * Execute changes made in WordPress 4.2.2. + * Executes changes made in WordPress 4.4.0. + * + * @ignore + * @since 4.4.0 * - * @since 4.2.2 + * @global int $wp_current_db_version Current version. + * @global wpdb $wpdb WordPress database abstraction object. */ -function upgrade_422() { +function upgrade_440() { global $wp_current_db_version, $wpdb; - if ( $wp_current_db_version < 31534 ) { - $content_length = $wpdb->get_col_length( $wpdb->comments, 'comment_content' ); - - if ( is_wp_error( $content_length ) ) { - return; + if ( $wp_current_db_version < 34030 ) { + $wpdb->query( "ALTER TABLE {$wpdb->options} MODIFY option_name VARCHAR(191)" ); + } + + // Remove the unused 'add_users' role. + $roles = wp_roles(); + foreach ( $roles->role_objects as $role ) { + if ( $role->has_cap( 'add_users' ) ) { + $role->remove_cap( 'add_users' ); } - - if ( false === $content_length ) { - $content_length = array( - 'type' => 'byte', - 'length' => 65535, - ); - } elseif ( ! is_array( $content_length ) ) { - $length = (int) $content_length > 0 ? (int) $content_length : 65535; - $content_length = array( - 'type' => 'byte', - 'length' => $length - ); - } - - if ( 'byte' !== $content_length['type'] || 0 === $content_length['length'] ) { - // Sites with malformed DB schemas are on their own. - return; - } - - $allowed_length = intval( $content_length['length'] ) - 10; - - $comments = $wpdb->get_results( - "SELECT `comment_ID` FROM `{$wpdb->comments}` - WHERE `comment_date_gmt` > '2015-04-26' - AND LENGTH( `comment_content` ) >= {$allowed_length} - AND ( `comment_content` LIKE '%<%' OR `comment_content` LIKE '%>%' )" - ); - - foreach ( $comments as $comment ) { - wp_delete_comment( $comment->comment_ID, true ); + } +} + +/** + * Executes changes made in WordPress 4.5.0. + * + * @ignore + * @since 4.5.0 + * + * @global int $wp_current_db_version Current database version. + * @global wpdb $wpdb WordPress database abstraction object. + */ +function upgrade_450() { + global $wp_current_db_version, $wpdb; + + if ( $wp_current_db_version < 36180 ) { + wp_clear_scheduled_hook( 'wp_maybe_auto_update' ); + } + + // Remove unused email confirmation options, moved to usermeta. + if ( $wp_current_db_version < 36679 && is_multisite() ) { + $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name REGEXP '^[0-9]+_new_email$'" ); + } + + // Remove unused user setting for wpLink. + delete_user_setting( 'wplink' ); +} + +/** + * Executes changes made in WordPress 4.6.0. + * + * @ignore + * @since 4.6.0 + * + * @global int $wp_current_db_version Current database version. + */ +function upgrade_460() { + global $wp_current_db_version; + + // Remove unused post meta. + if ( $wp_current_db_version < 37854 ) { + delete_post_meta_by_key( '_post_restored_from' ); + } + + // Remove plugins with callback as an array object/method as the uninstall hook, see #13786. + if ( $wp_current_db_version < 37965 ) { + $uninstall_plugins = get_option( 'uninstall_plugins', array() ); + + if ( ! empty( $uninstall_plugins ) ) { + foreach ( $uninstall_plugins as $basename => $callback ) { + if ( is_array( $callback ) && is_object( $callback[0] ) ) { + unset( $uninstall_plugins[ $basename ] ); + } + } + + update_option( 'uninstall_plugins', $uninstall_plugins ); } } } @@ -1501,25 +1785,15 @@ * Executes network-level upgrade routines. * * @since 3.0.0 + * + * @global int $wp_current_db_version + * @global wpdb $wpdb */ function upgrade_network() { global $wp_current_db_version, $wpdb; - // Always. - if ( is_main_network() ) { - /* - * Deletes all expired transients. The multi-table delete syntax is used - * to delete the transient record from table a, and the corresponding - * transient_timeout record from table b. - */ - $time = time(); - $sql = "DELETE a, b FROM $wpdb->sitemeta a, $wpdb->sitemeta b - WHERE a.meta_key LIKE %s - AND a.meta_key NOT LIKE %s - AND b.meta_key = CONCAT( '_site_transient_timeout_', SUBSTRING( a.meta_key, 17 ) ) - AND b.meta_value < %d"; - $wpdb->query( $wpdb->prepare( $sql, $wpdb->esc_like( '_site_transient_' ) . '%', $wpdb->esc_like ( '_site_transient_timeout_' ) . '%', $time ) ); - } + // Always clear expired transients + delete_expired_transients( true ); // 2.8. if ( $wp_current_db_version < 11549 ) { @@ -1538,7 +1812,7 @@ $start = 0; while( $rows = $wpdb->get_results( "SELECT meta_key, meta_value FROM {$wpdb->sitemeta} ORDER BY meta_id LIMIT $start, 20" ) ) { - foreach( $rows as $row ) { + foreach ( $rows as $row ) { $value = $row->meta_value; if ( !@unserialize( $value ) ) $value = stripslashes( $value ); @@ -1596,7 +1870,7 @@ // 4.2 if ( $wp_current_db_version < 31351 && $wpdb->charset === 'utf8mb4' ) { - if ( ! ( defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) && DO_NOT_UPGRADE_GLOBAL_TABLES ) ) { + if ( wp_should_upgrade_global_tables() ) { $wpdb->query( "ALTER TABLE $wpdb->usermeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" ); $wpdb->query( "ALTER TABLE $wpdb->site DROP INDEX domain, ADD INDEX domain(domain(140),path(51))" ); $wpdb->query( "ALTER TABLE $wpdb->sitemeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" ); @@ -1604,18 +1878,23 @@ $tables = $wpdb->tables( 'global' ); + // sitecategories may not exist. + if ( ! $wpdb->get_var( "SHOW TABLES LIKE '{$tables['sitecategories']}'" ) ) { + unset( $tables['sitecategories'] ); + } + foreach ( $tables as $table ) { maybe_convert_table_to_utf8mb4( $table ); } } } - // 4.2.2 - if ( $wp_current_db_version < 31535 && 'utf8mb4' === $wpdb->charset ) { - if ( ! ( defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) && DO_NOT_UPGRADE_GLOBAL_TABLES ) ) { + // 4.3 + if ( $wp_current_db_version < 33055 && 'utf8mb4' === $wpdb->charset ) { + if ( wp_should_upgrade_global_tables() ) { $upgrade = false; $indexes = $wpdb->get_results( "SHOW INDEXES FROM $wpdb->signups" ); - foreach( $indexes as $index ) { + foreach ( $indexes as $index ) { if ( 'domain_path' == $index->Key_name && 'domain' == $index->Column_name && 140 != $index->Sub_part ) { $upgrade = true; break; @@ -1625,6 +1904,17 @@ if ( $upgrade ) { $wpdb->query( "ALTER TABLE $wpdb->signups DROP INDEX domain_path, ADD INDEX domain_path(domain(140),path(51))" ); } + + $tables = $wpdb->tables( 'global' ); + + // sitecategories may not exist. + if ( ! $wpdb->get_var( "SHOW TABLES LIKE '{$tables['sitecategories']}'" ) ) { + unset( $tables['sitecategories'] ); + } + + foreach ( $tables as $table ) { + maybe_convert_table_to_utf8mb4( $table ); + } } } } @@ -1642,6 +1932,8 @@ * * @since 1.0.0 * + * @global wpdb $wpdb + * * @param string $table_name Database table name to create. * @param string $create_ddl SQL statement to create table. * @return bool If table already exists or was created by function. @@ -1670,9 +1962,11 @@ * * @since 1.0.1 * + * @global wpdb $wpdb + * * @param string $table Database table name. * @param string $index Index name to drop. - * @return bool True, when finished. + * @return true True, when finished. */ function drop_index($table, $index) { global $wpdb; @@ -1691,9 +1985,11 @@ * * @since 1.0.1 * + * @global wpdb $wpdb + * * @param string $table Database table name. * @param string $index Database table index column. - * @return bool True, when done with execution. + * @return true True, when done with execution. */ function add_clean_index($table, $index) { global $wpdb; @@ -1707,10 +2003,12 @@ * * @since 1.3.0 * + * @global wpdb $wpdb + * * @param string $table_name The table name to modify. * @param string $column_name The column name to add to the table. * @param string $create_ddl The SQL statement used to add the column. - * @return True if already exists or on successful completion, false on error. + * @return bool True if already exists or on successful completion, false on error. */ function maybe_add_column($table_name, $column_name, $create_ddl) { global $wpdb; @@ -1737,6 +2035,8 @@ * * @since 4.2.0 * + * @global wpdb $wpdb + * * @param string $table The table to convert. * @return bool true if the table was converted, false if it wasn't. */ @@ -1759,6 +2059,17 @@ } } + $table_details = $wpdb->get_row( "SHOW TABLE STATUS LIKE '$table'" ); + if ( ! $table_details ) { + return false; + } + + list( $table_charset ) = explode( '_', $table_details->Collation ); + $table_charset = strtolower( $table_charset ); + if ( 'utf8mb4' === $table_charset ) { + return true; + } + return $wpdb->query( "ALTER TABLE $table CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci" ); } @@ -1767,6 +2078,8 @@ * * @since 1.2.0 * + * @global wpdb $wpdb + * * @return stdClass List of options. */ function get_alloptions_110() { @@ -1783,12 +2096,14 @@ } /** - * Utility version of get_option that is private to install/upgrade. + * Utility version of get_option that is private to installation/upgrade. * * @ignore * @since 1.5.1 * @access private * + * @global wpdb $wpdb + * * @param string $setting Option name. * @return mixed */ @@ -1848,6 +2163,8 @@ * * @since 1.5.0 * + * @global wpdb $wpdb + * * @param string|array $queries Optional. The query to run. Can be multiple queries * in an array, or a string of queries separated by * semicolons. Default empty. @@ -1868,7 +2185,7 @@ } /** - * Filter the dbDelta SQL queries. + * Filters the dbDelta SQL queries. * * @since 3.3.0 * @@ -1881,7 +2198,7 @@ $for_update = array(); // Create a tablename index for an array ($cqueries) of queries - foreach($queries as $qry) { + foreach ($queries as $qry) { if ( preg_match( "|CREATE TABLE ([^ ]*)|", $qry, $matches ) ) { $cqueries[ trim( $matches[1], '`' ) ] = $qry; $for_update[$matches[1]] = 'Created table '.$matches[1]; @@ -1897,7 +2214,7 @@ } /** - * Filter the dbDelta SQL queries for creating tables and/or databases. + * Filters the dbDelta SQL queries for creating tables and/or databases. * * Queries filterable via this hook contain "CREATE TABLE" or "CREATE DATABASE". * @@ -1908,7 +2225,7 @@ $cqueries = apply_filters( 'dbdelta_create_queries', $cqueries ); /** - * Filter the dbDelta SQL queries for inserting or updating. + * Filters the dbDelta SQL queries for inserting or updating. * * Queries filterable via this hook contain "INSERT INTO" or "UPDATE". * @@ -1918,10 +2235,13 @@ */ $iqueries = apply_filters( 'dbdelta_insert_queries', $iqueries ); + $text_fields = array( 'tinytext', 'text', 'mediumtext', 'longtext' ); + $blob_fields = array( 'tinyblob', 'blob', 'mediumblob', 'longblob' ); + $global_tables = $wpdb->tables( 'global' ); foreach ( $cqueries as $table => $qry ) { - // Upgrade global tables only for the main site. Don't upgrade at all if DO_NOT_UPGRADE_GLOBAL_TABLES is defined. - if ( in_array( $table, $global_tables ) && ( !is_main_site() || defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) ) ) { + // Upgrade global tables only for the main site. Don't upgrade at all if conditions are not optimal. + if ( in_array( $table, $global_tables ) && ! wp_should_upgrade_global_tables() ) { unset( $cqueries[ $table ], $for_update[ $table ] ); continue; } @@ -1935,7 +2255,7 @@ continue; // Clear the field and index arrays. - $cfields = $indices = array(); + $cfields = $indices = $indices_without_subparts = array(); // Get all of the field names in the query from between the parentheses. preg_match("|\((.*)\)|ms", $qry, $match2); @@ -1944,68 +2264,172 @@ // Separate field lines into an array. $flds = explode("\n", $qryline); - // todo: Remove this? - //echo "
\n".print_r(strtolower($table), true).":\n".print_r($cqueries, true)."
{$table}:\n"; - } + $index_string .= " ($index_columns)"; + + // Check if the index definition exists, ignoring subparts. + if ( ! ( ( $aindex = array_search( $index_string, $indices_without_subparts ) ) === false ) ) { + // If the index already exists (even with different subparts), we don't need to create it. + unset( $indices_without_subparts[ $aindex ] ); + unset( $indices[ $aindex ] ); } - // todo: Remove this? - //else echo "
Found index:".$index_string."
{$table}:\n"; } } @@ -2097,8 +2517,6 @@ $allqueries = array_merge($cqueries, $iqueries); if ($execute) { foreach ($allqueries as $query) { - // todo: Remove this? - //echo "
Did not find index:".$index_string."
".print_r($indices, true)."
".print_r($query, true)."\n"; $wpdb->query($query); } } @@ -2121,7 +2539,7 @@ function make_db_current( $tables = 'all' ) { $alterations = dbDelta( $tables ); echo "