<!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-&gt;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">                         &lt;tr valign=&quot;top&quot;&gt;
</span><span class="cx">                                 &lt;th scope=&quot;row&quot;&gt;&lt;?php _e('Site Admin Email') ?&gt;&lt;/th&gt;
</span><span class="cx">                                 &lt;td&gt;
</span><del>-                                        &lt;input name=&quot;admin_email&quot; type=&quot;text&quot; id=&quot;admin_email&quot; style=&quot;width: 95%&quot; value=&quot;&lt;?php echo esc_attr( stripslashes( get_site_option('admin_email') ) ) ?&gt;&quot; size=&quot;45&quot; /&gt;
</del><ins>+                                        &lt;input name=&quot;admin_email&quot; type=&quot;text&quot; id=&quot;admin_email&quot; style=&quot;width: 95%&quot; value=&quot;&lt;?php echo esc_attr( get_site_option('admin_email') ) ?&gt;&quot; size=&quot;45&quot; /&gt;
</ins><span class="cx">                                         &lt;br /&gt;
</span><span class="cx">                                         &lt;?php printf( __( 'Registration and support mails will come from this address. Make it generic like &quot;support@%s&quot;' ), $current_site-&gt;domain ); ?&gt;
</span><span class="cx">                                 &lt;/td&gt;
</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">                 ?&gt;
</span><span class="cx">                 &lt;div class=&quot;wrap&quot;&gt;
</span><span class="cx">                 &lt;?php screen_icon(); ?&gt;
</span><del>-                &lt;h2&gt;&lt;?php _e('Edit Site'); ?&gt; - &lt;a href='http://&lt;?php echo $details-&gt;domain . $details-&gt;path; ?&gt;'&gt;http://&lt;?php echo $details-&gt;domain . $details-&gt;path; ?&gt;&lt;/a&gt;&lt;/h2&gt;
</del><ins>+                &lt;h2&gt;&lt;?php _e('Edit Site'); ?&gt; - &lt;a href='&lt;?php echo get_home_url($id); ?&gt;'&gt;&lt;?php echo get_home_url($id); ?&gt;&lt;/a&gt;&lt;/h2&gt;
</ins><span class="cx">                 &lt;form method=&quot;post&quot; action=&quot;ms-edit.php?action=updateblog&quot;&gt;
</span><span class="cx">                         &lt;?php wp_nonce_field('editblog'); ?&gt;
</span><span class="cx">                         &lt;input type=&quot;hidden&quot; name=&quot;id&quot; value=&quot;&lt;?php echo esc_attr($id) ?&gt;&quot; /&gt;
</span><span class="lines">@@ -93,12 +93,12 @@
</span><span class="cx">                                 &lt;table class=&quot;form-table&quot;&gt;
</span><span class="cx">                                                         &lt;tr class=&quot;form-field form-required&quot;&gt;
</span><span class="cx">                                                                 &lt;th scope=&quot;row&quot;&gt;&lt;?php _e('Domain') ?&gt;&lt;/th&gt;
</span><del>-                                                                &lt;td&gt;http://&lt;input name=&quot;blog[domain]&quot; type=&quot;text&quot; id=&quot;domain&quot; value=&quot;&lt;?php echo $details-&gt;domain ?&gt;&quot; size=&quot;33&quot; /&gt;&lt;/td&gt;
</del><ins>+                                                                &lt;td&gt;http://&lt;input name=&quot;blog[domain]&quot; type=&quot;text&quot; id=&quot;domain&quot; value=&quot;&lt;?php echo esc_attr($details-&gt;domain) ?&gt;&quot; size=&quot;33&quot; /&gt;&lt;/td&gt;
</ins><span class="cx">                                                         &lt;/tr&gt;
</span><span class="cx">                                                         &lt;tr class=&quot;form-field form-required&quot;&gt;
</span><span class="cx">                                                                 &lt;th scope=&quot;row&quot;&gt;&lt;?php _e('Path') ?&gt;&lt;/th&gt;
</span><span class="cx">                                                                 &lt;td&gt;&lt;input name=&quot;blog[path]&quot; type=&quot;text&quot; id=&quot;path&quot; value=&quot;&lt;?php echo esc_attr($details-&gt;path) ?&gt;&quot; size=&quot;40&quot; style='margin-bottom:5px;' /&gt;
</span><del>-                                                                &lt;br /&gt;&lt;input type='checkbox' style='width:20px;' name='update_home_url' value='update' &lt;?php if ( get_blog_option( $id, 'siteurl' ) == preg_replace('|/+$|', '', 'http://' . $details-&gt;domain . $details-&gt;path) || get_blog_option( $id, 'home' ) == preg_replace('|/+$|', '', 'http://' . $details-&gt;domain . $details-&gt;path) ) echo 'checked=&quot;checked&quot;'; ?&gt; /&gt; &lt;?php _e( &quot;Update 'siteurl' and 'home' as well.&quot; ); ?&gt;&lt;/td&gt;
</del><ins>+                                                                &lt;br /&gt;&lt;input type='checkbox' style='width:20px;' name='update_home_url' value='update' &lt;?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=&quot;checked&quot;'; ?&gt; /&gt; &lt;?php _e( &quot;Update 'siteurl' and 'home' as well.&quot; ); ?&gt;&lt;/td&gt;
</ins><span class="cx">                                                         &lt;/tr&gt;
</span><span class="cx">                                                         &lt;tr class=&quot;form-field&quot;&gt;
</span><span class="cx">                                                                 &lt;th scope=&quot;row&quot;&gt;&lt;?php _e('Registered') ?&gt;&lt;/th&gt;
</span><span class="lines">@@ -446,6 +446,7 @@
</span><span class="cx">                         &lt;?php
</span><span class="cx">                         if ( $blog_list ) {
</span><span class="cx">                                 $status_list = array( 'archived' =&gt; array( 'site-archived', __('Archived') ), 'spam' =&gt; array( 'site-spammed', __('Spam') ), 'deleted' =&gt; 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">                                                                         &lt;?php
</span><span class="cx">                                                                         $actions        = array();
</span><span class="cx">                                                                         $actions[]        = '&lt;a href=&quot;ms-sites.php?action=editblog&amp;amp;id=' . $blog['blog_id'] . '&quot; class=&quot;edit&quot;&gt;' . __('Edit') . '&lt;/a&gt;';
</span><del>-                                                                        $actions[]        = &quot;&lt;a href='{$protocol}{$blog['domain']}{$blog['path']}wp-admin/' class='edit'&gt;&quot; . __('Backend') . '&lt;/a&gt;';
</del><ins>+                                                                        $actions[]        = &quot;&lt;a href='&quot; . get_admin_url($blog['blog_id']) . &quot;' class='edit'&gt;&quot; . __('Backend') . '&lt;/a&gt;';
</ins><span class="cx"> 
</span><span class="cx">                                                                         if ( get_blog_status( $blog['blog_id'], &quot;deleted&quot; ) == '1' )
</span><span class="cx">                                                                                 $actions[]        = '&lt;a class=&quot;delete&quot; href=&quot;ms-edit.php?action=confirm&amp;amp;action2=activateblog&amp;amp;ref=' . urlencode( $_SERVER['REQUEST_URI'] ) . '&amp;amp;id=' . $blog['blog_id'] . '&amp;amp;msg=' . urlencode( sprintf( __( &quot;You are about to activate the blog %s&quot; ), $blogname ) ) . '&quot;&gt;' . __('Activate') . '&lt;/a&gt;';
</span><span class="lines">@@ -509,7 +510,7 @@
</span><span class="cx"> 
</span><span class="cx">                                                                         $actions[]        = '&lt;a class=&quot;delete&quot; href=&quot;ms-edit.php?action=confirm&amp;amp;action2=deleteblog&amp;amp;id=' . $blog['blog_id'] . '&amp;amp;msg=' . urlencode( sprintf( __( &quot;You are about to delete the blog %s&quot; ), $blogname ) ) . '&quot;&gt;' . __(&quot;Delete&quot;) . '&lt;/a&gt;';
</span><span class="cx"> 
</span><del>-                                                                        $actions[]        = &quot;&lt;a href='http://{$blog['domain']}{$blog['path']}' rel='permalink'&gt;&quot; . __('Visit') . '&lt;/a&gt;';
</del><ins>+                                                                        $actions[]        = &quot;&lt;a href='&quot; . get_home_url($blog['blog_id']) . &quot;' rel='permalink'&gt;&quot; . __('Visit') . '&lt;/a&gt;';
</ins><span class="cx">                                                                         ?&gt;
</span><span class="cx"> 
</span><span class="cx">                                                                         &lt;?php if ( count($actions) ) : ?&gt;
</span><span class="lines">@@ -542,7 +543,7 @@
</span><span class="cx">                                                                                 $blogusers_warning = '';
</span><span class="cx">                                                                                 if ( count( $blogusers ) &gt; 5 ) {
</span><span class="cx">                                                                                         $blogusers = array_slice( $blogusers, 0, 5 );
</span><del>-                                                                                        $blogusers_warning = __( 'Only showing first 5 users.' ) . ' &lt;a href=&quot;' . $protocol . $blog[ 'domain' ] . $blog[ 'path' ] . 'wp-admin/users.php&quot;&gt;' . __( 'More' ) . '&lt;/a&gt;';
</del><ins>+                                                                                        $blogusers_warning = __( 'Only showing first 5 users.' ) . ' &lt;a href=&quot;' . get_admin_url($blog['blog_id'], 'users.php') . '&quot;&gt;' . __( 'More' ) . '&lt;/a&gt;';
</ins><span class="cx">                                                                                 }
</span><span class="cx">                                                                                 foreach ( $blogusers as $key =&gt; $val )
</span><span class="cx">                                                                                         echo '&lt;a href=&quot;user-edit.php?user_id=' . $val-&gt;user_id . '&quot;&gt;' . $val-&gt;user_login . '&lt;/a&gt; ('.$val-&gt;user_email.')&lt;br /&gt;';
</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() &amp;&amp; !is_admin() ? 'https' : 'http';
</span><del>-        $url = str_replace( 'http://', &quot;$scheme://&quot;, 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://', &quot;$scheme://&quot;, $home );
+
</ins><span class="cx">         if ( !empty( $path ) &amp;&amp; is_string( $path ) &amp;&amp; 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://', &quot;{$scheme}://&quot;, 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://', &quot;{$scheme}://&quot;, $url );
+
</ins><span class="cx">         if ( !empty($path) &amp;&amp; is_string($path) &amp;&amp; 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) &amp;&amp; is_string($path) &amp;&amp; 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>