How can I check the current site id against the database and do something?
我正在检查当前站点id是否存在于
WordPress MU Domain Mapping 插件表。有列用于
blog_id 和
active. 理想情况下,如果
blog_id 存在且为
active 然后做点什么。
function is_domain_mapped() {
    global $wpdb;
    $domains = $wpdb->get_col( "SELECT active FROM $wpdb->dmtable} WHERE blog_id  = %d", $blog_id );
        // Do Something
    }
}
add_action( \'wp_head\', \'is_domain_mapped\', -1);
 
                    最合适的回答,由SO网友:birgire 整理而成
                    请注意,您应该能够映射没有第三方插件的域。
以下是一个未经测试的建议,建议您在当前情况下进行回访:
global $wpdb;
// Nothing to do if not multisite
if( ! is_multisite() )
    return;
// Define the custom table
$wpdb->dmtable = $wpdb->base_prefix . \'domain_mapping\';
// Check if the custom table exists
if ( $wpdb->dmtable != $wpdb->get_var( "SHOW TABLES LIKE \'{$wpdb->dmtable}\'" ) )
    return;
// Check if current site is mapped  
$domain_exists = (bool) $wpdb->get_var( 
    $wpdb->prepare( 
        "SELECT COUNT(blog_id) 
             FROM {$wpdb->dmtable} 
             WHERE blog_id = %d AND active = 1 LIMIT 0,1", 
        get_current_blog_id() 
    )
);
if( $domain_exists )
{
    // do something
}