WordPress函数:is_main_site 是否是主站点

江河/ 2023年09月19日/ WordPress/ 浏览 759

函数原型:


is_main_site( int $site_id = null, int $network_id = null ): bool


确定站点是否为当前网络的主站点。


参数说明:


$site_id,要测试的站点ID。默认为当前站点。


$network_id,要检查的网络的网络ID。默认为当前网络。


函数源码:


function is_main_site( $site_id = null, $network_id = null ) {
	if ( ! is_multisite() ) {
		return true;
	}

	if ( ! $site_id ) {
		$site_id = get_current_blog_id();
	}

	$site_id = (int) $site_id;

	return get_main_site_id( $network_id ) === $site_id;
}


使用举例:


if ( is_main_site( $blog_id ) ) {
  // display something special for the main site.
}


发表评论

暂无评论,抢个沙发...

客服 工单