registerHooks (function)

Last updated: Fri, May 26, 2023 9:26 am
Return to Knowledgebase

Purpose

The registerHooks function in UserSpice is a custom function used to register hooks for plugins. Hooks allow plugins to integrate with specific points in the UserSpice framework, enabling custom functionality and extending core features.

Location

users/helpers/us_helpers.php

Parameters

# Parameter Data Type Required Description
1 $hooks array Yes An associative array representing the hooks to register. The keys of the array represent the pages, and the values are nested arrays with keys representing the positions and values representing the hook names.
2 $plugin_name string Yes The name of the plugin registering the hooks.

Further Documentation:

$hooks = [
'dashboard' => [
'position1' => 'hook1',
'position2' => 'hook2',
],
'profile' => [
'position3' => 'hook3',
],
];

$pluginName = 'my_plugin';

registerHooks($hooks, $pluginName);



In the example above, the registerHooks function is called with the $hooks array and $pluginName as arguments. The $hooks array represents the hooks to be registered. It is an associative array where the keys represent the pages where the hooks will be registered, and the values are nested arrays. The nested arrays contain keys representing the positions within the page and values representing the hook names.

The function iterates over the $hooks array, checks if each hook is already registered in the us_plugin_hooks table, and updates the registration if it already exists. If a hook is not found, a new entry is inserted into the us_plugin_hooks table with the provided page, plugin name, position, and hook values.

By using the registerHooks function, plugins can add custom functionality to specific points within the UserSpice framework. This allows plugins to integrate seamlessly with UserSpice and extend its core features.