From ba6228f2b7862ae8093de2a531b2ac7b1de1245a Mon Sep 17 00:00:00 2001 From: ryan Date: Fri, 5 Feb 2010 21:49:19 +0000 Subject: [PATCH] Introduce get_home_url(), get_site_url(), and get_admin_url() for fetching urls by blog id. see #12119 git-svn-id: http://svn.automattic.com/wordpress/trunk@12978 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/ms-edit.php | 9 ++-- wp-admin/ms-options.php | 2 +- wp-admin/ms-sites.php | 13 ++--- wp-includes/link-template.php | 91 ++++++++++++++++++++++++++++++----- 4 files changed, 92 insertions(+), 23 deletions(-) diff --git a/wp-admin/ms-edit.php b/wp-admin/ms-edit.php index 395bf71a31..9c6ecb71bb 100644 --- a/wp-admin/ms-edit.php +++ b/wp-admin/ms-edit.php @@ -207,11 +207,12 @@ switch ( $_GET['action'] ) { } if ( $_POST['update_home_url'] == 'update' ) { - if ( get_option( 'siteurl' ) != 'http://' . $_POST['blog']['domain'] . $_POST['blog']['path'] ) - update_option( 'siteurl', 'http://' . $_POST['blog']['domain'] . $_POST['blog']['path'] ); + $blog_address = get_blogaddress_by_domain($_POST['blog']['domain'], $_POST['blog']['path']); + if ( get_option( 'siteurl' ) != $blog_address ) + update_option( 'siteurl', $blog_address); - if ( get_option( 'home' ) != 'http://' . $_POST['blog']['domain'] . $_POST['blog']['path'] ) - update_option( 'home', 'http://' . $_POST['blog']['domain'] . $_POST['blog']['path'] ); + if ( get_option( 'home' ) != $blog_address ) + update_option( 'home', $blog_address ); } $wp_rewrite->flush_rules(); diff --git a/wp-admin/ms-options.php b/wp-admin/ms-options.php index df4c176054..80f525b742 100644 --- a/wp-admin/ms-options.php +++ b/wp-admin/ms-options.php @@ -38,7 +38,7 @@ if (isset($_GET['updated'])) { - +
domain ); ?> diff --git a/wp-admin/ms-sites.php b/wp-admin/ms-sites.php index dd0caba3d8..729756ed5e 100644 --- a/wp-admin/ms-sites.php +++ b/wp-admin/ms-sites.php @@ -82,7 +82,7 @@ switch ( $action ) { ?>
-

- http://domain . $details->path; ?>

+

-

@@ -93,12 +93,12 @@ switch ( $action ) { - + +
/> @@ -446,6 +446,7 @@ switch ( $action ) { array( 'site-archived', __('Archived') ), 'spam' => array( 'site-spammed', __('Spam') ), 'deleted' => array( 'site-deleted', __('Deleted') ) ); + $class = ''; foreach ( $blog_list as $blog ) { $class = ('alternate' == $class) ? '' : 'alternate'; reset( $status_list ); @@ -490,7 +491,7 @@ switch ( $action ) { ' . __('Edit') . ''; - $actions[] = "" . __('Backend') . ''; + $actions[] = "" . __('Backend') . ''; if ( get_blog_status( $blog['blog_id'], "deleted" ) == '1' ) $actions[] = '' . __('Activate') . ''; @@ -509,7 +510,7 @@ switch ( $action ) { $actions[] = '' . __("Delete") . ''; - $actions[] = "" . __('Visit') . ''; + $actions[] = "" . __('Visit') . ''; ?> @@ -542,7 +543,7 @@ switch ( $action ) { $blogusers_warning = ''; if ( count( $blogusers ) > 5 ) { $blogusers = array_slice( $blogusers, 0, 5 ); - $blogusers_warning = __( 'Only showing first 5 users.' ) . ' ' . __( 'More' ) . ''; + $blogusers_warning = __( 'Only showing first 5 users.' ) . ' ' . __( 'More' ) . ''; } foreach ( $blogusers as $key => $val ) echo '' . $val->user_login . ' ('.$val->user_email.')
'; diff --git a/wp-includes/link-template.php b/wp-includes/link-template.php index e9385fa00d..73f78caabf 100644 --- a/wp-includes/link-template.php +++ b/wp-includes/link-template.php @@ -1732,32 +1732,59 @@ function get_shortcut_link() { } /** - * Retrieve the home url. + * Retrieve the home url for the current 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 + * @since 3.0.0 + * + * @uses get_home_url() * * @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 home_url( $path = '', $scheme = null ) { + 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 ) { $orig_scheme = $scheme; $scheme = is_ssl() && !is_admin() ? 'https' : 'http'; - $url = str_replace( 'http://', "$scheme://", get_option('home') ); + + 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 ); if ( !empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false ) $url .= '/' . ltrim( $path, '/' ); - return apply_filters( 'home_url', $url, $path, $orig_scheme ); + return apply_filters( 'home_url', $url, $path, $orig_scheme, $blog_id ); } /** - * Retrieve the site url. + * Retrieve the site url for the current 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 @@ -1766,11 +1793,32 @@ function home_url( $path = '', $scheme = null ) { * @package WordPress * @since 2.6.0 * + * @uses get_site_url() + * * @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 site_url($path = '', $scheme = null) { +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 ) { // should the list of allowed schemes be maintained elsewhere? $orig_scheme = $scheme; if ( !in_array($scheme, array('http', 'https')) ) { @@ -1784,16 +1832,21 @@ function site_url($path = '', $scheme = null) { $scheme = ( is_ssl() ? 'https' : 'http' ); } - $url = str_replace( 'http://', "{$scheme}://", get_option('siteurl') ); + if ( empty($blog_id) || !is_multisite() ) + $url = get_option('siteurl'); + else + $url = untrailingslashit(get_blogaddress_by_id($blog_id)); + + $url = str_replace( 'http://', "{$scheme}://", $url ); if ( !empty($path) && is_string($path) && strpos($path, '..') === false ) $url .= '/' . ltrim($path, '/'); - return apply_filters('site_url', $url, $path, $orig_scheme); + return apply_filters('site_url', $url, $path, $orig_scheme, $blog_id); } /** - * Retrieve the url to the admin area. + * Retrieve the url to the admin area for the current site. * * @package WordPress * @since 2.6.0 @@ -1801,13 +1854,27 @@ function site_url($path = '', $scheme = null) { * @param string $path Optional path relative to the admin url * @return string Admin url link with optional path appended */ -function admin_url($path = '') { - $url = site_url('wp-admin/', 'admin'); +function admin_url( $path = '' ) { + return get_admin_url(null, $path); +} + +/** + * 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'); if ( !empty($path) && is_string($path) && strpos($path, '..') === false ) $url .= ltrim($path, '/'); - return apply_filters('admin_url', $url, $path); + return apply_filters('admin_url', $url, $path, $blog_id); } /**
http://http://
-
domain . $details->path) || get_blog_option( $id, 'home' ) == preg_replace('|/+$|', '', 'http://' . $details->domain . $details->path) ) echo 'checked="checked"'; ?> />