From 9dbf900004d47f9416b0a68292afd8ac4fd22544 Mon Sep 17 00:00:00 2001 From: Sukhendu Sekhar Guria Date: Mon, 7 Apr 2025 15:42:07 +0530 Subject: [PATCH 1/2] Deprecate get_blogaddress_by_id() and update references to use get_home_url() --- src/wp-includes/ms-blogs.php | 4 +++ src/wp-includes/ms-deprecated.php | 8 ++++- src/wp-includes/ms-functions.php | 2 +- tests/phpunit/tests/multisite/site.php | 47 ++++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/ms-blogs.php b/src/wp-includes/ms-blogs.php index 19fc6c1a7613e..a175b33403df2 100644 --- a/src/wp-includes/ms-blogs.php +++ b/src/wp-includes/ms-blogs.php @@ -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 ) ) { diff --git a/src/wp-includes/ms-deprecated.php b/src/wp-includes/ms-deprecated.php index fe7e8da494c4a..2b0071e8275ac 100644 --- a/src/wp-includes/ms-deprecated.php +++ b/src/wp-includes/ms-deprecated.php @@ -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' ); diff --git a/src/wp-includes/ms-functions.php b/src/wp-includes/ms-functions.php index f1cbc62fa8ec7..0d0c33fecfdc1 100644 --- a/src/wp-includes/ms-functions.php +++ b/src/wp-includes/ms-functions.php @@ -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 ); diff --git a/tests/phpunit/tests/multisite/site.php b/tests/phpunit/tests/multisite/site.php index 920a76f6a7e30..b00c9f0f1b24a 100644 --- a/tests/phpunit/tests/multisite/site.php +++ b/tests/phpunit/tests/multisite/site.php @@ -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 ); } @@ -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 ); } @@ -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 ) ); @@ -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() ); @@ -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 From 6d3374778350ee055a56f27c73f322dc3fac6683 Mon Sep 17 00:00:00 2001 From: Sukhendu Sekhar Guria Date: Fri, 29 May 2026 12:48:06 +0530 Subject: [PATCH 2/2] Fix PHPCS errors --- tests/phpunit/tests/multisite/site.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/tests/multisite/site.php b/tests/phpunit/tests/multisite/site.php index b00c9f0f1b24a..833e99350b1a1 100644 --- a/tests/phpunit/tests/multisite/site.php +++ b/tests/phpunit/tests/multisite/site.php @@ -753,7 +753,7 @@ public function test_wpmu_welcome_notification_uses_filtered_home_url() { return $url; }; - $welcome_email = null; + $welcome_email = null; $filter_welcome_email = static function ( $email ) use ( &$welcome_email ) { $welcome_email = $email;