PHP code example of symplely / hooks

1. Go to this page and download the library: Download symplely/hooks library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

symplely / hooks example snippets


add_action('header_action', 'echo_this_in_header');

function echo_this_in_header() {
   echo 'this came from a hooked function';
}

echo '<div id="extra_header">';
  do_action('header_action');
echo '</div>';


Async\Hook\EventEmitter;

$emitter = new EventEmitter();


$emitter->on('user.created', function (User $user) use ($logger) {
    $logger->log(sprintf("User '%s' was created.", $user->getLogin()));
});


$emitter->emit('user.created', $user);

/**
 * Hooks a function on to a specific action hook.
 */
add_action($hook_point, $function_to_add, $priority, $accepted_args);

/**
 * Execute functions hooked on a specific action hook.
 * Will return null if $hook_point does not exist
 */
do_action($hook_point, ...$arg);

/**
 * Removes a function from a specified action hook.
 * Will return true if the function is removed
 */
remove_action($hook_point, $function_to_remove, $priority);

/**
 * Check if any action has been registered for a hook.
 * Will return boolean if anything registered, or the priority.
 */
has_action($hook_point, $function_to_check);

/**
 * Retrieve the number of times an action is fired.
 */
did_action($hook_point);

/**
 * Hooks a function or method to a specific filter hook.
 * Will return boolean true
 */
add_filter($hook_point, $function_to_add, $priority, $accepted_args);

/**
 * Removes a function from a specified filter hook.
 * Will return boolean Whether the function existed before it was removed
 */
remove_filter($hook_point, $function_to_remove, $priority, $accepted_args);

/**
 * Check if any filter has been registered for a hook.
 * Will return mixed
 */
has_filter($hook_point, $function_to_check);

/**
 * Call the functions added to a filter hook.
 * Will return the filtered value after all hooked functions are applied to it.
 */
apply_filters($hook_point, $value, ...$arg);