Skip to content

JacobPrice/wp-hooks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WP HOOKS

Installation

composer require jacobprice/wp-hooks php-di/php-di

Usage

use Jacobprice\WpHooks\HookManager;
use DI\ContainerBuilder;

$container_builder = new ContainerBuilder();
$container = $container_builder->build();
$hook_manager = new HookManager( $container );

$hook_manager->add_source('ExampleNameSpace\\Hooks\\', __DIR__ . '/app/Hooks');

$hook_manager->register_hooks();

Example Hook Class

<?php

namespace ExampleNameSpace\Hooks;

use Jacobprice\WpHooks\Interfaces\Action;
use Jacobprice\WpHooks\Interfaces\Filter;

class ExampleAction implements Action, Filter{
    /**
     * Lazily load this hook
     */
    public function should_load() : bool {
        return is_admin();
    }
    /**
     * Load the hook
     */
    public function load() {
        $this->add_action('init', [$this, 'init']);
        $this->add_filter('the_content', [$this, 'the_content']);
    }

    public function init() {
        echo 'Hello, World!';
    }

    public function the_content($content) {
        return $content;
    }
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages