Elgg  Version master
Functions
access.php File Reference

Go to the source code of this file.

Functions

 elgg_get_ignore_access ()
 Functions for Elgg's access system for entities, metadata, and annotations. More...
 
 elgg_get_access_array (int $user_guid=0)
 Returns an array of access IDs a user is permitted to see. More...
 
 elgg_get_default_access (\ElggUser $user=null, array $input_params=[])
 Gets the default access permission. More...
 
 elgg_has_access_to_entity (int $entity_guid, int $user_guid=0)
 Can a user access an entity. More...
 
 elgg_get_write_access_array (int $user_guid=0, bool $flush=false, array $input_params=[])
 Returns an array of access permissions that the user is allowed to save content with. More...
 
 elgg_create_access_collection (string $name, int $owner_guid=0, string $subtype=null)
 Creates a new access collection. More...
 
 elgg_get_access_collection (int $collection_id)
 Get a specified access collection. More...
 
 elgg_get_access_collections (array $options=[])
 Returns access collections. More...
 
 elgg_get_readable_access_level (int $entity_access_id)
 Return the name of an ACCESS_* constant or an access collection, but only if the logged in user has write access to it. More...
 

Function Documentation

elgg_create_access_collection ( string  $name,
int  $owner_guid = 0,
string  $subtype = null 
)

Creates a new access collection.

Access colletions allow plugins and users to create granular access for entities.

Triggers 'create', 'access_collection' event sequence

Parameters
string$nameThe name of the collection
int$owner_guidThe GUID of the owner (default: currently logged in user)
string$subtypeThe subtype indicates the usage of the acl
Returns
|null
Since
4.3

Definition at line 147 of file access.php.

elgg_get_access_array ( int  $user_guid = 0)

Returns an array of access IDs a user is permitted to see.

Can be overridden with the 'access:collections:read', 'user' event.

Warning
A callback for that event needs to either not retrieve data from the database that would use the access system (triggering the plugin again) or ignore the second call. Otherwise, an infinite loop will be created.

This returns a list of all the collection ids a user owns or belongs to plus public and logged in access levels. If the user is an admin, it includes the private access level.

See also
elgg_get_write_access_array() for the access levels that a user can write to.
Parameters
int$user_guidUser ID; defaults to currently logged in user
Returns
array An array of access collections ids
Since
4.3

Definition at line 39 of file access.php.

elgg_get_access_collection ( int  $collection_id)

Get a specified access collection.

Parameters
int$collection_idThe collection ID
Returns
|null
Since
4.3

Definition at line 164 of file access.php.

elgg_get_access_collections ( array  $options = [])

Returns access collections.

Parameters
array$optionsarray of options to get access collections by
Returns
[]

Definition at line 175 of file access.php.

elgg_get_default_access ( \ElggUser  $user = null,
array  $input_params = [] 
)

Gets the default access permission.

This returns the default access level for the site or optionally of the user. If want you to change the default access based on group of other information, use the 'default', 'access' event.

Parameters
\ElggUser$userThe user for whom we're getting default access. Defaults to logged in user.
array$input_paramsParameters passed into an input/access view
Returns
int default access id (see ACCESS defines in constants.php)
Since
4.3

Definition at line 56 of file access.php.

elgg_get_ignore_access ( )

Functions for Elgg's access system for entities, metadata, and annotations.

Access is generally saved in the database as access_id. This corresponds to one of the ACCESS_* constants defined in elgglib.php or the ID of an access collection. Get current ignore access setting.

Returns
bool
Since
1.7.0

Definition at line 16 of file access.php.

elgg_get_readable_access_level ( int  $entity_access_id)

Return the name of an ACCESS_* constant or an access collection, but only if the logged in user has write access to it.

Write access requirement prevents us from exposing names of access collections that current user has been added to by other members and may contain sensitive classification of the current user (e.g. close friends vs acquaintances).

Returns a string in the language of the user for global access levels, e.g.'Public, 'Friends', 'Logged in', 'Public'; or a name of the owned access collection, e.g. 'My work colleagues'; or a name of the group or other access collection, e.g. 'Group: Elgg technical support'; or 'Limited' if the user access is restricted to read-only, e.g. a friends collection the user was added to

Parameters
int$entity_access_idThe entity's access id
Returns
string
Since
4.3

Definition at line 196 of file access.php.

elgg_get_write_access_array ( int  $user_guid = 0,
bool  $flush = false,
array  $input_params = [] 
)

Returns an array of access permissions that the user is allowed to save content with.

Permissions returned are of the form (id => 'name').

Example return value in English: array( 0 => 'Private', -2 => 'Friends', 1 => 'Logged in users', 2 => 'Public', 34 => 'My favorite friends', );

Event of 'access:collections:write', 'user'

Warning
this only returns access collections that the user owns plus the standard access levels. It does not return access collections that the user belongs to such as the access collection for a group.
Parameters
int$user_guidThe user's GUID
bool$flushIf this is set to true, this will ignore a cached access array
array$input_paramsSome parameters passed into an input/access view
Returns
array List of access permissions
Since
4.3

Definition at line 129 of file access.php.

elgg_has_access_to_entity ( int  $entity_guid,
int  $user_guid = 0 
)

Can a user access an entity.

This is mostly useful for checking if a user other than the logged in user has access to an entity that is currently loaded.

Parameters
int$entity_guidThe entity_guid to check access for
int$user_guidOptionally user_guid to check access with (defaults to logged in user)
Returns
bool
Since
4.3

Definition at line 91 of file access.php.