Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
voku committed Nov 29, 2015
1 parent df67c60 commit a8bdb01
Showing 1 changed file with 47 additions and 46 deletions.
93 changes: 47 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,42 @@ PHP-Hooks
The PHP Hooks Class is a fork of the WordPress filters hook system rolled in to a class to be ported into any php based system
* This class is heavily based on the WordPress plugin API and most (if not all) of the code comes from there.


----------

How to Use?
=====

We start with a simple example ...

<?php
```php
<?php

$hooks = Hooks::getInstance();
$hooks = Hooks::getInstance();

$hooks->add_action('header_action','echo_this_in_header');

function echo_this_in_header(){
echo 'this came from a hooked function';
}
$hooks->add_action('header_action','echo_this_in_header');

then all that is left for you is to call the hooked function when you want anywhere in your application, EX:
function echo_this_in_header(){
echo 'this came from a hooked function';
}
```

<?php
then all that is left for you is to call the hooked function when you want anywhere in your application, EX:

$hooks = Hooks::getInstance();
```php
<?php

echo '<div id="extra_header">';
$hooks->do_action('header_action');
echo '</div>';
$hooks = Hooks::getInstance();

echo '<div id="extra_header">';
$hooks->do_action('header_action');
echo '</div>';
```

and you output will be: `< div id="extra_header">this came from a hooked function</div>`

PS: you can also use method from a class for a hook e.g.:

$hooks->add_action('header_action', array($this, 'echo_this_in_header_via_method');
```php
$hooks->add_action('header_action', array($this, 'echo_this_in_header_via_method');
```

Methods
=======
Expand All @@ -69,7 +71,6 @@ Methods

**remove_action** Removes a function from a specified action hook.


- @access public
- @since 0.1
- @param string $tag The action hook to which the function to be removed is hooked.
Expand All @@ -90,52 +91,52 @@ Methods

**did_action** Retrieve the number of times an action is fired.

- @access public
- @since 0.1
- @param string $tag The name of the action hook.
- @return int The number of times action hook <tt>$tag</tt> is fired
- @access public
- @since 0.1
- @param string $tag The name of the action hook.
- @return int The number of times action hook <tt>$tag</tt> is fired

**FILTERS:**

**add_filter** Hooks a function or method to a specific filter action.

- @access public
- @since 0.1
- @param string $tag The name of the filter to hook the $function_to_add to.
- @param callback $function_to_add The name of the function to be called when the filter is applied.
- @param int $priority optional. Used to specify the order in which the functions associated with a particular action are executed (default: 10). 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.
- @param int $accepted_args optional. The number of arguments the function accept (default 1).
- @return boolean true
- @since 0.1
- @param string $tag The name of the filter to hook the $function_to_add to.
- @param callback $function_to_add The name of the function to be called when the filter is applied.
- @param int $priority optional. Used to specify the order in which the functions associated with a particular action are executed (default: 10). 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.
- @param int $accepted_args optional. The number of arguments the function accept (default 1).
- @return boolean true

**remove_filter** Removes a function from a specified filter hook.

- @access public
- @since 0.1
- @param string $tag The filter hook to which the function to be removed is hooked.
- @param callback $function_to_remove The name of the function which should be removed.
- @param int $priority optional. The priority of the function (default: 10).
- @param int $accepted_args optional. The number of arguments the function accepts (default: 1).
- @return boolean Whether the function existed before it was removed.
- @access public
- @since 0.1
- @param string $tag The filter hook to which the function to be removed is hooked.
- @param callback $function_to_remove The name of the function which should be removed.
- @param int $priority optional. The priority of the function (default: 10).
- @param int $accepted_args optional. The number of arguments the function accepts (default: 1).
- @return boolean Whether the function existed before it was removed.


**has_filter** Check if any filter has been registered for a hook.

- @access public
- @since 0.1
- @param string $tag The name of the filter hook.
- @param callback $function_to_check optional.
- @return mixed If $function_to_check is omitted, returns boolean for whether the hook has anything registered.
- @access public
- @since 0.1
- @param string $tag The name of the filter hook.
- @param callback $function_to_check optional.
- @return mixed If $function_to_check is omitted, returns boolean for whether the hook has anything registered.
When checking a specific function, the priority of that hook is returned, or false if the function is not attached.
When using the $function_to_check argument, this function may return a non-boolean value that evaluates to false (e.g.) 0, so use the === operator for testing the return value.

**apply_filters** Call the functions added to a filter hook.

- @access public
- @since 0.1
- @param string $tag The name of the filter hook.
- @param mixed $value The value on which the filters hooked to <tt>$tag</tt> are applied on.
- @param mixed $var,... Additional variables passed to the functions hooked to <tt>$tag</tt>.
- @return mixed The filtered value after all hooked functions are applied to it.
- @access public
- @since 0.1
- @param string $tag The name of the filter hook.
- @param mixed $value The value on which the filters hooked to <tt>$tag</tt> are applied on.
- @param mixed $var,... Additional variables passed to the functions hooked to <tt>$tag</tt>.
- @return mixed The filtered value after all hooked functions are applied to it.

There are a few more methods but these are the main ones you'll use :).

Expand Down

0 comments on commit a8bdb01

Please sign in to comment.