<!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>[32759] trunk/src/wp-admin/network/site-info.php: Capture domain and path when editing sites on a subdomain 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 { 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/32759">32759</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/32759","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>jeremyfelt</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2015-06-14 07:08:30 +0000 (Sun, 14 Jun 2015)</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'>Capture domain and path when editing sites on a subdomain network
When a network is configured as subdomain, allow for the input of arbitrary domain and path combinations when editing a site rather than just the domain.
This takes a step or two toward <a href="https://core.trac.wordpress.org/ticket/32503">#32503</a>.
Props @scribu, @ericlewis, @jeremyfelt.
See <a href="https://core.trac.wordpress.org/ticket/22383">#22383</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadminnetworksiteinfophp">trunk/src/wp-admin/network/site-info.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpadminnetworksiteinfophp"></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/network/site-info.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/network/site-info.php 2015-06-14 05:00:27 UTC (rev 32758)
+++ trunk/src/wp-admin/network/site-info.php 2015-06-14 07:08:30 UTC (rev 32759)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -46,7 +46,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> wp_die( __( 'You do not have permission to access this page.' ), 403 );
</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">-$parsed = parse_url( $details->siteurl );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+$parsed_scheme = parse_url( $details->siteurl, PHP_URL_SCHEME );
</ins><span class="cx" style="display: block; padding: 0 10px"> $is_main_site = is_main_site( $id );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( isset( $_REQUEST['action'] ) && 'update-site' == $_REQUEST['action'] ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -57,8 +57,31 @@
</span><span class="cx" style="display: block; padding: 0 10px"> // Rewrite rules can't be flushed during switch to blog.
</span><span class="cx" style="display: block; padding: 0 10px"> delete_option( 'rewrite_rules' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Update blogs table.
</del><span class="cx" style="display: block; padding: 0 10px"> $blog_data = wp_unslash( $_POST['blog'] );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ if ( $is_main_site ) {
+ // On the network's main site, don't allow the domain or path to change.
+ $blog_data['domain'] = $details->domain;
+ $blog_data['path'] = $details->path;
+ } elseif ( is_subdomain_install() ) {
+ // All parts of a URL can be updated for a subdomain configuration. We first
+ // need to ensure a scheme has been provided, otherwise fallback to the existing.
+ $new_url_scheme = parse_url( $blog_data['url'], PHP_URL_SCHEME );
+
+ if ( ! $new_url_scheme ) {
+ $blog_data['url'] = esc_url( $parsed_scheme . '://' . $blog_data['url'] );
+ }
+ $update_parsed_url = parse_url( $blog_data['url'] );
+
+ $blog_data['scheme'] = $update_parsed_url['scheme'];
+ $blog_data['domain'] = $update_parsed_url['host'];
+ $blog_data['path'] = $update_parsed_url['path'];
+ } else {
+ // Only the path can be updated for a subdirectory configuration, so capture existing domain.
+ $blog_data['scheme'] = $parsed_scheme;
+ $blog_data['domain'] = $details->domain;
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> $existing_details = get_blog_details( $id, false );
</span><span class="cx" style="display: block; padding: 0 10px"> $blog_data_checkboxes = array( 'public', 'archived', 'spam', 'mature', 'deleted' );
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( $blog_data_checkboxes as $c ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -68,11 +91,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $blog_data[ $c ] = isset( $_POST['blog'][ $c ] ) ? 1 : 0;
</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">+
</ins><span class="cx" style="display: block; padding: 0 10px"> update_blog_details( $id, $blog_data );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( isset( $_POST['update_home_url'] ) && $_POST['update_home_url'] == 'update' ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $new_details = get_blog_details( $id, false );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $blog_address = esc_url_raw( $new_details->domain . $new_details->path );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $blog_address = untrailingslashit( esc_url_raw( $blog_data['scheme'] . '://' . $new_details->domain . $new_details->path ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( get_option( 'siteurl' ) != $blog_address ) {
</span><span class="cx" style="display: block; padding: 0 10px"> update_option( 'siteurl', $blog_address );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -125,37 +149,53 @@
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( $messages as $msg ) {
</span><span class="cx" style="display: block; padding: 0 10px"> echo '<div id="message" class="updated notice is-dismissible"><p>' . $msg . '</p></div>';
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-} ?>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+}
+
+switch_to_blog( $id );
+?>
</ins><span class="cx" style="display: block; padding: 0 10px"> <form method="post" action="site-info.php?action=update-site">
</span><span class="cx" style="display: block; padding: 0 10px"> <?php wp_nonce_field( 'edit-site' ); ?>
</span><span class="cx" style="display: block; padding: 0 10px"> <input type="hidden" name="id" value="<?php echo esc_attr( $id ) ?>" />
</span><span class="cx" style="display: block; padding: 0 10px"> <table class="form-table">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ <?php
+ // The main site of the network should not be updated on this page.
+ if ( $is_main_site ) : ?>
+ <tr class="form-field">
+ <th scope="row"><?php _e( 'Site URL' ); ?></th>
+ <td><?php echo esc_url( $details->siteurl ); ?></td>
+ </tr>
+ <?php
+ // In a subdomain configuration, the scheme, domain, and path can all be changed.
+ elseif ( is_subdomain_install() ) : ?>
</ins><span class="cx" style="display: block; padding: 0 10px"> <tr class="form-field form-required">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- <?php if ( $is_main_site ) { ?>
- <th scope="row"><?php _e( 'Domain' ) ?></th>
- <td><code><?php echo $parsed['scheme'] . '://' . esc_attr( $details->domain ) ?></code></td>
- <?php } else { ?>
- <th scope="row"><label for="domain"><?php _e( 'Domain' ) ?></label></th>
- <td><?php echo $parsed['scheme'] . '://'; ?><input name="blog[domain]" type="text" id="domain" value="<?php echo esc_attr( $details->domain ) ?>" /></td>
- <?php } ?>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ <th scope="row"><?php _e( 'Site URL' ); ?></th>
+ <td><input name="blog[url]" type="text" id="url" value="<?php echo $parsed_scheme . '://' . esc_attr( $details->domain ) . esc_attr( $details->path ); ?>" /></td>
</ins><span class="cx" style="display: block; padding: 0 10px"> </tr>
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ <?php
+ // In a subdirectory configuration, only the path can be changed.
+ // Scheme and domain are inherited from the network.
+ else : ?>
+ <tr class="form-field">
+ <th scope="row"><?php _e( 'Domain' ); ?></th>
+ <td><?php echo $parsed_scheme . ':// ' . esc_attr( $details->domain ); ?></td>
+ </tr>
</ins><span class="cx" style="display: block; padding: 0 10px"> <tr class="form-field form-required">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- <?php if ( $is_main_site ) { ?>
- <th scope="row"><?php _e( 'Path' ) ?></th>
- <td><code><?php echo esc_attr( $details->path ) ?></code></td>
- <?php
- } else {
- switch_to_blog( $id );
- ?>
</del><span class="cx" style="display: block; padding: 0 10px"> <th scope="row"><label for="path"><?php _e( 'Path' ) ?></label></th>
</span><span class="cx" style="display: block; padding: 0 10px"> <td>
</span><span class="cx" style="display: block; padding: 0 10px"> <input name="blog[path]" type="text" id="path" value="<?php echo esc_attr( $details->path ) ?>" /><br />
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ </td>
+ </tr>
+ <?php endif; ?>
+
+ <?php if ( ! $is_main_site ) : ?>
+ <tr class="form-field">
+ <th scope="row"></th>
+ <td>
</ins><span class="cx" style="display: block; padding: 0 10px"> <input type="checkbox" name="update_home_url" id="update_home_url" value="update" <?php if ( get_option( 'siteurl' ) == untrailingslashit( get_blogaddress_by_id ($id ) ) || get_option( 'home' ) == untrailingslashit( get_blogaddress_by_id( $id ) ) ) echo 'checked="checked"'; ?> /> <label for="update_home_url"><?php _e( 'Update <code>siteurl</code> and <code>home</code> as well.' ); ?></label>
</span><span class="cx" style="display: block; padding: 0 10px"> </td>
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- <?php
- restore_current_blog();
- } ?>
</del><span class="cx" style="display: block; padding: 0 10px"> </tr>
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ <?php endif; ?>
+
</ins><span class="cx" style="display: block; padding: 0 10px"> <tr class="form-field">
</span><span class="cx" style="display: block; padding: 0 10px"> <th scope="row"><label for="blog_registered"><?php _ex( 'Registered', 'site' ) ?></label></th>
</span><span class="cx" style="display: block; padding: 0 10px"> <td><input name="blog[registered]" type="text" id="blog_registered" value="<?php echo esc_attr( $details->registered ) ?>" /></td>
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -191,4 +231,5 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> </div>
</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">+restore_current_blog();
</ins><span class="cx" style="display: block; padding: 0 10px"> require( ABSPATH . 'wp-admin/admin-footer.php' );
</span></span></pre>
</div>
</div>
</body>
</html>