Class Hooks
Hooks is a class that manages all the hooks set throughout the framework.
Hooks are useful to attach actions to other actions, or to alter the execution thread without
changing the code.
Hooks is based on the Wordpress hooks system, to allow for plugin flexibility
Defaults:
The hooks included by default in the framework are:
Kernel\AppKernel
:
('After_Hooks_Setup', $hooks) // called right after the constructor
('exec_beforestart', ['controller' => $controllerName, 'action' => $action]) // just after Kernel\Router::matchRoute()
('permission_unallowed', [
'permission' => $permission,
'controller' => $controllerName,
'action' => $action]) // when it's an unauthorized request
('general_exception', ['e' => $e]) // when an Exception is thrown
('exec_afterend', ['controller' => $controllerName, 'action' => $action]) // When execution has finished
('include_show_view', ['vars' => $this->vars]) // Called just before including the view fileCore\ParentController::show()
('include_get_view', ['vars' => $_vars]) // Called just before including a view fileCore\ParentController::get()
('extra_params_path', ['route' => $route]) // If extra parameters are required when creating a urlCore\ParentController::$path
('on_userauth', ['user' => $user]) // Called just after the login session has been createdCore\LoginController::login()
('on_userdeauth', ['user' => Session::getUser()]) // Called just before destroying the login session.Core\LoginController::deauthenticateUser()
('show_prod_exception', ['e' => $e]) // Called when an exception is thrown on the PROD environmentCore\ExceptionController::showException()
('show_dev_exception', ['e' => $e]) // Called when an exception is thrown on the DEV environmentCore\ExceptionController::showException()
('logger_post', $postArray) // Called before posting an error log Kernel\Logger::sendLog()
See Core\Hooks::do_action()
and Core\Hooks::add_action()
functions to learn how to use them
Located at Hooks.php
public
|
|
public
boolean
|
#
add_filter( string $tag, callable $function_to_add, integer $priority = 10, integer $accepted_args = 1 )
add_filter Hooks a function or method to a specific filter action. |
public
boolean
|
#
remove_filter( string $tag, callable $function_to_remove, integer $priority = 10, integer $accepted_args,… )
remove_filter Removes a function from a specified filter hook. |
public
boolean
|
#
remove_all_filters( string $tag, integer $priority = false )
remove_all_filters Remove all of the hooks from a filter. |
public
mixed
|
#
has_filter( string $tag, callable $function_to_check = false )
has_filter Check if any filter has been registered for a hook. |
public
mixed
|
#
apply_filters( string $tag, mixed $value )
apply_filters Call the functions added to a filter hook. |
public
mixed
|
#
apply_filters_ref_array( string $tag, array $args )
apply_filters_ref_array Execute functions hooked on a specific filter hook, specifying arguments in an array. |
public
boolean|true
|
#
add_action( string $tag, callable $function_to_add, integer $priority = 10, integer $accepted_args = 1 )
add_action Hooks a function on to a specific action. |
public
mixed
|
#
has_action( string $tag, callable $function_to_check = false )
has_action Check if any action has been registered for a hook. |
public
boolean
|
#
remove_action( string $tag, callable $function_to_remove, integer $priority = 10 )
remove_action Removes a function from a specified action hook. |
public
boolean
|
#
remove_all_actions( string $tag, integer $priority = false )
remove_all_actions Remove all of the hooks from an action. |
public
mixed
|
#
do_action( string $tag, mixed $arg = '' )
do_action Execute functions hooked on a specific action hook. |
public
null
|
#
do_action_ref_array( string $tag, array $args )
do_action_ref_array Execute functions hooked on a specific action hook, specifying arguments in an array. |
public
integer
|
|
public
string
|
|
public
string
|
|
public
boolean
|
#
doing_filter( null|string $filter = null )
Retrieve the name of a filter currently being processed. |
public
boolean
|
#
doing_action( string|null $action = null )
Retrieve the name of an action currently being processed. |
public
|
public
array
|
$filters
$filters holds list of hooks |
#
array()
|
public
array
|
$merged_filters
$merged_filters |
#
array()
|
public
array
|
$actions
$actions |
#
array()
|
public
array
|
$current_filter
$current_filter holds the name of the current filter |
#
array()
|