1

How do one use the domain_exists() function with an example.

I have checked the codex, but it didn't help

5

domain_exists() is something you probably won´t call by yourself.

It is used in the registration/creation process of new sites in a Multisite installation. There it´s used to check if a specific blog URL is already in use:

if ( domain_exists($mydomain, $path, $current_site->id) )
    $errors->add( 'blogname', __( 'Sorry, that site already exists!' ) );

(From /wp-includes/ms-functions.php, line 612-613)

The "normal" Codex also has a page about it: mu_exists()

You can see that it was introduced with the Multisite functionality in WP 3.5, it´s defined in lines 1256-1259 of /wp-includes/ms-functions.php

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) );
}

All in all you most probably don´t want to call it yourself. If you want to check for an existent site or something like that, there are more comfortable functions like wp_get_blogs().

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.