<!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" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { 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 #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#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>
<title>[12978] trunk: Introduce get_home_url(), get_site_url(), and get_admin_url(
) for fetching urls by blog id.</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/12978">12978</a></dd>
<dt>Author</dt> <dd>ryan</dd>
<dt>Date</dt> <dd>2010-02-05 21:49:19 +0000 (Fri, 05 Feb 2010)</dd>
</dl>
<h3>Log Message</h3>
<pre>Introduce get_home_url(), get_site_url(), and get_admin_url() for fetching urls by blog id. see <a href="http://trac.wordpress.org/ticket/12119">#12119</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminmseditphp">trunk/wp-admin/ms-edit.php</a></li>
<li><a href="#trunkwpadminmsoptionsphp">trunk/wp-admin/ms-options.php</a></li>
<li><a href="#trunkwpadminmssitesphp">trunk/wp-admin/ms-sites.php</a></li>
<li><a href="#trunkwpincludeslinktemplatephp">trunk/wp-includes/link-template.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminmseditphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/ms-edit.php (12977 => 12978)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/ms-edit.php        2010-02-05 21:40:22 UTC (rev 12977)
+++ trunk/wp-admin/ms-edit.php        2010-02-05 21:49:19 UTC (rev 12978)
</span><span class="lines">@@ -207,11 +207,12 @@
</span><span class="cx">                 }
</span><span class="cx">
</span><span class="cx">                 if ( $_POST['update_home_url'] == 'update' ) {
</span><del>-                        if ( get_option( 'siteurl' ) != 'http://' . $_POST['blog']['domain'] . $_POST['blog']['path'] )
-                                update_option( 'siteurl', 'http://' . $_POST['blog']['domain'] . $_POST['blog']['path'] );
</del><ins>+                        $blog_address = get_blogaddress_by_domain($_POST['blog']['domain'], $_POST['blog']['path']);
+                        if ( get_option( 'siteurl' ) != $blog_address )
+                                update_option( 'siteurl', $blog_address);
</ins><span class="cx">
</span><del>-                        if ( get_option( 'home' ) != 'http://' . $_POST['blog']['domain'] . $_POST['blog']['path'] )
-                                update_option( 'home', 'http://' . $_POST['blog']['domain'] . $_POST['blog']['path'] );
</del><ins>+                        if ( get_option( 'home' ) != $blog_address )
+                                update_option( 'home', $blog_address );
</ins><span class="cx">                 }
</span><span class="cx">
</span><span class="cx">                 $wp_rewrite->flush_rules();
</span></span></pre></div>
<a id="trunkwpadminmsoptionsphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/ms-options.php (12977 => 12978)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/ms-options.php        2010-02-05 21:40:22 UTC (rev 12977)
+++ trunk/wp-admin/ms-options.php        2010-02-05 21:49:19 UTC (rev 12978)
</span><span class="lines">@@ -38,7 +38,7 @@
</span><span class="cx">                         <tr valign="top">
</span><span class="cx">                                 <th scope="row"><?php _e('Site Admin Email') ?></th>
</span><span class="cx">                                 <td>
</span><del>-                                        <input name="admin_email" type="text" id="admin_email" style="width: 95%" value="<?php echo esc_attr( stripslashes( get_site_option('admin_email') ) ) ?>" size="45" />
</del><ins>+                                        <input name="admin_email" type="text" id="admin_email" style="width: 95%" value="<?php echo esc_attr( get_site_option('admin_email') ) ?>" size="45" />
</ins><span class="cx">                                         <br />
</span><span class="cx">                                         <?php printf( __( 'Registration and support mails will come from this address. Make it generic like "support@%s"' ), $current_site->domain ); ?>
</span><span class="cx">                                 </td>
</span></span></pre></div>
<a id="trunkwpadminmssitesphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/ms-sites.php (12977 => 12978)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/ms-sites.php        2010-02-05 21:40:22 UTC (rev 12977)
+++ trunk/wp-admin/ms-sites.php        2010-02-05 21:49:19 UTC (rev 12978)
</span><span class="lines">@@ -82,7 +82,7 @@
</span><span class="cx">                 ?>
</span><span class="cx">                 <div class="wrap">
</span><span class="cx">                 <?php screen_icon(); ?>
</span><del>-                <h2><?php _e('Edit Site'); ?> - <a href='http://<?php echo $details->domain . $details->path; ?>'>http://<?php echo $details->domain . $details->path; ?></a></h2>
</del><ins>+                <h2><?php _e('Edit Site'); ?> - <a href='<?php echo get_home_url($id); ?>'><?php echo get_home_url($id); ?></a></h2>
</ins><span class="cx">                 <form method="post" action="ms-edit.php?action=updateblog">
</span><span class="cx">                         <?php wp_nonce_field('editblog'); ?>
</span><span class="cx">                         <input type="hidden" name="id" value="<?php echo esc_attr($id) ?>" />
</span><span class="lines">@@ -93,12 +93,12 @@
</span><span class="cx">                                 <table class="form-table">
</span><span class="cx">                                                         <tr class="form-field form-required">
</span><span class="cx">                                                                 <th scope="row"><?php _e('Domain') ?></th>
</span><del>-                                                                <td>http://<input name="blog[domain]" type="text" id="domain" value="<?php echo $details->domain ?>" size="33" /></td>
</del><ins>+                                                                <td>http://<input name="blog[domain]" type="text" id="domain" value="<?php echo esc_attr($details->domain) ?>" size="33" /></td>
</ins><span class="cx">                                                         </tr>
</span><span class="cx">                                                         <tr class="form-field form-required">
</span><span class="cx">                                                                 <th scope="row"><?php _e('Path') ?></th>
</span><span class="cx">                                                                 <td><input name="blog[path]" type="text" id="path" value="<?php echo esc_attr($details->path) ?>" size="40" style='margin-bottom:5px;' />
</span><del>-                                                                <br /><input type='checkbox' style='width:20px;' name='update_home_url' value='update' <?php if ( get_blog_option( $id, 'siteurl' ) == preg_replace('|/+$|', '', 'http://' . $details->domain . $details->path) || get_blog_option( $id, 'home' ) == preg_replace('|/+$|', '', 'http://' . $details->domain . $details->path) ) echo 'checked="checked"'; ?> /> <?php _e( "Update 'siteurl' and 'home' as well." ); ?></td>
</del><ins>+                                                                <br /><input type='checkbox' style='width:20px;' name='update_home_url' value='update' <?php if ( get_blog_option( $id, 'siteurl' ) == untrailingslashit( get_blogaddress_by_id($id) ) || get_blog_option( $id, 'home' ) == untrailingslashit( get_blogaddress_by_id($id) ) ) echo 'checked="checked"'; ?> /> <?php _e( "Update 'siteurl' and 'home' as well." ); ?></td>
</ins><span class="cx">                                                         </tr>
</span><span class="cx">                                                         <tr class="form-field">
</span><span class="cx">                                                                 <th scope="row"><?php _e('Registered') ?></th>
</span><span class="lines">@@ -446,6 +446,7 @@
</span><span class="cx">                         <?php
</span><span class="cx">                         if ( $blog_list ) {
</span><span class="cx">                                 $status_list = array( 'archived' => array( 'site-archived', __('Archived') ), 'spam' => array( 'site-spammed', __('Spam') ), 'deleted' => array( 'site-deleted', __('Deleted') ) );
</span><ins>+                                $class = '';
</ins><span class="cx">                                 foreach ( $blog_list as $blog ) {
</span><span class="cx">                                         $class = ('alternate' == $class) ? '' : 'alternate';
</span><span class="cx">                                         reset( $status_list );
</span><span class="lines">@@ -490,7 +491,7 @@
</span><span class="cx">                                                                         <?php
</span><span class="cx">                                                                         $actions        = array();
</span><span class="cx">                                                                         $actions[]        = '<a href="ms-sites.php?action=editblog&amp;id=' . $blog['blog_id'] . '" class="edit">' . __('Edit') . '</a>';
</span><del>-                                                                        $actions[]        = "<a href='{$protocol}{$blog['domain']}{$blog['path']}wp-admin/' class='edit'>" . __('Backend') . '</a>';
</del><ins>+                                                                        $actions[]        = "<a href='" . get_admin_url($blog['blog_id']) . "' class='edit'>" . __('Backend') . '</a>';
</ins><span class="cx">
</span><span class="cx">                                                                         if ( get_blog_status( $blog['blog_id'], "deleted" ) == '1' )
</span><span class="cx">                                                                                 $actions[]        = '<a class="delete" href="ms-edit.php?action=confirm&amp;action2=activateblog&amp;ref=' . urlencode( $_SERVER['REQUEST_URI'] ) . '&amp;id=' . $blog['blog_id'] . '&amp;msg=' . urlencode( sprintf( __( "You are about to activate the blog %s" ), $blogname ) ) . '">' . __('Activate') . '</a>';
</span><span class="lines">@@ -509,7 +510,7 @@
</span><span class="cx">
</span><span class="cx">                                                                         $actions[]        = '<a class="delete" href="ms-edit.php?action=confirm&amp;action2=deleteblog&amp;id=' . $blog['blog_id'] . '&amp;msg=' . urlencode( sprintf( __( "You are about to delete the blog %s" ), $blogname ) ) . '">' . __("Delete") . '</a>';
</span><span class="cx">
</span><del>-                                                                        $actions[]        = "<a href='http://{$blog['domain']}{$blog['path']}' rel='permalink'>" . __('Visit') . '</a>';
</del><ins>+                                                                        $actions[]        = "<a href='" . get_home_url($blog['blog_id']) . "' rel='permalink'>" . __('Visit') . '</a>';
</ins><span class="cx">                                                                         ?>
</span><span class="cx">
</span><span class="cx">                                                                         <?php if ( count($actions) ) : ?>
</span><span class="lines">@@ -542,7 +543,7 @@
</span><span class="cx">                                                                                 $blogusers_warning = '';
</span><span class="cx">                                                                                 if ( count( $blogusers ) > 5 ) {
</span><span class="cx">                                                                                         $blogusers = array_slice( $blogusers, 0, 5 );
</span><del>-                                                                                        $blogusers_warning = __( 'Only showing first 5 users.' ) . ' <a href="' . $protocol . $blog[ 'domain' ] . $blog[ 'path' ] . 'wp-admin/users.php">' . __( 'More' ) . '</a>';
</del><ins>+                                                                                        $blogusers_warning = __( 'Only showing first 5 users.' ) . ' <a href="' . get_admin_url($blog['blog_id'], 'users.php') . '">' . __( 'More' ) . '</a>';
</ins><span class="cx">                                                                                 }
</span><span class="cx">                                                                                 foreach ( $blogusers as $key => $val )
</span><span class="cx">                                                                                         echo '<a href="user-edit.php?user_id=' . $val->user_id . '">' . $val->user_login . '</a> ('.$val->user_email.')<br />';
</span></span></pre></div>
<a id="trunkwpincludeslinktemplatephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/link-template.php (12977 => 12978)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/link-template.php        2010-02-05 21:40:22 UTC (rev 12977)
+++ trunk/wp-includes/link-template.php        2010-02-05 21:49:19 UTC (rev 12978)
</span><span class="lines">@@ -1732,32 +1732,59 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Retrieve the home url.
</del><ins>+ * Retrieve the home url for the current site.
</ins><span class="cx"> *
</span><span class="cx"> * Returns the 'home' option with the appropriate protocol, 'https' if
</span><span class="cx"> * is_ssl() and 'http' otherwise. If $scheme is 'http' or 'https', is_ssl() is
</span><span class="cx"> * overridden.
</span><span class="cx"> *
</span><span class="cx"> * @package WordPress
</span><del>- * @since 3.0
</del><ins>+ * @since 3.0.0
</ins><span class="cx"> *
</span><ins>+ * @uses get_home_url()
+ *
</ins><span class="cx"> * @param string $path (optional) Path relative to the home url.
</span><span class="cx"> * @param string $scheme (optional) Scheme to give the home url context. Currently 'http','https'
</span><span class="cx"> * @return string Home url link with optional path appended.
</span><span class="cx"> */
</span><span class="cx"> function home_url( $path = '', $scheme = null ) {
</span><ins>+        return get_home_url(null, $path, $scheme);
+}
+
+/**
+ * Retrieve the home url for a given site.
+ *
+ * Returns the 'home' option with the appropriate protocol, 'https' if
+ * is_ssl() and 'http' otherwise. If $scheme is 'http' or 'https', is_ssl() is
+ * overridden.
+ *
+ * @package WordPress
+ * @since 3.0.0
+ *
+ * @param int $blog_id (optional) Blog ID. Defaults to current blog.
+ * @param string $path (optional) Path relative to the home url.
+ * @param string $scheme (optional) Scheme to give the home url context. Currently 'http','https'
+ * @return string Home url link with optional path appended.
+*/
+function get_home_url( $blog_id = null, $path = '', $scheme = null ) {
</ins><span class="cx">         $orig_scheme = $scheme;
</span><span class="cx">         $scheme = is_ssl() && !is_admin() ? 'https' : 'http';
</span><del>-        $url = str_replace( 'http://', "$scheme://", get_option('home') );
</del><span class="cx">
</span><ins>+        if ( empty($blog_id) || !is_multisite() )
+                $home = get_option('home');
+        else
+                $home = untrailingslashit(get_blogaddress_by_id($blog_id));
+
+        $url = str_replace( 'http://', "$scheme://", $home );
+
</ins><span class="cx">         if ( !empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false )
</span><span class="cx">                 $url .= '/' . ltrim( $path, '/' );
</span><span class="cx">
</span><del>-        return apply_filters( 'home_url', $url, $path, $orig_scheme );
</del><ins>+        return apply_filters( 'home_url', $url, $path, $orig_scheme, $blog_id );
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Retrieve the site url.
</del><ins>+ * Retrieve the site url for the current site.
</ins><span class="cx"> *
</span><span class="cx"> * Returns the 'site_url' option with the appropriate protocol, 'https' if
</span><span class="cx"> * is_ssl() and 'http' otherwise. If $scheme is 'http' or 'https', is_ssl() is
</span><span class="lines">@@ -1766,11 +1793,32 @@
</span><span class="cx"> * @package WordPress
</span><span class="cx"> * @since 2.6.0
</span><span class="cx"> *
</span><ins>+ * @uses get_site_url()
+ *
</ins><span class="cx"> * @param string $path Optional. Path relative to the site url.
</span><span class="cx"> * @param string $scheme Optional. Scheme to give the site url context. Currently 'http','https', 'login', 'login_post', or 'admin'.
</span><span class="cx"> * @return string Site url link with optional path appended.
</span><span class="cx"> */
</span><del>-function site_url($path = '', $scheme = null) {
</del><ins>+function site_url( $path = '', $scheme = null ) {
+        return get_site_url(null, $path, $scheme);
+}
+
+/**
+ * Retrieve the site url for a given site.
+ *
+ * Returns the 'site_url' option with the appropriate protocol, 'https' if
+ * is_ssl() and 'http' otherwise. If $scheme is 'http' or 'https', is_ssl() is
+ * overridden.
+ *
+ * @package WordPress
+ * @since 3.0.0
+ *
+ * @param int $blog_id (optional) Blog ID. Defaults to current blog.
+ * @param string $path Optional. Path relative to the site url.
+ * @param string $scheme Optional. Scheme to give the site url context. Currently 'http','https', 'login', 'login_post', or 'admin'.
+ * @return string Site url link with optional path appended.
+*/
+function get_site_url( $blog_id = null, $path = '', $scheme = null ) {
</ins><span class="cx">         // should the list of allowed schemes be maintained elsewhere?
</span><span class="cx">         $orig_scheme = $scheme;
</span><span class="cx">         if ( !in_array($scheme, array('http', 'https')) ) {
</span><span class="lines">@@ -1784,16 +1832,21 @@
</span><span class="cx">                         $scheme = ( is_ssl() ? 'https' : 'http' );
</span><span class="cx">         }
</span><span class="cx">
</span><del>-        $url = str_replace( 'http://', "{$scheme}://", get_option('siteurl') );
</del><ins>+        if ( empty($blog_id) || !is_multisite() )
+                $url = get_option('siteurl');
+        else
+                $url = untrailingslashit(get_blogaddress_by_id($blog_id));
</ins><span class="cx">
</span><ins>+        $url = str_replace( 'http://', "{$scheme}://", $url );
+
</ins><span class="cx">         if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
</span><span class="cx">                 $url .= '/' . ltrim($path, '/');
</span><span class="cx">
</span><del>-        return apply_filters('site_url', $url, $path, $orig_scheme);
</del><ins>+        return apply_filters('site_url', $url, $path, $orig_scheme, $blog_id);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Retrieve the url to the admin area.
</del><ins>+ * Retrieve the url to the admin area for the current site.
</ins><span class="cx"> *
</span><span class="cx"> * @package WordPress
</span><span class="cx"> * @since 2.6.0
</span><span class="lines">@@ -1801,13 +1854,27 @@
</span><span class="cx"> * @param string $path Optional path relative to the admin url
</span><span class="cx"> * @return string Admin url link with optional path appended
</span><span class="cx"> */
</span><del>-function admin_url($path = '') {
-        $url = site_url('wp-admin/', 'admin');
</del><ins>+function admin_url( $path = '' ) {
+        return get_admin_url(null, $path);
+}
</ins><span class="cx">
</span><ins>+/**
+ * Retrieve the url to the admin area for a given site.
+ *
+ * @package WordPress
+ * @since 3.0.0
+ *
+ * @param int $blog_id (optional) Blog ID. Defaults to current blog.
+ * @param string $path Optional path relative to the admin url
+ * @return string Admin url link with optional path appended
+*/
+function get_admin_url( $blog_id = null, $path = '' ) {
+        $url = get_site_url($blog_id, 'wp-admin/', 'admin');
+
</ins><span class="cx">         if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
</span><span class="cx">                 $url .= ltrim($path, '/');
</span><span class="cx">
</span><del>-        return apply_filters('admin_url', $url, $path);
</del><ins>+        return apply_filters('admin_url', $url, $path, $blog_id);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span></span></pre>
</div>
</div>
</body>
</html>