Skip to content

A Hook System in PHP

License

GPL-3.0, GPL-3.0 licenses found

Licenses found

GPL-3.0
LICENSE
GPL-3.0
license.txt
Notifications You must be signed in to change notification settings

taranjeet2022/hooks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 install?

composer require krypton/hooks

How to use?

We start with a simple example ...

<?php

use Krypton\Hooks\Hooks;

function print_user_save()
{
    echo "User is Saved";
}

function print_user_added()
{
    echo "User is Added to the System";
}

$hooks = Hooks::getInstance();

$hooks->getAction()->add($hooks->getFilter(), 'user_save', 'print_user_save');

$hooks->getAction()->add($hooks->getFilter(), 'user_save', 'print_user_added');

$hooks->getFilter()->add('uppercase', 'strtoupper');

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

<?php

$hooks = Hooks::getInstance();

echo '<div id="extra_header">';

echo $hooks->getFilter()->apply('uppercase', 'taranjeet');

$hooks->getAction()->do($hooks->getFilter(), 'user_save');

echo '</div>';

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

About

A Hook System in PHP

Resources

License

GPL-3.0, GPL-3.0 licenses found

Licenses found

GPL-3.0
LICENSE
GPL-3.0
license.txt

Stars

Watchers

Forks

Packages

No packages published

Languages