diff --git a/src/wp-includes/ms-blogs.php b/src/wp-includes/ms-blogs.php index 72ebbaa3a8..d291f169db 100644 --- a/src/wp-includes/ms-blogs.php +++ b/src/wp-includes/ms-blogs.php @@ -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 ) : ''; } /** diff --git a/tests/phpunit/tests/multisite/site.php b/tests/phpunit/tests/multisite/site.php index 73cbd2872b..603546c3c7 100644 --- a/tests/phpunit/tests/multisite/site.php +++ b/tests/phpunit/tests/multisite/site.php @@ -332,7 +332,7 @@ class Tests_Multisite_Site extends WP_UnitTestCase { $result = update_blog_details( 999, array( 'domain' => 'example.com' ) ); $this->assertFalse( $result ); } - + function test_update_blog_details() { $blog_id = $this->factory->blog->create(); @@ -1461,6 +1461,22 @@ class Tests_Multisite_Site extends WP_UnitTestCase { remove_filter( 'domain_exists', array( $this, '_domain_exists_cb' ), 10, 4 ); } + + /** + * Tests returning an address for a given valid id. + */ + function test_get_blogaddress_by_id_with_valid_id() { + $blogaddress = get_blogaddress_by_id( 1 ); + $this->assertEquals( 'http://example.org/', $blogaddress ); + } + + /** + * Tests returning the appropriate response for a invalid id given. + */ + function test_get_blogaddress_by_id_with_invalid_id() { + $blogaddress = get_blogaddress_by_id( 42 ); + $this->assertEquals( '', $blogaddress ); + } } endif; \ No newline at end of file