is_main_site()判断当前站点是否为主站点(多站点)

目录

描述

Test if site is main site, given site id

is_main_site() 描述

用法

<?php is_main_site$blog_id ?>

is_main_site() 用法

参数

$blog_id

(integer) (可选) optional site id to test (default to current site) .

默认值: defaults to empty (site in V3 is blog in v2)

is_main_site() 参数

返回值

(boolean) 

True if not multisite or site is main site (site in V3 is blog in v2) .

is_main_site() 返回值

示例

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */

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

is_main_site() 示例

注意

Replaces function is_main_blog(), deprecated since 3.0.0. (wp-includes/ms-deprecated.php)

is_main_site() 注意

历史

添加于 版本 3.0.0.

is_main_site() 历史

源文件

is_main_site() 函数的代码位于 wp-includes/functions.php.

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Determine whether a site is the main site of the current network.
 *
 * @since 3.0.0
 *
 * @global object $current_site
 *
 * @param int $site_id Optional. Site ID to test. Defaults to current site.
 *                     Defaults to current site.
 * @return bool True if $site_id is the main site of the network, or if not
 *              running Multisite.
 */
function is_main_site( $site_id = null ) {
	// This is the current network's information; 'site' is old terminology.
	global $current_site;

	if ( ! is_multisite() )
		return true;

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

	return (int) $site_id === (int) $current_site->blog_id;
}

is_main_site() 源文件