1. Go to this page and download the library: Download paperpixel/wp-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/ */
paperpixel / wp-hooks example snippets
use WPHooks\WPHook;
class ExampleHook extends WPHook {
// Mandatory method, used to register actions and filters with Wordpress.
public function register() {
$this->add_action('init', 'my_action_hook');
$this->add_filter('the_title', 'my_filter_hook');
}
private function my_action_hook() {
// Stuff here will be called by Wordpress
}
private function my_filter_hook($title) {
// Stuff here will be called by Wordpress
}
}
// functions.php
new ExampleHook();
$example_hook->register();
// functions.php
p';
// You can pass a WPHook instance
WPHooks\WPHookLoader::register(new ExampleHook());
// Or an array of WPHook instances
WPHooks\WPHookLoader::register([
new Hook1(),
new Hook2(),
new Hook3(),
...
]);
// __autoload.php
use Composer\Autoload\ClassLoader;
$loader = new ClassLoader();
$loader-> register();
$loader->addPsr4('Hooks\\Actions\\', __DIR__ . '/hooks/actions');
$loader->addPsr4('Hooks\\Filters\\', __DIR__ . '/hooks/filters');
// hooks/actions/ExampleAction.php
namespace Hooks\Actions;
use WPHooks\WPHook;
class ExampleAction extends WPHook {
function register() {
...
}
}
// functions.php
// Without WPHookLoader
$example_actions = new Actions\ExampleAction();
// With WPHookLoader
WPHooks\WPHookLoader::register(new Actions\ExampleAction());