Check for existence of data from `get_blogaddress_by_id()` before returning a URL

* Prevent a notice when an invalid ID is used with `get_blogaddres_by_id()`.
* Return a falsy empty string rather than the previous "http://".
* Add unit tests for `get_blogaddress_by_id()`.

Props nerrad.

Fixes #30566.

Built from https://develop.svn.wordpress.org/trunk@31157


git-svn-id: http://core.svn.wordpress.org/trunk@31138 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Jeremy Felt 2015-01-12 02:24:22 +00:00
parent 40bcb404a3
commit 343a6587cf
2 changed files with 3 additions and 3 deletions

View File

@ -33,11 +33,11 @@ function wpmu_update_blogs_date() {
* @since MU
*
* @param int $blog_id Blog ID
* @return string
* @return string Full URL of the blog if found. Empty string if not.
*/
function get_blogaddress_by_id( $blog_id ) {
$bloginfo = get_blog_details( (int) $blog_id, false ); // only get bare details!
return esc_url( 'http://' . $bloginfo->domain . $bloginfo->path );
return isset( $bloginfo->domain ) && isset( $bloginfo->path ) ? esc_url( 'http://' . $bloginfo->domain . $bloginfo->path ) : '';
}
/**

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.2-alpha-31156';
$wp_version = '4.2-alpha-31157';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.