domain_exists

Check whether a blogname is already taken.

Description

(int) domain_exists( (string) $domain, (string) $path, (int) $site_id = 1 ); 

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

Returns (int)

Parameters (3)

0. $domain (string)
The domain to be checked.
1. $path (string)
The path to be checked.
2. $site_id — Optional. (int) => 1
Relevant only on multi-network installs.

Usage

  1. if ( !function_exists( 'domain_exists' ) ) { 
  2. require_once ABSPATH . WPINC . '/ms-functions.php'; 
  3.  
  4. // The domain to be checked. 
  5. $domain = ''; 
  6.  
  7. // The path to be checked. 
  8. $path = ''; 
  9.  
  10. // Optional. Relevant only on multi-network installs. 
  11. $site_id = 1; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = domain_exists($domain, $path, $site_id); 
  15.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/ms-functions.php  
  1. function domain_exists($domain, $path, $site_id = 1) { 
  2. $path = trailingslashit( $path ); 
  3. $args = array( 
  4. 'network_id' => $site_id,  
  5. 'domain' => $domain,  
  6. 'path' => $path,  
  7. 'fields' => 'ids',  
  8. ); 
  9. $result = get_sites( $args ); 
  10. $result = array_shift( $result ); 
  11.  
  12. /** 
  13. * Filters whether a blogname is taken. 
  14. * @since 3.5.0 
  15. * @param int|null $result The blog_id if the blogname exists, null otherwise. 
  16. * @param string $domain Domain to be checked. 
  17. * @param string $path Path to be checked. 
  18. * @param int $site_id Site ID. Relevant only on multi-network installs. 
  19. */ 
  20. return apply_filters( 'domain_exists', $result, $domain, $path, $site_id );