revoke_super_admin

函数
revoke_super_admin ( $user_id )
参数
  • (int) $user_id ID of the user Super Admin privileges to be revoked from.
    Required:
返回值
  • (bool) True on success, false on failure. This can fail when the user's email is the network admin email or when the `$super_admins` global is defined.
定义位置
相关方法
get_super_adminsis_super_admingrant_super_adminis_user_adminwp_revoke_user
引入
3.0.0
弃用
-

revoke_super_admin: 这是一个WordPress的函数,用来撤销一个多站点网络中的用户的超级管理员权限。超级管理员可以访问网络上的所有站点,并可以执行管理任务。revoke_super_admin可以删除用户的超级管理员权限。

撤销超级管理员的权限。

function revoke_super_admin( $user_id ) {
	// If global super_admins override is defined, there is nothing to do here.
	if ( isset( $GLOBALS['super_admins'] ) || ! is_multisite() ) {
		return false;
	}

	/**
	 * Fires before the user's Super Admin privileges are revoked.
	 *
	 * @since 3.0.0
	 *
	 * @param int $user_id ID of the user Super Admin privileges are being revoked from.
	 */
	do_action( 'revoke_super_admin', $user_id );

	// Directly fetch site_admins instead of using get_super_admins().
	$super_admins = get_site_option( 'site_admins', array( 'admin' ) );

	$user = get_userdata( $user_id );
	if ( $user && 0 !== strcasecmp( $user->user_email, get_site_option( 'admin_email' ) ) ) {
		$key = array_search( $user->user_login, $super_admins, true );
		if ( false !== $key ) {
			unset( $super_admins[ $key ] );
			update_site_option( 'site_admins', $super_admins );

			/**
			 * Fires after the user's Super Admin privileges are revoked.
			 *
			 * @since 3.0.0
			 *
			 * @param int $user_id ID of the user Super Admin privileges were revoked from.
			 */
			do_action( 'revoked_super_admin', $user_id );
			return true;
		}
	}
	return false;
}

常见问题

FAQs
查看更多 >