diff --git a/includes/utils.php b/includes/utils.php index 70ba7dbcc..764a4b1a4 100644 --- a/includes/utils.php +++ b/includes/utils.php @@ -204,6 +204,10 @@ function is_site_indexable( $blog_id = null ) { $site = get_site( $blog_id ); + if ( empty( $site ) ) { + return false; + } + $is_indexable = get_site_meta( $site['blog_id'], 'ep_indexable', true ); return 'no' !== $is_indexable && ! $site['deleted'] && ! $site['archived'] && ! $site['spam']; @@ -303,6 +307,10 @@ function get_host() { function get_site( $site_id ) { $site = \get_site( $site_id ); + if ( ! $site instanceof \WP_Site ) { + return []; + } + return [ 'blog_id' => $site->blog_id, 'domain' => $site->domain, diff --git a/tests/php/TestUtils.php b/tests/php/TestUtils.php index f2f0c8777..8df958db3 100644 --- a/tests/php/TestUtils.php +++ b/tests/php/TestUtils.php @@ -100,6 +100,29 @@ public function testIsSiteIndexableDisabled() { $this->assertFalse( ElasticPress\Utils\is_site_indexable() ); } + /** + * Check that get_site returns an empty array for a non-existent site ID. + * + * @since 5.3.4 + * @group utils + * @group skip-on-single-site + */ + public function testGetSiteReturnsEmptyArrayForNonexistentSite() { + $result = ElasticPress\Utils\get_site( 999999 ); + $this->assertSame( [], $result ); + } + + /** + * Check that is_site_indexable returns false for a non-existent site ID. + * + * @since 5.3.4 + * @group utils + * @group skip-on-single-site + */ + public function testIsSiteIndexableReturnsFalseForNonexistentSite() { + $this->assertFalse( ElasticPress\Utils\is_site_indexable( 999999 ) ); + } + /** * Tests the sanitize_credentials utils function. *