PHP code example of typisttech / wp-contained-hook

1. Go to this page and download the library: Download typisttech/wp-contained-hook 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/ */

    

typisttech / wp-contained-hook example snippets


use League\Container\Container;
use TypistTech\WPContainedHook\Hooks\Action;
use TypistTech\WPContainedHook\Hooks\Filter;
use TypistTech\WPContainedHook\Loader;

$container = new Container;

// Configure the container.
// This depends on your `psr/container-implementation`.
$container->add('bar', Bar::class);
$container->add('foo', Foo::class);

// Action.
$action = new Action('bar', 'admin_init', 'doSomething');

// Filter.
$filter = new Filter('foo', 'the_content', 'filterSomething');

// Add to loader.
$loader = new Loader($container);
$loader->add($action, $filter);

// Add to WordPress.
$loader->run();

$bar = new Bar();
add_action('admin_init', [$bar, 'doSomething'])

$foo = new Foo();
add_filter('the_content', [$foo, 'filterSomething'])

add_action('admin_init', function ($arg) use ($container): void {
  $bar = $container->get('bar');
  $bar->doSomething($arg);
})

add_filter('the_content', function ($arg) use ($container) {
  $foo = $container->get('foo');
  return $foo->filterSomething($arg);
})

$container = new Container;
$loader = new Loader($container);

// Action.
$action = new Action(SomeClass::class, 'plugin_loaded', 'doSomething');

// Filter.
$filter = new Filter(SomeClass::class, 'the_content', 'filterSomething');

// Add to loader
$loader->add($action, $filter);

$loader->run();

$action = new Action('bar', 'admin_init', 'doSomething', 20, 2);

$filter = new Filter('foo', 'the_content', 'filterSomething', 20, 2);