Skip to content

3.1) Hooks: Implementation

Marco Cesarato edited this page Apr 11, 2019 · 6 revisions

Hooks/Plugins Implementation

For write hooks you can use hooks/custom folder or edit manually the examples on hooks/actions.hooks.php or hooks/filters.hooks.php

Remember to name file like this pattern: [FILENAME].hooks.php or it will not be included automatically (else you can include it manually)

Tips

You can use this code for have a database instance and the current user authenticated row:

$user = Auth::getUser(); // User row
$db = API::getDatabase('dataset'); // You can specify dataset. Return PDO Object

Most important hooks

  • sql_restriction

    Description: Return a string to append in where condition

    Parameters: $table, $permission

    Options of $permission:

    case 'READ':
    case 'EDIT':
    case 'DELETE':

    Return

    // All denied
    $sql = "'1' = '0'";
    // All allowed
    $sql = "'1' = '1'";

    Examples:

    // Only Created
    $sql = 'created_by = '.$user['id'];
    // Only Team
    $sql = 'created_by IN ('.implode(',',$teams_ids).')';
  • can_read

    Description: Return if can GET/SELECT

    Parameters: $restriction, $permission, $table

    Return: Boolean

  • can_write

    Description: Return if can POST/INSERT

    Parameters: $permission, $table

    Return: Boolean

  • can_edit

    Description: Return if can PUT/UPDATE

    Parameters: $permission, $table

    Return: Boolean

  • can_delete

    Description: Return if can DELETE

    Parameters: $permission, $table

    Return: Boolean

Clone this wiki locally