• Stars
    star
    274
  • Rank 149,834 (Top 3 %)
  • Language
    PHP
  • License
    GNU General Publi...
  • Created about 12 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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 .

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.

Head Over to http://bainternet.github.io/PHP-Hooks/ For more info


How to Use?

Simple, Include the class file in your application bootstrap (setup/load/configuration or whatever you call it) and start hooking your filter and action hooks using the global $hooks. Ex:

include_once('php-hooks.php');
global $hooks;
$hooks->add_action('header_action','echo_this_in_header');

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

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

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

and you output will be:

<div id="extra_header">this came from a hooked function</div>

Methods

ACTIONS:

add_action Hooks a function on to a specific action.

 - @access public
 - @since 0.1
 - @param string $tag The name of the action to which the $function_to_add is hooked.
 - @param callback $function_to_add The name of the function you wish to be called.
 - @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).

do_action Execute functions hooked on a specific action hook.

 - @access public
 - @since 0.1
 - @param string $tag The name of the action to be executed.
 - @param mixed $arg,... Optional additional arguments which are passed on to the functions hooked to the action.
 - @return null Will return null if $tag does not exist

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.
 - @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).
 - @return boolean Whether the function is removed.

has_action Check if any action has been registered for a hook.

 -  @access public
 -  @since 0.1
 -  @param string $tag The name of the action 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.

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

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

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.

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.
   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.

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

Download

You can download this project in either zip or tar formats

You can also clone the project with Git by running:

$ git clone git://github.com/bainternet/PHP-Hooks.git

License

Since this class is derived from the WordPress Plugin API so are the license and they are GPL http://www.gnu.org/licenses/gpl.html

Analytics

More Repositories

1

Tax-Meta-Class

A class for creating WordPress taxonomies custom fields
PHP
405
star
2

My-Meta-Box

A class for creating custom meta boxes for WordPress
JavaScript
223
star
3

Admin-Page-Class

create custom WordPress Admin option Pages
JavaScript
128
star
4

bs3_panel_shortcode

A plugin to add Bootstrap 3 panel shortcode as a part to the GWP tutorial a part of the Take your shortcodes to the ultimate level tutorial http://generatewp.com/?p=11889
JavaScript
63
star
5

Memchaced-Dashboard

A dead simple single file Memchaced stats dashboard in PHP.
PHP
57
star
6

Wamp-WordPress-installer

Simple WordPress Auto Installer for WAMP
PHP
41
star
7

GWP-Custom-Product-Tabs

A plugin to add Custom product tabs for WooCommerce a part of the Create WooCommerce custom product tabs plugin tutorial http://generatewp.com/create-woocommerce-custom-product-tabs-plugin/
PHP
23
star
8

GWP-Widget-Cache

A plugin to cache WordPress Widgets using the Transients API, based on this tutorial http://generatewp.com/?p=10132
PHP
15
star
9

GWP-Menu-Cache

A plugin to cache WordPress menus using the Transients API, based on this tutorial http://generatewp.com/?p=10473
PHP
12
star
10

SQLite-simple-store

Super lightweight Zero configuration sqlite-based key => value store with expiration time for PHP.
PHP
12
star
11

GWP-mail-BCC-and-CC

A plugin to add bcc and cc email address to any mail sent by WordPress part of the Allow multiple recipients to any WordPress mail tutorial http://generatewp.com/allow-multiple-recipients-wordpress-mail/
PHP
11
star
12

FlatFileDB

FlatFileDB
PHP
6
star
13

FancyCheckbox

FancyCheckbox is a simple and lightweight jQuery plugin to create Iphone styled checkboxes
JavaScript
4
star
14

Curlo

simple curl wrapper for PHP based on the WordPress HTTP curl class
PHP
4
star
15

Lyte_video

Lyte_video is a jquery plugin to embed youtube videos on selected event, after the page loads
JavaScript
4
star
16

elementor-oembed-widget

PHP
2
star
17

Contact-Form-7-Israeli-Phone-numbers

This plugin add a new form tag named [telil] which acts just like the tel tag but validate against Israeli mobile and land-line phone numbers ex: 052-5555555, 052-555-5555,0525555555,08-5555555,085555555. known mobile pattern is 10 digital starting with: "050","052","053","054","055","056","057","058","059". known land-lines patterns are 10 digital starting with:"072","073","074","076","077","078" and 9 digital starting with "02","03","04","08","09".
PHP
1
star