Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/wp-includes/ms-blogs.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,15 @@ function wpmu_update_blogs_date() {
* Gets a full site URL, given a site ID.
*
* @since MU (3.0.0)
* @deprecated 6.9.0 Use get_home_url() instead when possible.
* @see get_home_url()
*
* @param int $blog_id Site ID.
* @return string Full site URL if found. Empty string if not.
*/
function get_blogaddress_by_id( $blog_id ) {
_deprecated_function( __FUNCTION__, '6.9.0', 'get_home_url()' );

$bloginfo = get_site( (int) $blog_id );

if ( empty( $bloginfo ) ) {
Expand Down
8 changes: 7 additions & 1 deletion src/wp-includes/ms-deprecated.php
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,13 @@ function install_blog( $blog_id, $blog_title = '' ) {
}
$wpdb->suppress_errors( $suppress );

$url = get_blogaddress_by_id( $blog_id );
// Get the site URL directly from get_site() instead of using get_blogaddress_by_id().
$site_info = get_site( $blog_id );
if ( ! empty( $site_info ) ) {
$url = 'http://' . $site_info->domain . $site_info->path;
} else {
$url = '';
}

// Set everything up.
make_db_current_silent( 'blog' );
Expand Down
2 changes: 1 addition & 1 deletion src/wp-includes/ms-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1688,7 +1688,7 @@ function wpmu_welcome_notification(
);
}

$url = get_blogaddress_by_id( $blog_id );
$url = get_home_url( $blog_id, '/' );

$welcome_email = str_replace( 'SITE_NAME', $current_network->site_name, $welcome_email );
$welcome_email = str_replace( 'BLOG_TITLE', $title, $welcome_email );
Expand Down
47 changes: 47 additions & 0 deletions tests/phpunit/tests/multisite/site.php
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,8 @@ public function test_slashed_path_in_domain_exists() {
* Tests returning an address for a given valid ID.
*/
public function test_get_blogaddress_by_id_with_valid_id() {
$this->setExpectedDeprecated( 'get_blogaddress_by_id' );

$blogaddress = get_blogaddress_by_id( 1 );
$this->assertSame( 'http://' . WP_TESTS_DOMAIN . '/', $blogaddress );
}
Expand All @@ -691,6 +693,8 @@ public function test_get_blogaddress_by_id_with_valid_id() {
* Tests returning an empty string for a non-existing ID.
*/
public function test_get_blogaddress_by_id_with_invalid_id() {
$this->setExpectedDeprecated( 'get_blogaddress_by_id' );

$blogaddress = get_blogaddress_by_id( PHP_INT_MAX );
$this->assertSame( '', $blogaddress );
}
Expand All @@ -699,6 +703,8 @@ public function test_get_blogaddress_by_id_with_invalid_id() {
* @ticket 14867
*/
public function test_get_blogaddress_by_id_scheme_reflects_blog_scheme() {
$this->setExpectedDeprecated( 'get_blogaddress_by_id' );

$blog = self::factory()->blog->create();

$this->assertSame( 'http', parse_url( get_blogaddress_by_id( $blog ), PHP_URL_SCHEME ) );
Expand All @@ -712,6 +718,8 @@ public function test_get_blogaddress_by_id_scheme_reflects_blog_scheme() {
* @ticket 14867
*/
public function test_get_blogaddress_by_id_scheme_is_unaffected_by_request() {
$this->setExpectedDeprecated( 'get_blogaddress_by_id' );

$blog = self::factory()->blog->create();

$this->assertFalse( is_ssl() );
Expand All @@ -726,6 +734,45 @@ public function test_get_blogaddress_by_id_scheme_is_unaffected_by_request() {
$this->assertSame( 'http', $address );
}

/**
* @ticket 37297
*/
public function test_wpmu_welcome_notification_uses_filtered_home_url() {
$blog_id = self::factory()->blog->create();
$user_id = self::factory()->user->create(
array(
'user_email' => 'welcome@example.org',
)
);

$filter_home_url = static function ( $url, $path, $scheme, $current_blog_id ) use ( $blog_id ) {
if ( $blog_id === $current_blog_id ) {
return 'https://filtered.example.org/';
}

return $url;
};

$welcome_email = null;
$filter_welcome_email = static function ( $email ) use ( &$welcome_email ) {
$welcome_email = $email;

return $email;
};

add_filter( 'home_url', $filter_home_url, 10, 4 );
add_filter( 'update_welcome_email', $filter_welcome_email );
add_filter( 'pre_wp_mail', '__return_true' );

wpmu_welcome_notification( $blog_id, $user_id, 'password', 'Site Title' );

remove_filter( 'home_url', $filter_home_url, 10 );
remove_filter( 'update_welcome_email', $filter_welcome_email );
remove_filter( 'pre_wp_mail', '__return_true' );

$this->assertStringContainsString( 'https://filtered.example.org/', $welcome_email );
}

/**
* @ticket 33620
* @dataProvider data_new_blog_url_schemes
Expand Down
Loading