From 88c822fbe4a4681edeee60611d63f840ae15d071 Mon Sep 17 00:00:00 2001 From: Christopher Ross <122108986+thisismyurl@users.noreply.github.com> Date: Thu, 11 Jun 2026 11:08:23 -0400 Subject: [PATCH 1/3] Fix: guard Utils\\get_site() and is_site_indexable() against non-existent site IDs On PHP 8.x, calling \get_site() with an ID that does not exist returns null rather than a WP_Site object. The wrapper Utils\\get_site() was passing that null directly to array property access, causing a fatal TypeError. is_site_indexable() then received false-y data and could also propagate a null return where an array is expected. Fix: add an instanceof WP_Site guard in get_site() that returns [] when the core function returns null, and an empty() guard in is_site_indexable() that short-circuits to false for non-existent site IDs. Both changes are consistent with the existing @return array contract and the behavior the callers already expect for non-indexable sites. --- includes/utils.php | 8 ++++++++ 1 file changed, 8 insertions(+) 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, From c1a269a09729a4dee03a8bff03803e20f5207b49 Mon Sep 17 00:00:00 2001 From: Christopher Ross <122108986+thisismyurl@users.noreply.github.com> Date: Thu, 11 Jun 2026 11:08:26 -0400 Subject: [PATCH 2/3] Test: cover Utils\\get_site() and is_site_indexable() for non-existent site IDs Two tests covering the null-guard introduced in the prior commit: - testGetSiteReturnsEmptyArrayForNonexistentSite - testIsSiteIndexableReturnsFalseForNonexistentSite Both are tagged @group skip-on-single-site since the functions are multisite-only paths. --- tests/php/TestUtils.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/php/TestUtils.php b/tests/php/TestUtils.php index f2f0c8777..bd607230c 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( PHP_INT_MAX ); + $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( PHP_INT_MAX ) ); + } + /** * Tests the sanitize_credentials utils function. * From 4d8544c897257b5b7ea8a9eb5ecf662637862433 Mon Sep 17 00:00:00 2001 From: Christopher Ross <122108986+thisismyurl@users.noreply.github.com> Date: Fri, 12 Jun 2026 08:11:59 -0400 Subject: [PATCH 3/3] fix: use deterministic site ID 999999 instead of PHP_INT_MAX in tests --- tests/php/TestUtils.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/php/TestUtils.php b/tests/php/TestUtils.php index bd607230c..8df958db3 100644 --- a/tests/php/TestUtils.php +++ b/tests/php/TestUtils.php @@ -108,7 +108,7 @@ public function testIsSiteIndexableDisabled() { * @group skip-on-single-site */ public function testGetSiteReturnsEmptyArrayForNonexistentSite() { - $result = ElasticPress\Utils\get_site( PHP_INT_MAX ); + $result = ElasticPress\Utils\get_site( 999999 ); $this->assertSame( [], $result ); } @@ -120,7 +120,7 @@ public function testGetSiteReturnsEmptyArrayForNonexistentSite() { * @group skip-on-single-site */ public function testIsSiteIndexableReturnsFalseForNonexistentSite() { - $this->assertFalse( ElasticPress\Utils\is_site_indexable( PHP_INT_MAX ) ); + $this->assertFalse( ElasticPress\Utils\is_site_indexable( 999999 ) ); } /**