예제 #1
0
/**
 * Check if a domain has a mapping available
 *
 * @param stdClass|null $site Site object if already found, null otherwise
 * @param string $domain Domain we're looking for
 * @return stdClass|null Site object if already found, null otherwise
 */
function check_domain_mapping($site, $domain)
{
    // Have we already matched? (Allows other plugins to match first)
    if (!empty($site)) {
        return $site;
    }
    global $wpdb;
    // Grab both WWW and no-WWW
    if (strpos($domain, 'www.') === 0) {
        $www = $domain;
        $nowww = substr($domain, 4);
    } else {
        $nowww = $domain;
        $www = 'www.' . $domain;
    }
    $mapping = Mapping::get_by_domain(array($www, $nowww));
    if (empty($mapping) || is_wp_error($mapping)) {
        return $site;
    }
    // Ignore non-active domains
    if (!$mapping->is_active()) {
        return $site;
    }
    // Fetch the actual data for the site
    $mapped_site = $mapping->get_site();
    if (empty($mapped_site)) {
        return $site;
    }
    // Note: This is only for backwards compatibility with WPMU Domain Mapping,
    // do not rely on this constant in new code.
    defined('DOMAIN_MAPPING') or define('DOMAIN_MAPPING', 1);
    return $mapped_site;
}