removePermission (function)

Last updated: Fri, May 26, 2023 9:19 am
Return to Knowledgebase

Purpose

The removePermission function in UserSpice is a custom function used to remove permission assignments between users and permissions in the user_permission_matches table of the database.

Location

users/helpers/permissions.php

Parameters

# Parameter Data Type Required Description
1 $permissions integer, array Yes The ID(s) of the permission(s) to remove. Can be a single ID or an array of IDs.
2 $members integer, array Yes The ID(s) of the member(s) to remove the permission(s) from. Can be a single ID or an array of IDs.

Returns

Data Type Description of Returned Data
int The function returns the number of affected rows (permissions removed) as an integer.

Example

removePermission($permissions, $members)

Further Documentation:

This should only be done through the User Interface.


$permissionId = 123;
$memberId = 456;

// Remove a single permission from a single member
$affectedRows = removePermission($permissionId, $memberId);
echo "Removed $affectedRows permission(s) from member $memberId.";

// Remove multiple permissions from a single member
$permissionIds = [123, 456, 789];
$affectedRows = removePermission($permissionIds, $memberId);
echo "Removed $affectedRows permission(s) from member $memberId.";

// Remove a single permission from multiple members
$memberIds = [456, 789, 012];
$affectedRows = removePermission($permissionId, $memberIds);
echo "Removed $affectedRows permission(s) from members.";

// Remove multiple permissions from multiple members
$affectedRows = removePermission($permissionIds, $memberIds);
echo "Removed $affectedRows permission(s) from members.";



In the examples above, the removePermission function is called with different combinations of permission and member IDs. The function removes the permission assignments between the specified users and permissions in the user_permission_matches table. The returned affectedRows variable holds the count of removed permissions. It is then used to display the number of permissions that were successfully removed.

Note that the function supports both single and multiple permission/member IDs, allowing you to remove permissions for individual members or multiple members at once.