domain_exists

The timeline below displays how wordpress function domain_exists has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.2

/**
 * Checks whether a site name is already taken.
 *
 * 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.
 *
 * @since MU (3.0.0)
 *
 * @param string $domain     The domain to be checked.
 * @param string $path       The path to be checked.
 * @param int    $network_id Optional. Network ID. Only relevant on multi-network installations.
 *                           Default 1.
 * @return int|null The site ID if the site name exists, null otherwise.
 */
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);
}

WordPress Version: .10

/**
 * Checks whether a site name is already taken.
 *
 * 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.
 *
 * @since MU (3.0.0)
 *
 * @param string $domain     The domain to be checked.
 * @param string $path       The path to be checked.
 * @param int    $network_id Optional. Network ID. Relevant only on multi-network installations.
 * @return int|null The site ID if the site name exists, null otherwise.
 */
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);
}

WordPress Version: 4.9

/**
 * Checks whether a site name is already taken.
 *
 * 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.
 *
 * @since MU (3.0.0)
 *
 * @param string $domain     The domain to be checked.
 * @param string $path       The path to be checked.
 * @param int    $network_id Optional. Network ID. Relevant only on multi-network installations.
 * @return int|null The site ID if the site name exists, null otherwise.
 */
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);
    $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);
}

WordPress Version: 4.6

/**
 * Check whether a blogname is already taken.
 *
 * Used during the new site registration process to ensure
 * that each blogname is unique.
 *
 * @since MU
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string $domain  The domain to be checked.
 * @param string $path    The path to be checked.
 * @param int    $site_id Optional. Relevant only on multi-network installs.
 * @return int
 */
function domain_exists($domain, $path, $site_id = 1)
{
    $path = trailingslashit($path);
    $args = array('network_id' => $site_id, 'domain' => $domain, 'path' => $path, 'fields' => 'ids');
    $result = get_sites($args);
    $result = array_shift($result);
    /**
     * Filters whether a blogname is taken.
     *
     * @since 3.5.0
     *
     * @param int|null $result  The blog_id if the blogname exists, null otherwise.
     * @param string   $domain  Domain to be checked.
     * @param string   $path    Path to be checked.
     * @param int      $site_id Site ID. Relevant only on multi-network installs.
     */
    return apply_filters('domain_exists', $result, $domain, $path, $site_id);
}

WordPress Version: 4.4

/**
 * Check whether a blogname is already taken.
 *
 * Used during the new site registration process to ensure
 * that each blogname is unique.
 *
 * @since MU
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string $domain  The domain to be checked.
 * @param string $path    The path to be checked.
 * @param int    $site_id Optional. Relevant only on multi-network installs.
 * @return int
 */
function domain_exists($domain, $path, $site_id = 1)
{
    global $wpdb;
    $path = trailingslashit($path);
    $result = $wpdb->get_var($wpdb->prepare("SELECT blog_id FROM {$wpdb->blogs} WHERE domain = %s AND path = %s AND site_id = %d", $domain, $path, $site_id));
    /**
     * Filter whether a blogname is taken.
     *
     * @since 3.5.0
     *
     * @param int|null $result  The blog_id if the blogname exists, null otherwise.
     * @param string   $domain  Domain to be checked.
     * @param string   $path    Path to be checked.
     * @param int      $site_id Site ID. Relevant only on multi-network installs.
     */
    return apply_filters('domain_exists', $result, $domain, $path, $site_id);
}

WordPress Version: 4.3

/**
 * Check whether a blogname is already taken.
 *
 * Used during the new site registration process to ensure
 * that each blogname is unique.
 *
 * @since MU
 *
 * @global wpdb $wpdb
 *
 * @param string $domain  The domain to be checked.
 * @param string $path    The path to be checked.
 * @param int    $site_id Optional. Relevant only on multi-network installs.
 * @return int
 */
function domain_exists($domain, $path, $site_id = 1)
{
    global $wpdb;
    $path = trailingslashit($path);
    $result = $wpdb->get_var($wpdb->prepare("SELECT blog_id FROM {$wpdb->blogs} WHERE domain = %s AND path = %s AND site_id = %d", $domain, $path, $site_id));
    /**
     * Filter whether a blogname is taken.
     *
     * @since 3.5.0
     *
     * @param int|null $result  The blog_id if the blogname exists, null otherwise.
     * @param string   $domain  Domain to be checked.
     * @param string   $path    Path to be checked.
     * @param int      $site_id Site ID. Relevant only on multi-network installs.
     */
    return apply_filters('domain_exists', $result, $domain, $path, $site_id);
}

WordPress Version: 3.9

/**
 * Check whether a blogname is already taken.
 *
 * Used during the new site registration process to ensure
 * that each blogname is unique.
 *
 * @since MU
 *
 * @param string $domain The domain to be checked.
 * @param string $path The path to be checked.
 * @param int $site_id Optional. Relevant only on multi-network installs.
 * @return int
 */
function domain_exists($domain, $path, $site_id = 1)
{
    global $wpdb;
    $path = trailingslashit($path);
    $result = $wpdb->get_var($wpdb->prepare("SELECT blog_id FROM {$wpdb->blogs} WHERE domain = %s AND path = %s AND site_id = %d", $domain, $path, $site_id));
    /**
     * Filter whether a blogname is taken.
     *
     * @since 3.5.0
     *
     * @param int|null $result  The blog_id if the blogname exists, null otherwise.
     * @param string   $domain  Domain to be checked.
     * @param string   $path    Path to be checked.
     * @param int      $site_id Site ID. Relevant only on multi-network installs.
     */
    return apply_filters('domain_exists', $result, $domain, $path, $site_id);
}

WordPress Version: 3.8

/**
 * Check whether a blogname is already taken.
 *
 * Used during the new site registration process to ensure
 * that each blogname is unique.
 *
 * @since MU
 *
 * @param string $domain The domain to be checked.
 * @param string $path The path to be checked.
 * @param int $site_id Optional. Relevant only on multi-network installs.
 * @return int
 */
function domain_exists($domain, $path, $site_id = 1)
{
    global $wpdb;
    $result = $wpdb->get_var($wpdb->prepare("SELECT blog_id FROM {$wpdb->blogs} WHERE domain = %s AND path = %s AND site_id = %d", $domain, $path, $site_id));
    /**
     * Filter whether a blogname is taken.
     *
     * @since 3.5.0
     *
     * @param int|null $result  The blog_id if the blogname exists, null otherwise.
     * @param string   $domain  Domain to be checked.
     * @param string   $path    Path to be checked.
     * @param int      $site_id Site ID. Relevant only on multi-network installs.
     */
    return apply_filters('domain_exists', $result, $domain, $path, $site_id);
}

WordPress Version: 3.7

/**
 * Check whether a blogname is already taken.
 *
 * Used during the new site registration process to ensure
 * that each blogname is unique.
 *
 * @since MU
 *
 * @param string $domain The domain to be checked.
 * @param string $path The path to be checked.
 * @param int $site_id Optional. Relevant only on multi-network installs.
 * @return int
 */
function domain_exists($domain, $path, $site_id = 1)
{
    global $wpdb;
    $result = $wpdb->get_var($wpdb->prepare("SELECT blog_id FROM {$wpdb->blogs} WHERE domain = %s AND path = %s AND site_id = %d", $domain, $path, $site_id));
    return apply_filters('domain_exists', $result, $domain, $path, $site_id);
}