Actions

This concept is based on Wordpress hook functions.

Reference: https://thachpham.com/wordpress/wordpress-development/cach-su-dung-action-hook-trong-wordpress.html

Reference: https://viblo.asia/p/action-hook-va-filter-hook-trong-wordpress-p1-QpmleQqrlrd

#Add action

Reference: https://developer.wordpress.org/reference/functions/add_action

function add_action(string $tag, callable $function_to_add, int $priority = 10, int $accepted_args = 1)

#Description

Actions are the hooks that the core launches at specific points during execution, or when specific events occur.

Plugins can specify that one or more of its PHP functions are executed at these points, using the Action API.

#Parameters

Parameter Value Description
tag string (Required) The name of the filter to hook the $function_to_add callback to.
function_to_add callable (Required) The callback to be run when the filter is applied.
priority int | Default value: 10 Used to specify the order in which the functions associated with a particular action are executed. Lower numbers correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the action.
accepted_args int | Default value: 1 The number of arguments the function accepts.

#Do action

Reference: https://developer.wordpress.org/reference/functions/do_action

function do_action(string $tag, mixed $value)

#Description

This function invokes all functions attached to action hook $tag. It is possible to create new action hooks by simply calling this function, specifying the name of the new hook using the $tag parameter.

You can pass extra arguments to the hooks, much like you can with apply_filters().

#Parameters

Parameter Value Description
tag string (Required) The name of the filter hook.
value mixed (Required) The value on which the filters hooked to $tag are applied on..

#Remove action

Reference: https://developer.wordpress.org/reference/functions/remove_action

function remove_action( string $tag, callable $function_to_remove, int $priority = 10 )

#Description

This function removes a function attached to a specified filter hook. This method can be used to remove default functions attached to a specific filter hook and possibly replace them with a substitute.

To remove a hook, the $function_to_remove and $priority arguments must match when the hook was added. This goes for both filters and actions. No warning will be given on removal failure.

#Parameters

Parameter Value Description
tag string (Required) The filter hook to which the function to be removed is hooked.
function_to_remove callable (Required) The name of the function which should be removed.
priority int | Default value: 10 The priority of the function.