函数文档

is_network_admin()

💡 云策文档标注

概述

is_network_admin() 函数用于判断当前请求是否针对 WordPress 多站点网络的网络管理界面,例如 /wp-admin/network/。它不检查用户权限或是否启用多站点,仅关注请求的上下文。

关键要点

  • 函数返回布尔值:true 表示当前位于网络管理页面,false 表示不是。
  • 不验证用户是否为管理员,需使用 current_user_can() 检查角色和能力。
  • 不检查是否启用多站点,需使用 is_multisite() 进行验证。
  • 内部实现基于 $GLOBALS['current_screen'] 或 WP_NETWORK_ADMIN 常量。

代码示例

// 检查当前屏幕是否为网络管理屏幕
if ( is_network_admin() ) {
    echo __( 'You are viewing a WordPress network administration page', 'textdomain' );
} else {
    echo __( 'You are not viewing a WordPress network administration page', 'textdomain' );
}

📄 原文内容

Determines whether the current request is for the network administrative interface.

Description

e.g. /wp-admin/network/

Does not check if the user is an administrator; use current_user_can() for checking roles and capabilities.

Does not check if the site is a Multisite network; use is_multisite() for checking if Multisite is enabled.

Return

bool True if inside WordPress network administration pages.

Source

function is_network_admin() {
	if ( isset( $GLOBALS['current_screen'] ) ) {
		return $GLOBALS['current_screen']->in_admin( 'network' );
	} elseif ( defined( 'WP_NETWORK_ADMIN' ) ) {
		return WP_NETWORK_ADMIN;
	}

	return false;
}

Changelog

Version Description
3.1.0 Introduced.

User Contributed Notes