PHPackages                             pessek/hypecapabilities - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. pessek/hypecapabilities

ActiveElgg-plugin

pessek/hypecapabilities
=======================

Roles and capabilities API

v1.2.1(4y ago)05proprietaryPHPPHP &gt;=7.1

Since May 29Pushed 4y ago1 watchersCompare

[ Source](https://github.com/rheman/hypeCapabilities)[ Packagist](https://packagist.org/packages/pessek/hypecapabilities)[ RSS](/packages/pessek-hypecapabilities/feed)WikiDiscussions master Synced today

READMEChangelog (2)Dependencies (1)Versions (3)Used By (0)

hypeCapabilities
================

[](#hypecapabilities)

Capabilities and roles API

Registering a role
------------------

[](#registering-a-role)

```
\hypeJunction->register('role_name');
```

Assigning a role to a user
--------------------------

[](#assigning-a-role-to-a-user)

```
// Site wide role
elgg()->roles->assign('role_name', $user);

// Group specific role
elgg()->roles->assign('role_name', $user, $group);
```

Remove a role from a user
-------------------------

[](#remove-a-role-from-a-user)

```
// Site wide role
elgg()->roles->unassign('role_name', $user);

// Group specific role
elgg()->roles->unassign('role_name', $user, $group);
```

Configuring role permissions
----------------------------

[](#configuring-role-permissions)

### Creating entities of a specific type

[](#creating-entities-of-a-specific-type)

```
// Prevent users with given role from creating entities of a given type
elgg()->roles->role_name->onCreate('object', 'blog', Role::DENY);

// Allow users to create entities of a given type regardless of context
elgg()->roles->role_name->onCreate('object', 'blog', Role::ALLOW, Role::OVERRIDE);

// Allow users to create entities of a given type if all other container permissins are met
elgg()->roles->role_name->onCreate('object', 'blog', Role::ALLOW, Role::STACK);

// Allow users to create entities when specific conditions are met
// Only allow group blogs
elgg()->roles->role_name->onCreate('object', 'blog', Role::DENY, function(\hypeJunction\Capabilities\Context $context) {
	$container = $context->getTarget();
	if (!$container instanceof ElggGroup) {
		return Role::DENY;
	}
});
```

### Update and delete permissions

[](#update-and-delete-permissions)

Similar to above, you can use `onUpdate` and `onDelete` methods;

### Granting administrative permissions

[](#granting-administrative-permissions)

Administrative permissions imply high-level administrative action on entities, e.g. approving a certain post after moderation. By default, core does not use this privilege level, but you can check if the user has admin permissions over an entity like so:

```
$params = [
	'entity' => $entity,
	'user' => $user,
];
if (!elgg_trigger_plugin_hook('permissions_check:administer', "$entity->type:$entity->subtype", $params, false)) {
	// No permissions to approve
	throw new EntityPermissionsException();
}

// Do something that requires high level permissions, e.g.
$entity->published_status = 'published';
```

Granting/denying admin permissions

```
// Prevent users with given role from creating entities of a given type
// Allow moderator role to administer all blogs regardless of owner/container
elgg()->roles->moderator->onAdminister('object', 'blog', Role::ALLOW, Role::OVERRIDE);

// Allow users to create entities when specific conditions are met
// Allow teacher to administer all group blogs
elgg()->roles->teacher->canAdminister('object', 'blog', Role::ALLOW, function(\hypeJunction\Capabilities\Context $context) {
	$entity = $context->getTarget();
	$actor = $context->getActor();

	$container = $entity->getContainerEntity();
	return $container->canEdit($actor->guid);
});
```

### Routes

[](#routes)

You can allow/deny access to certain routes by route name

```
// Context parameter contain matched route elements
// e.g. prevent access to user profile if users are not friends
elgg()->roles->user->onRouteAccess('view:user', Role::DENY, function(\hypeJunction\Capabilities\Context $context) {
	$actor = $context->getActor();

	$username = $context->getParam('username');
	$user = get_user_by_username($username);

	if (!$actor || !$user instanceof ElggUser || !$actor->isFriendOf($user->guid)) {
		register_error('You must be friends to access user profiles');
		return Role::DENY;
	}
});

// Here is an example of how to prevent access to member pages to non-logged in users:
elgg()->roles->guest->onRouteAccess('collection:user:user', Role::DENY);
elgg()->roles->guest->onRouteAccess('collection:user:user:alpha', Role::DENY);
elgg()->roles->guest->onRouteAccess('collection:user:user:newest', Role::DENY);
elgg()->roles->guest->onRouteAccess('collection:user:user:online', Role::DENY);
elgg()->roles->guest->onRouteAccess('collection:user:user:popular', Role::DENY);
elgg()->roles->guest->onRouteAccess('search:user:user', Role::DENY);
elgg()->roles->guest->onRouteAccess('view:user', Role::DENY);
```

### Custom (component) capabilities

[](#custom-component-capabilities)

You can check and alter custom capabilities:

```
// Check a custom role
elgg()->roles->can('read', 'discussions');

// Define how role responds to capability check
elgg()->roles->guest->on('read', 'discussions', Role::DENY);

// Override role response
elgg_register_plugin_hook_handler('capability', 'read:discussions', function(Hook $hook) {

});
```

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

1806d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/649b17479d3b3a91bcdbbd05d56d9c55a33e095c8c4412ba6a34fa43bd3aff46?d=identicon)[rhemandaddy](/maintainers/rhemandaddy)

---

Tags

pluginelggrolescapabilities

### Embed Badge

![Health badge](/badges/pessek-hypecapabilities/health.svg)

```
[![Health](https://phpackages.com/badges/pessek-hypecapabilities/health.svg)](https://phpackages.com/packages/pessek-hypecapabilities)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
