Skip to content
This repository has been archived by the owner on Nov 25, 2022. It is now read-only.

Access Control Level

Kader Bouyakoub edited this page May 30, 2018 · 3 revisions

This module adds a whole new Access Control Level to your CodeIgniter Skeleton application.

Installation

The link to this module will be provided soon. Once the package downloaded:

  1. Head to modules installation on the dashboard and upload the archive.
  2. Unzip package files into your application/modules OR content/modules folders.

Functions

There are several functions you may use but, please NEVER use available classes (Ianhub_Acl_Role and Ianhub_Acl_Roles).
Some functions save settings into options table, so it might be better to run this on themes/plugins activation.

acl_instance

This function may be used to instantiate the Ianhub_Acl_Roles class then have direct access to its methods.

$acl = acl_instance();
$acl->add_role($slug, $name, $capabilities);

acl_add_role

This function is used to add new roles to your application. It takes three (3) arguments:

  • $slug (string) : a unique slug (username) used to stored your new role.
  • $name(string) : the name your new role will have.
  • $capabilities (array) : An array of capibitilies and their status (TRUEor FALSE)
acl_add_role('admin', 'administrator', array(
	'manage_themes' => true,
	'manage_modules' => true,
	'manage_plugins' => true,
	'manage_users' => true,
	'add_users' => true,
	// ...
));
// Returns a `Ianhub_Acl_Role` object on success,
// null if that role already exists.

acl_remove_role

This function is used to remove a previously stored role.

// We remove "admin" we added obove.
acl_remove_role('admin'); // That's all.
// Returns true if the role was removed, else false.

acl_get_role

Retrieves a role object if found.

// acl_get_role($role_slug);
$admin = acl_get_role('admin');
// The result wil be an object:
array(
	'name' => 'Administrator',
	'capabilities'=> array(
		'manage_themes' => true,
		// ...
	),
);

acl_is_role

Checks whether the given role slug is available.

// acl_is_role($slug);
acl_is_role('manager');
// Returns: true if the role is found, else false.

acl_get_roles

Returns the list of previously all registered roles objects.

acl_get_default_role

Returns default users role (string).

$role = acl_get_default_role();
echo $role; // Default: "regular".

acl_set_default_role

Returns default users role upon registration.

// acl_set_defaul_role($role_slug);
acl_set_default_role('regular');

acl_get_names

Retrieve list of all registered roles ad their names.

$names = acl_get_names();
// array(
//		'admininstrator' => 'Administrator',
//		'manager' => 'Manager',
//		'regular' => 'Regular',
// );

acl_add_cap

Adds capability to the given role.

// acl_add_cap($role, $cap, $status);
acl_add_cap('moderator', 'manage_users', true);
acl_add_cap('moderator', 'manage_options', false);

acl_remove_cap

Removes capability from role.

// acl_remove_cap($role, $cap);
acl_remove_cap('moderator', 'manage_options');

Actions on roles

You can execute some actions on retrieved roles:

$admin = acl_get_role('admin');	// Returns the role object.
$admin->add_cap($cap, $status);	// To add capability.
$admin->remove_cap($cap);		// To remove capability.
$admin->has_cap($cap);			// To check if the role has the capability.

Users function.

acl_users_instance

Simply returns an instance of Ianhub_Acl_Users class.

acl_user_caps

Returns an array of all user's compabilities. If the user has none, it returns user's role capabilities. IF, for some reason, nothing was found, it returns an empty array.

// $user may be user's ID/username or KB_User instance.
$caps = acl_user_caps($user); // Returns an array;

acl_user_has_cap

Checks whether the selected user has the given capability. The capability must exist and MUST be set to TRUE.

// $user may be user's ID/username or KB_User instance.
$status = acl_user_has_cap($user, 'manage_options'); // Boolean

acl_user_promote

Promotes the selected user to the given role. The role must exit to proceed. Otherwise, it will return false.

// $user may be user's ID/username or KB_User instance.
$status = acl_user_promote($user, 'manager');

acl_user_demote

Demotes the user back to default users role (default: regular).

// $user may be user's ID/username or KB_User instance.
$status = acl_user_demote($user);

acl_user_remove_cap

Removes a previously added capability from user capabilities list.

// $user may be user's ID/username or KB_User instance.
acl_user_remove_cap($user, 'manage_themes');
Clone this wiki locally