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

Checks whether a site name is already taken.


Description 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 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 Return

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


Top ↑

Source Source

File: wp-includes/ms-functions.php

1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
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 );
}

Top ↑

Changelog Changelog

Changelog
Version Description
MU (3.0.0) Introduced.


Top ↑

User Contributed Notes User Contributed Notes

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