Пример #1
0
function ure_is_admin( $user_id = false ) {
  global $current_user;

	if ( ! $user_id ) {
    if (empty($current_user) && function_exists('get_currentuserinfo')) {
      get_currentuserinfo();
    }
		$user_id = ! empty($current_user) ? $current_user->ID : 0;
	}

	if ( ! $user_id )
		return false;

	$user = new WP_User($user_id);

  $simpleAdmin = ure_has_administrator_role($user_id);

	if ( is_multisite() ) {
		$super_admins = get_super_admins();
		$superAdmin =  is_array( $super_admins ) && in_array( $user->user_login, $super_admins );
	} else {
    $superAdmin = false;
  }

	return $simpleAdmin || $superAdmin;
}
function ure_not_edit_admin($allcaps, $caps, $name)
{
    global $ure_userToCheck;
    $userKeys = array('user_id', 'user');
    foreach ($userKeys as $userKey) {
        $accessDeny = false;
        if (isset($_GET[$userKey])) {
            $ure_UserId = $_GET[$userKey];
            if ($ure_UserId == 1) {
                // built-in WordPress Admin
                $accessDeny = true;
            } else {
                if (!isset($ure_userToCheck[$ure_UserId])) {
                    // check if user_id has Administrator role
                    $accessDeny = ure_has_administrator_role($ure_UserId);
                } else {
                    // user_id was checked already, get result from cash
                    $accessDeny = $ure_userToCheck[$ure_UserId];
                }
            }
            if ($accessDeny) {
                unset($allcaps['edit_users']);
            }
            break;
        }
    }
    return $allcaps;
}