<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[43628] trunk: Upgrade/Install: Introduce `populate_network_meta()`, moving logic out of `populate_network()`.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/43628">43628</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/43628","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>flixos90</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2018-09-05 10:44:02 +0000 (Wed, 05 Sep 2018)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Upgrade/Install: Introduce `populate_network_meta()`, moving logic out of `populate_network()`.
Fixes <a href="https://core.trac.wordpress.org/ticket/44895">#44895</a>. See <a href="https://core.trac.wordpress.org/ticket/41333">#41333</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadminincludesschemaphp">trunk/src/wp-admin/includes/schema.php</a></li>
<li><a href="#trunktestsphpunittestsadminincludesSchemaphp">trunk/tests/phpunit/tests/admin/includesSchema.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpadminincludesschemaphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/includes/schema.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/includes/schema.php 2018-09-05 09:38:04 UTC (rev 43627)
+++ trunk/src/wp-admin/includes/schema.php 2018-09-05 10:44:02 UTC (rev 43628)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -383,7 +383,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // If WP_DEFAULT_THEME doesn't exist, fall back to the latest core default theme.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $stylesheet = $template = WP_DEFAULT_THEME;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $stylesheet = WP_DEFAULT_THEME;
+ $template = WP_DEFAULT_THEME;
</ins><span class="cx" style="display: block; padding: 0 10px"> $theme = wp_get_theme( WP_DEFAULT_THEME );
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! $theme->exists() ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $theme = WP_Theme::get_core_default_theme();
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -402,7 +403,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * or a valid timezone string (America/New_York). See https://secure.php.net/manual/en/timezones.php
</span><span class="cx" style="display: block; padding: 0 10px"> * for all timezone strings supported by PHP.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $offset_or_tz = _x( '0', 'default GMT offset or timezone string' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $offset_or_tz = _x( '0', 'default GMT offset or timezone string' ); // phpcs:ignore WordPress.WP.I18n.NoEmptyStrings
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( is_numeric( $offset_or_tz ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $gmt_offset = $offset_or_tz;
</span><span class="cx" style="display: block; padding: 0 10px"> } elseif ( $offset_or_tz && in_array( $offset_or_tz, timezone_identifiers_list() ) ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -562,7 +563,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $fat_options = array( 'moderation_keys', 'recently_edited', 'blacklist_keys', 'uninstall_plugins' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $keys = "'" . implode( "', '", array_keys( $options ) ) . "'";
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $existing_options = $wpdb->get_col( "SELECT option_name FROM $wpdb->options WHERE option_name in ( $keys )" );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $existing_options = $wpdb->get_col( "SELECT option_name FROM $wpdb->options WHERE option_name in ( $keys )" ); // phpcs:ignore WordPress.WP.PreparedSQL.NotPrepared
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $insert = '';
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( $options as $option => $value ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -585,7 +586,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! empty( $insert ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $wpdb->query( "INSERT INTO $wpdb->options (option_name, option_value, autoload) VALUES " . $insert );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $wpdb->query( "INSERT INTO $wpdb->options (option_name, option_value, autoload) VALUES " . $insert ); // phpcs:ignore WordPress.WP.PreparedSQL.NotPrepared
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // In case it is set, but blank, update "home".
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -960,7 +961,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @global wpdb $wpdb
</span><span class="cx" style="display: block; padding: 0 10px"> * @global object $current_site
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @global int $wp_db_version
</del><span class="cx" style="display: block; padding: 0 10px"> * @global WP_Rewrite $wp_rewrite
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param int $network_id ID of network to populate.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -974,7 +974,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * so the error code must be checked) or failure.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function populate_network( $network_id = 1, $domain = '', $email = '', $site_name = '', $path = '/', $subdomain_install = false ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- global $wpdb, $current_site, $wp_db_version, $wp_rewrite;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ global $wpdb, $current_site, $wp_rewrite;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $errors = new WP_Error();
</span><span class="cx" style="display: block; padding: 0 10px"> if ( '' == $domain ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1004,13 +1004,149 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return $errors;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( 1 == $network_id ) {
+ $wpdb->insert(
+ $wpdb->site,
+ array(
+ 'domain' => $domain,
+ 'path' => $path,
+ )
+ );
+ $network_id = $wpdb->insert_id;
+ } else {
+ $wpdb->insert(
+ $wpdb->site,
+ array(
+ 'domain' => $domain,
+ 'path' => $path,
+ 'id' => $network_id,
+ )
+ );
+ }
+
+ populate_network_meta(
+ $network_id,
+ array(
+ 'admin_email' => $email,
+ 'site_name' => $site_name,
+ 'subdomain_install' => $subdomain_install,
+ )
+ );
+
+ $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 ) ) );
+
+ /*
+ * When upgrading from single to multisite, assume the current site will
+ * become the main site of the network. When using populate_network()
+ * to create another network in an existing multisite environment, skip
+ * these steps since the main site of the new network has not yet been
+ * created.
+ */
+ if ( ! is_multisite() ) {
+ $current_site = new stdClass;
+ $current_site->domain = $domain;
+ $current_site->path = $path;
+ $current_site->site_name = ucfirst( $domain );
+ $wpdb->insert(
+ $wpdb->blogs,
+ array(
+ 'site_id' => $network_id,
+ 'blog_id' => 1,
+ 'domain' => $domain,
+ 'path' => $path,
+ 'registered' => current_time( 'mysql' ),
+ )
+ );
+ $current_site->blog_id = $wpdb->insert_id;
+ update_user_meta( $site_user->ID, 'source_domain', $domain );
+ update_user_meta( $site_user->ID, 'primary_blog', $current_site->blog_id );
+
+ if ( $subdomain_install ) {
+ $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
+ } else {
+ $wp_rewrite->set_permalink_structure( '/blog/%year%/%monthnum%/%day%/%postname%/' );
+ }
+
+ flush_rewrite_rules();
+
+ if ( ! $subdomain_install ) {
+ return true;
+ }
+
+ $vhost_ok = false;
+ $errstr = '';
+ $hostname = substr( md5( time() ), 0, 6 ) . '.' . $domain; // Very random hostname!
+ $page = wp_remote_get(
+ 'http://' . $hostname,
+ array(
+ 'timeout' => 5,
+ 'httpversion' => '1.1',
+ )
+ );
+ if ( is_wp_error( $page ) ) {
+ $errstr = $page->get_error_message();
+ } elseif ( 200 == wp_remote_retrieve_response_code( $page ) ) {
+ $vhost_ok = true;
+ }
+
+ if ( ! $vhost_ok ) {
+ $msg = '<p><strong>' . __( 'Warning! Wildcard DNS may not be configured correctly!' ) . '</strong></p>';
+
+ $msg .= '<p>' . sprintf(
+ /* translators: %s: host name */
+ __( 'The installer attempted to contact a random hostname (%s) on your domain.' ),
+ '<code>' . $hostname . '</code>'
+ );
+ if ( ! empty( $errstr ) ) {
+ /* translators: %s: error message */
+ $msg .= ' ' . sprintf( __( 'This resulted in an error message: %s' ), '<code>' . $errstr . '</code>' );
+ }
+ $msg .= '</p>';
+
+ $msg .= '<p>' . sprintf(
+ /* translators: %s: asterisk symbol (*) */
+ __( '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.' ),
+ '<code>*</code>'
+ ) . '</p>';
+
+ $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>';
+
+ return new WP_Error( 'no_wildcard_dns', $msg );
+ }
+ }
+
+ return true;
+}
+
+/**
+ * Creates WordPress network meta and sets the default values.
+ *
+ * @since 5.0.0
+ *
+ * @global wpdb $wpdb WordPress database abstraction object.
+ * @global int $wp_db_version WordPress database version.
+ *
+ * @param int $network_id Network ID to populate meta for.
+ * @param array $meta Optional. Custom meta $key => $value pairs to use. Default empty array.
+ */
+function populate_network_meta( $network_id, array $meta = array() ) {
+ global $wpdb, $wp_db_version;
+
+ $network_id = (int) $network_id;
+
+ $email = ! empty( $meta['admin_email'] ) ? $meta['admin_email'] : '';
+ $subdomain_install = isset( $meta['subdomain_install'] ) ? (int) $meta['subdomain_install'] : 0;
+
</ins><span class="cx" style="display: block; padding: 0 10px"> // If a user with the provided email does not exist, default to the current user as the new network admin.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $site_user = get_user_by( 'email', $email );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $site_user = ! empty( $email ) ? get_user_by( 'email', $email ) : false;
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( false === $site_user ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $site_user = wp_get_current_user();
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Set up site tables.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( empty( $email ) ) {
+ $email = $site_user->user_email;
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> $template = get_option( 'template' );
</span><span class="cx" style="display: block; padding: 0 10px"> $stylesheet = get_option( 'stylesheet' );
</span><span class="cx" style="display: block; padding: 0 10px"> $allowed_themes = array( $stylesheet => true );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1025,31 +1161,12 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // If WP_DEFAULT_THEME doesn't exist, also whitelist the latest core default theme.
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! wp_get_theme( WP_DEFAULT_THEME )->exists() ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( $core_default = WP_Theme::get_core_default_theme() ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $core_default = WP_Theme::get_core_default_theme();
+ if ( $core_default ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $allowed_themes[ $core_default->get_stylesheet() ] = true;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( 1 == $network_id ) {
- $wpdb->insert(
- $wpdb->site,
- array(
- 'domain' => $domain,
- 'path' => $path,
- )
- );
- $network_id = $wpdb->insert_id;
- } else {
- $wpdb->insert(
- $wpdb->site,
- array(
- 'domain' => $domain,
- 'path' => $path,
- 'id' => $network_id,
- )
- );
- }
-
</del><span class="cx" style="display: block; padding: 0 10px"> wp_cache_delete( 'networks_have_paths', 'site-options' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! is_multisite() ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1089,7 +1206,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> --The Team @ SITE_NAME'
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $misc_exts = array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $misc_exts = array(
</ins><span class="cx" style="display: block; padding: 0 10px"> // Images.
</span><span class="cx" style="display: block; padding: 0 10px"> 'jpg',
</span><span class="cx" style="display: block; padding: 0 10px"> 'jpeg',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1122,7 +1239,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $upload_filetypes = array_unique( array_merge( $misc_exts, $audio_exts, $video_exts ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $sitemeta = array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'site_name' => $site_name,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'site_name' => __( 'My Network' ),
</ins><span class="cx" style="display: block; padding: 0 10px"> 'admin_email' => $email,
</span><span class="cx" style="display: block; padding: 0 10px"> 'admin_user_id' => $site_user->ID,
</span><span class="cx" style="display: block; padding: 0 10px"> 'registration' => 'none',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1140,7 +1257,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'siteurl' => get_option( 'siteurl' ) . '/',
</span><span class="cx" style="display: block; padding: 0 10px"> 'add_new_users' => '0',
</span><span class="cx" style="display: block; padding: 0 10px"> 'upload_space_check_disabled' => is_multisite() ? get_site_option( 'upload_space_check_disabled' ) : '1',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'subdomain_install' => intval( $subdomain_install ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'subdomain_install' => $subdomain_install,
</ins><span class="cx" style="display: block; padding: 0 10px"> 'global_terms_enabled' => global_terms_enabled() ? '1' : '0',
</span><span class="cx" style="display: block; padding: 0 10px"> 'ms_files_rewriting' => is_multisite() ? get_site_option( 'ms_files_rewriting' ) : '0',
</span><span class="cx" style="display: block; padding: 0 10px"> 'initial_db_version' => get_option( 'initial_db_version' ),
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1151,6 +1268,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $sitemeta['illegal_names'][] = 'blog';
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $sitemeta = wp_parse_args( $meta, $sitemeta );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Filters meta for a network on creation.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1171,87 +1290,5 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> $insert .= $wpdb->prepare( '( %d, %s, %s)', $network_id, $meta_key, $meta_value );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $wpdb->query( "INSERT INTO $wpdb->sitemeta ( site_id, meta_key, meta_value ) VALUES " . $insert );
-
- /*
- * When upgrading from single to multisite, assume the current site will
- * become the main site of the network. When using populate_network()
- * to create another network in an existing multisite environment, skip
- * these steps since the main site of the new network has not yet been
- * created.
- */
- if ( ! is_multisite() ) {
- $current_site = new stdClass;
- $current_site->domain = $domain;
- $current_site->path = $path;
- $current_site->site_name = ucfirst( $domain );
- $wpdb->insert(
- $wpdb->blogs,
- array(
- 'site_id' => $network_id,
- 'blog_id' => 1,
- 'domain' => $domain,
- 'path' => $path,
- 'registered' => current_time( 'mysql' ),
- )
- );
- $current_site->blog_id = $blog_id = $wpdb->insert_id;
- update_user_meta( $site_user->ID, 'source_domain', $domain );
- update_user_meta( $site_user->ID, 'primary_blog', $blog_id );
-
- if ( $subdomain_install ) {
- $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
- } else {
- $wp_rewrite->set_permalink_structure( '/blog/%year%/%monthnum%/%day%/%postname%/' );
- }
-
- flush_rewrite_rules();
-
- if ( ! $subdomain_install ) {
- return true;
- }
-
- $vhost_ok = false;
- $errstr = '';
- $hostname = substr( md5( time() ), 0, 6 ) . '.' . $domain; // Very random hostname!
- $page = wp_remote_get(
- 'http://' . $hostname,
- array(
- 'timeout' => 5,
- 'httpversion' => '1.1',
- )
- );
- if ( is_wp_error( $page ) ) {
- $errstr = $page->get_error_message();
- } elseif ( 200 == wp_remote_retrieve_response_code( $page ) ) {
- $vhost_ok = true;
- }
-
- if ( ! $vhost_ok ) {
- $msg = '<p><strong>' . __( 'Warning! Wildcard DNS may not be configured correctly!' ) . '</strong></p>';
-
- $msg .= '<p>' . sprintf(
- /* translators: %s: host name */
- __( 'The installer attempted to contact a random hostname (%s) on your domain.' ),
- '<code>' . $hostname . '</code>'
- );
- if ( ! empty( $errstr ) ) {
- /* translators: %s: error message */
- $msg .= ' ' . sprintf( __( 'This resulted in an error message: %s' ), '<code>' . $errstr . '</code>' );
- }
- $msg .= '</p>';
-
- $msg .= '<p>' . sprintf(
- /* translators: %s: asterisk symbol (*) */
- __( '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.' ),
- '<code>*</code>'
- ) . '</p>';
-
- $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>';
-
- return new WP_Error( 'no_wildcard_dns', $msg );
- }
- }
-
- return true;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $wpdb->query( "INSERT INTO $wpdb->sitemeta ( site_id, meta_key, meta_value ) VALUES " . $insert ); // phpcs:ignore WordPress.WP.PreparedSQL.NotPrepared
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunktestsphpunittestsadminincludesSchemaphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/admin/includesSchema.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/admin/includesSchema.php 2018-09-05 09:38:04 UTC (rev 43627)
+++ trunk/tests/phpunit/tests/admin/includesSchema.php 2018-09-05 10:44:02 UTC (rev 43628)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,4 +1,5 @@
</span><span class="cx" style="display: block; padding: 0 10px"> <?php
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+// phpcs:ignoreFile WordPress.WP.PreparedSQL.NotPrepared
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * @group admin
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -6,6 +7,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> class Tests_Admin_Includes_Schema extends WP_UnitTestCase {
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> private static $options;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ private static $sitemeta;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Make sure the schema code is loaded before the tests are run.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -14,8 +16,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> global $wpdb;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> self::$options = 'testprefix_options';
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ self::$sitemeta = 'testprefix_sitemeta';
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $options = self::$options;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $options = self::$options;
+ $sitemeta = self::$sitemeta;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> require_once( ABSPATH . 'wp-admin/includes/schema.php' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -34,6 +38,19 @@
</span><span class="cx" style="display: block; padding: 0 10px"> ) {$charset_collate}
</span><span class="cx" style="display: block; padding: 0 10px"> "
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $wpdb->query(
+ "
+ CREATE TABLE {$sitemeta} (
+ meta_id bigint(20) unsigned NOT NULL auto_increment,
+ site_id bigint(20) unsigned NOT NULL default '0',
+ meta_key varchar(255) default NULL,
+ meta_value longtext,
+ PRIMARY KEY (meta_id),
+ KEY meta_key (meta_key({$max_index_length})),
+ KEY site_id (site_id)
+ ) {$charset_collate}
+ "
+ );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -42,9 +59,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> public static function wpTearDownAfterClass() {
</span><span class="cx" style="display: block; padding: 0 10px"> global $wpdb;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $options = self::$options;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $options = self::$options;
+ $sitemeta = self::$sitemeta;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $wpdb->query( "DROP TABLE IF EXISTS {$options}" );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $wpdb->query( "DROP TABLE IF EXISTS {$sitemeta}" );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -54,10 +73,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> function test_populate_options( $options, $expected ) {
</span><span class="cx" style="display: block; padding: 0 10px"> global $wpdb;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- remove_all_filters( 'option_admin_email' );
- remove_all_filters( 'pre_option_admin_email' );
- remove_all_filters( 'default_option_admin_email' );
-
</del><span class="cx" style="display: block; padding: 0 10px"> $orig_options = $wpdb->options;
</span><span class="cx" style="display: block; padding: 0 10px"> $wpdb->options = self::$options;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -92,8 +107,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> array(
</span><span class="cx" style="display: block; padding: 0 10px"> array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'posts_per_rss' => 7,
- 'rss_use_excerpt' => 1,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'posts_per_rss' => 7,
+ 'rss_use_excerpt' => 1,
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> array(
</span><span class="cx" style="display: block; padding: 0 10px"> // Random options to check.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -129,15 +144,83 @@
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> array(
</span><span class="cx" style="display: block; padding: 0 10px"> array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'rss_0123456789abcdef0123456789abcdef' => '1',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'rss_0123456789abcdef0123456789abcdef' => '1',
</ins><span class="cx" style="display: block; padding: 0 10px"> 'rss_0123456789abcdef0123456789abcdef_ts' => '1',
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> array(
</span><span class="cx" style="display: block; padding: 0 10px"> // These options would be obsolete magpie cache data and should never exist.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'rss_0123456789abcdef0123456789abcdef' => false,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'rss_0123456789abcdef0123456789abcdef' => false,
</ins><span class="cx" style="display: block; padding: 0 10px"> 'rss_0123456789abcdef0123456789abcdef_ts' => false,
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ /**
+ * @ticket 44895
+ * @dataProvider data_populate_network_meta
+ */
+ function test_populate_network_meta( $meta, $expected ) {
+ global $wpdb;
+
+ $orig_sitemeta = $wpdb->sitemeta;
+ $wpdb->sitemeta = self::$sitemeta;
+
+ populate_network_meta( 42, $meta );
+
+ $results = array();
+ foreach ( $expected as $meta_key => $value ) {
+ if ( is_multisite() ) {
+ $results[ $meta_key ] = get_network_option( 42, $meta_key );
+ } else {
+ $results[ $meta_key ] = $wpdb->get_var( $wpdb->prepare( "SELECT meta_value FROM {$wpdb->sitemeta} WHERE meta_key = %s AND site_id = %d", $meta_key, 42 ) );
+ }
+ }
+
+ $wpdb->query( "TRUNCATE TABLE {$wpdb->sitemeta}" );
+
+ $wpdb->sitemeta = $orig_sitemeta;
+
+ $this->assertEquals( $expected, $results );
+ }
+
+ public function data_populate_network_meta() {
+ return array(
+ array(
+ array(),
+ array(
+ // Random meta to check.
+ 'registration' => 'none',
+ 'blog_upload_space' => 100,
+ 'fileupload_maxk' => 1500,
+ ),
+ ),
+ array(
+ array(
+ 'site_name' => 'My Great Network',
+ 'WPLANG' => 'fr_FR',
+ ),
+ array(
+ // Random meta to check.
+ 'site_name' => 'My Great Network',
+ 'registration' => 'none',
+ 'blog_upload_space' => 100,
+ 'fileupload_maxk' => 1500,
+ 'WPLANG' => 'fr_FR',
+ ),
+ ),
+ array(
+ array(
+ 'custom_meta' => '1',
+ ),
+ array(
+ // Random meta to check.
+ 'custom_meta' => '1',
+ 'registration' => 'none',
+ 'blog_upload_space' => 100,
+ 'fileupload_maxk' => 1500,
+ ),
+ ),
+ );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre>
</div>
</div>
</body>
</html>