Primary

API

Filters

groups_file_access_can_access

This filter is used to modify whether a file should be accessible for a particular user or not. The filter is invoked before the file is served.

The filter takes three parameters and must return a boolean which determines whether the user is allowed to access the particular file or not.

Parameters:

  • boolean $can_access true if the user is already allowed to access the file, otherwise false
  • int $user_id the ID of the user to whom the file would be served
  • int $file_id the ID of the file to be served

Returns:

boolean true if the user should be allowed to access the file, otherwise false

Example:

function custom_groups_file_access_can_access(  $can_access, $user_id, $file_id ) {
	if ( $can_access ) {
		// additional verification ...
	}
	return $can_access;
}
add_filter( 'groups_file_access_can_access', 'custom_groups_file_access_can_access', 10, 3 );

We recommend to put this in a plugin of its own although a customized filter can also be added to your theme’s functions.php.

groups_file_access_server_response_title

Allows to modify the page title.

This is one of several filters that allow to customize server responses when 403 or 404 responses are sent in reply to requests for invalid or inaccessible files. See the Groups File Access Custom Response plugin for an example implementation. This filter cannot be used within a theme’s functions.php, it must be used within a plugin.

Parameters:

  • string $title  the page title
  • int $code the error code
  • int $file_id the ID of the file

Returns:

string the page title

groups_file_access_server_response_heading

Allows to modify the heading displayed.

This is one of several filters that allow to customize server responses when 403 or 404 responses are sent in reply to requests for invalid or inaccessible files. See the Groups File Access Custom Response plugin for an example implementation. This filter cannot be used within a theme’s functions.php, it must be used within a plugin.

Parameters:

  • string $heading  the heading
  • int $code the error code
  • int $file_id the ID of the file

Returns:

string the heading

groups_file_access_server_response_message

Allows to modify the message displayed.

This is one of several filters that allow to customize server responses when 403 or 404 responses are sent in reply to requests for invalid or inaccessible files. See the Groups File Access Custom Response plugin for an example implementation. This filter cannot be used within a theme’s functions.php, it must be used within a plugin.

Parameters:

  • string $message  the message
  • int $code the error code
  • int $file_id the ID of the file

Returns:

string the message

groups_file_access_server_response_document

Allows to modify the document, uses %s placeholders for title, heading and message.

This is one of several filters that allow to customize server responses when 403 or 404 responses are sent in reply to requests for invalid or inaccessible files. See the Groups File Access Custom Response plugin for an example implementation. This filter cannot be used within a theme’s functions.php, it must be used within a plugin.

Parameters:

  • string $document  the document
  • int $code the error code
  • int $file_id the ID of the file

Returns:

string the document

Actions

groups_created_file

This action is invoked when a new file has been created.

Parameters:

  • int $file_id the file id

groups_updated_file

This action is invoked when a file or the data related to it has been updated.

Parameters:

  • int $file_id the file id

groups_deleted_file

This action is invoked when a file has been deleted.

Parameters:

  • object $file the file row object

groups_created_file_group

This action is invoked when a file is related to a group.

Parameters:

  • int $file_id the file id
  • int $group_id the group id

groups_deleted_file_group

This action is invoked when the relation of a file has been removed from a group.

Parameters:

  • int $file_id the file id
  • int $group_id the group id

groups_file_served

This action is triggered when a file has been served to a user.

Parameters:

  • int $file_id the file id
  • int $user_id the user id

Classes

Groups_File_Access

The Groups_File_Access class provides class methods that can be used to obtain information about files and user access on files.

Groups_File_Access::can_access( $user_id, $file_id )

Returns true if a user can access a file handled by the Groups File Access plugin.

Parameters:

  • int $user_id the user id
  • int $file_id the file id

Returns:

boolean true if the user can access the file, otherwise false

Groups_File_Access:get_count( $user_id, $file_id )

Return the number of times the user has accessed the file.

Parameters:

  • int $user_id the user id
  • int $file_id the file id

Returns:

int number of times

Groups_File_Access:get_max_count( $file_id )

Returns the maximum number of accesses allowed per user for the given file.

Parameters:

  • int $file_id the file id

Returns:

int number of accesses allowed, 0 for unlimited, null on error

Groups_File_Access::get_remaining( $user_id, $file_id )

Returns the number of remaining accesses on the file for the given user.

Parameters:

  • int $user_id the user id
  • int $file_id the file id

Returns:

int remaining number of times the user can access the file or INF if unlimited

GFA_Shortcodes

The GFA_Shortcodes class provides class methods that can be used to render links and information about files handled by the Groups File Access plugin.

GFA_Shortcodes::groups_file_url( $atts, $content = null )

Renders a file URL.

Attributes are passed through $atts:

  • file_id : id of the file
  • visibility : This option determines whether the file URL will be returned for the current user or not. can_access will only return the file URL if the current user is allowed to access the file; always will return the file URL disregarding whether the user is allowed to access the file.

Parameters

  • array $atts attributes
  • string $content – not used

Returns:

string rendered URL

GFA_Shortcodes::groups_file_link( $atts, $content = null )

Renders a link to a file based on settings passed through $atts.

Required attributes are either file_id or group.

Basic attributes:

  • file_id : id of the file
  • visibility : can_access or always see GFA_Shortcodes::groups_file_url()
  • group : group name or ID – will list files for the given group sorted by name
  • description : defaults to noyes shows description for each entry (only group)
  • order : ASC or DESC sort order (only for group)
  • list_prefix : defaults to <ul>
  • list_suffix : defaults to </ul>
  • item_prefix : defaults to <li>
  • item_suffix : defaults to </li>

Note that the prefixes and suffixes are very limited due to filters applied.

Allowed link attributes that are applied to the rendered a tag: accesskeyaltcharsetcoordsclassdirhreflangidlangnamerelrevshapestyletabindextarget

Parameters:

  • array $atts attributes
  • string $content not used

Returns:

string rendered link

GFA_Shortcodes::groups_can_access_file( $atts, $content = null )

Returns $content if the current user can access the file.

Parameters:

  • array $atts attributes – must provide the file_id
  • string $content content to render

Returns:

string $content or empty string

GFA_Shortcodes::groups_can_not_access_file( $atts, $content = null )

Returns $content if the current user can not access the file.

Parameters:

  • array $atts attributes – must provide the file_id
  • string $content content to render

Returns:

string $content or empty string

GFA_Shortcodes::groups_file_info( $atts, $content = null )

Renders file information.

The visibility parameter determines whether the $content will be returned for the current user or not:

can_access will only return $content if the current user is allowed to access the file; alwayswill return $content disregarding whether the user is allowed to access the file

Attributes:

  • file_id : id of the file
  • visibility : can_access (default) or always
  • show : namedescriptioncountmax_countremainingfile_id

Parameters:

  • array $atts attributes – must provide the file_id
  • string $content content to render

Returns:

string $content or empty string

GFA_Shortcodes::groups_visibility( $atts, $content = null )

Allows to switch the default visibility setting for shortcodes handled by GFA_Shortcodes.

Parameters:

  • array $atts attributes must specify the visibility with allowed values alwayscan_access
  • string $content not used