permissionNameExists (function)

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

Purpose

Tells whether a permission name exits in UserSpice

Location

users/helpers/permissions.php

Parameters

# Parameter Data Type Required Description
1 $permission string Yes The permission name to check for existence.

Returns

Data Type Description of Returned Data
bool The function returns a boolean value: true if the permission name exists in the permissions table. false if the permission name doesn't exist.

Example

permissionNameExists('admin')

Further Documentation:

This is generally an internal UserSpice function and is not usually used by developers.

$permission = 'manage_users';

// Check if the permission name exists
if (permissionNameExists($permission)) {
echo "Permission name '$permission' already exists.";
// Perform appropriate action
} else {
echo "Permission name '$permission' does not exist.";
// Perform appropriate action
}



In the example above, the permissionNameExists function is called with the $permission variable as the argument. The function queries the permissions table to check if any permission records match the provided permission name. If a match is found, the function returns true, indicating that the permission name exists. If no match is found, it returns false, indicating that the permission name does not exist.

You can use conditional statements based on the return value of the function to perform the desired actions accordingly. In the example, if the return value is true, it prints a message indicating that the permission name already exists. Otherwise, it prints a message indicating that the permission name does not exist. You can customize the actions based on your specific requirements.