domain_exists() WordPress Function

The domain_exists() function checks whether a domain is available for registration. It returns true if the domain is available, or false if it is not.

domain_exists( string $domain, string $path, int $network_id = 1 ) #

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.


Top ↑

Parameters

$domain

(string)(Required)The domain to be checked.

$path

(string)(Required)The path to be checked.

$network_id

(int)(Optional) Network ID. Relevant only on multi-network installations.

Default value: 1


Top ↑

Return

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


Top ↑

Source

File: wp-includes/ms-functions.php

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. Relevant only on multi-network installations.
	 */
	return apply_filters( 'domain_exists', $result, $domain, $path, $network_id );
}


Top ↑

Changelog

Changelog
VersionDescription
MU (3.0.0)Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More