返回介绍

is_super_admin()

发布于 2017-09-11 01:28:10 字数 2979 浏览 2389 评论 0 收藏 0

is_super_admin( int $user_id = false )

Determine if user is a site admin.


description


参数

$user_id

(int) (Optional) (Optional) The ID of a user. Defaults to the current user.

Default value: false


返回值

(bool) True if the user is a site admin.


源代码

File: wp-includes/capabilities.php

function is_super_admin( $user_id = false ) {
	if ( ! $user_id || $user_id == get_current_user_id() )
		$user = wp_get_current_user();
	else
		$user = get_userdata( $user_id );

	if ( ! $user || ! $user->exists() )
		return false;

	if ( is_multisite() ) {
		$super_admins = get_super_admins();
		if ( is_array( $super_admins ) && in_array( $user->user_login, $super_admins ) )
			return true;
	} else {
		if ( $user->has_cap('delete_users') )
			return true;
	}

	return false;
}

更新日志

Versiondescription
3.0.0Introduced.

相关函数

Uses

  • wp-includes/capabilities.php: get_super_admins()
  • wp-includes/pluggable.php: wp_get_current_user()
  • wp-includes/pluggable.php: get_userdata()
  • wp-includes/load.php: is_multisite()
  • wp-includes/user.php: get_current_user_id()

Used By

  • wp-admin/includes/class-wp-ms-users-list-table.php: WP_MS_Users_List_Table::column_cb()
  • wp-admin/includes/upgrade.php: wp_install_defaults()
  • wp-includes/class-wp-user.php: WP_User::has_cap()
  • wp-includes/capabilities.php: map_meta_cap()
  • wp-includes/ms-functions.php: wpmu_create_blog()
  • wp-includes/ms-deprecated.php: is_site_admin()
  • wp-includes/ms-load.php: ms_site_check()
  • Show 2 more used by Hide more used by

User Contributed Notes

  1. Skip to note content You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note Contributed by Codex

    Example

    
    <?php
    // Removes the "Edit" menu for users who are not Super Admins of a multisite network
    if ( ! is_super_admin() ) {
    	add_action( 'admin_init', 'wpdocs_remove_edit_menu' );
    }
    
    /**
     * Remove the profile editing link for non-super admins.
     */
    function wpdocs_remove_edit_menu() {
    	remove_menu_page('edit.php');
    }
    ?>
    
    

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文