includeHook (function)

Last updated: Mon, Apr 17, 2023 10:34 am
Return to Knowledgebase

Purpose

Includes plugin hooks at a specific position in the application.

Location

users/helpers/us_helpers.php

Parameters

# Parameter Data Type Required Description
1 $hooks array Yes An array of hooks where the key is the position and the value is an array of hook files to include at that position.
2 $position string Yes The position where the hooks should be included. This can be one of the following values: 'head', 'body', 'body-close', 'footer'.

Returns

Data Type Description of Returned Data
nothing

Further Documentation:

The includeHook function is a Userspice function that includes plugin hooks at a specific position in the application. It takes two parameters:

$hooks: An array containing the list of plugin hooks. Each hook is an array containing the following information:
name: The name of the plugin that defines the hook.
file: The file path of the hook file within the plugin.
$position: The position of the hook to include. This can be one of the following values:
'pre': The hook will be included before the main content.
'post': The hook will be included after the main content.The function loops through the list of hooks at the specified position and includes the file associated with each hook if the plugin that defines the hook is installed and active.

Example usage:

// Define plugin hooks
$hooks = [
'my_plugin' => [
[
'name' => 'my_plugin',
'file' => 'hooks/my_hook.php',
],
],
];

// Include pre-content hooks
includeHook($hooks, 'pre');

// Output main content

// Include post-content hooks
includeHook($hooks, 'post');



In this example, the includeHook function is used to include the hooks defined by the my_plugin plugin before and after the main content of the page. The $hooks array contains one hook defined by the my_plugin plugin, which specifies the file hooks/my_hook.php to be included at the specified position.