domain_exists( string $domain, string $path, int $network_id = 1 ): int|null

Checks whether a site name is already taken.

Description

The name is the site’s subdomain or the site’s subdirectory path depending on the network settings.

Used during the new site registration process to ensure that each site name is unique.

Parameters

$domainstringrequired
The domain to be checked.
$pathstringrequired
The path to be checked.
$network_idintoptional
Network ID. Only relevant on multi-network installations.

Default:1

Return

int|null The site ID if the site name exists, null otherwise.

Source

function domain_exists( $domain, $path, $network_id = 1 ) {
	$path   = trailingslashit( $path );
	$args   = array(
		'network_id'             => $network_id,
		'domain'                 => $domain,
		'path'                   => $path,
		'fields'                 => 'ids',
		'number'                 => 1,
		'update_site_meta_cache' => false,
	);
	$result = get_sites( $args );
	$result = array_shift( $result );

	/**
	 * Filters whether a site name is taken.
	 *
	 * The name is the site's subdomain or the site's subdirectory
	 * path depending on the network settings.
	 *
	 * @since 3.5.0
	 *
	 * @param int|null $result     The site ID if the site name exists, null otherwise.
	 * @param string   $domain     Domain to be checked.
	 * @param string   $path       Path to be checked.
	 * @param int      $network_id Network ID. Only relevant on multi-network installations.
	 */
	return apply_filters( 'domain_exists', $result, $domain, $path, $network_id );
}

Hooks

apply_filters( ‘domain_exists’, int|null $result, string $domain, string $path, int $network_id )

Filters whether a site name is taken.

Changelog

VersionDescription
MU (3.0.0)Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.