Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
8 changes: 8 additions & 0 deletions includes/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down Expand Up @@ -303,6 +307,10 @@ function get_host() {
function get_site( $site_id ) {
$site = \get_site( $site_id );

if ( ! $site instanceof \WP_Site ) {
return [];
}
Comment on lines 307 to +312

return [
'blog_id' => $site->blog_id,
'domain' => $site->domain,
Expand Down
23 changes: 23 additions & 0 deletions tests/php/TestUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Comment on lines +110 to +113

/**
* 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.
*
Expand Down