public static function checkPermission(string $permissionName, bool $checkForNested = false): bool
    {
        if (self::isAdmin()) {
            return true;
        }

        $user           = \Craft::$app->getUser();
        $permissionName = strtolower($permissionName);

        if (self::permissionsEnabled()) {
            if ($checkForNested) {
                if (!$user->getId()) {
                    return false;
                }

                $permissionList = \Craft::$app->userPermissions->getPermissionsByUserId($user->getId());
                foreach ($permissionList as $permission) {
                    if (strpos($permission, $permissionName) === 0) {
                        return true;
                    }
                }
            }

            return $user->checkPermission($permissionName);
        }

        return false;
    }
public static function checkPermission(string $permissionName, bool $checkForNested = false): bool
    {
        if (self::isAdmin()) {
            return true;
        }

        $user           = \Craft::$app->getUser();
        $permissionName = strtolower($permissionName);

        if (self::permissionsEnabled()) {
            if ($checkForNested) {
                if (!$user->getId()) {
                    return false;
                }

                $permissionList = \Craft::$app->userPermissions->getPermissionsByUserId($user->getId());
                foreach ($permissionList as $permission) {
                    if (strpos($permission, $permissionName) === 0) {
                        return true;
                    }
                }
            }

            return $user->checkPermission($permissionName);
        }

        return false;
    }
public static function checkPermission ( string $ permissionName , bool $ checkForNested = false ) : bool { if ( self :: isAdmin ( ) ) { return true ; } $ user = \ Craft :: $ app -> getUser ( ) ; $ permissionName = strtolower ( $ permissionName ) ; if ( self :: permissionsEnabled ( ) ) { if ( $ checkForNested ) { if ( ! $ user -> getId ( ) ) { return false ; } $ permissionList = \ Craft :: $ app -> userPermissions -> getPermissionsByUserId ( $ user -> getId ( ) ) ; foreach ( $ permissionList as $ permission ) { if ( strpos ( $ permission , $ permissionName ) === 0 ) { return true ; } } } return $ user -> checkPermission ( $ permissionName ) ; } return false ; }
Checks a given permission for the currently logged in user

@param string $permissionName
@param bool   $checkForNested - see nested permissions for matching permission name root

@return bool
Checks a given permission for the currently logged in user