Example #1
0
 /**
  * Add a listener for a WP hook.
  *
  * @since 0.1.0
  *
  * @param string $hook Hook to create listener for.
  * @param \Wplog\Events\Listener $listener The closure that creates the event for
  *                                         the hook.
  *
  * @return void
  */
 public function addListener(string $hook, Listener $listener)
 {
     // Create a callback wrapper to let the world outside the hook know about it.
     $cb = function (...$args) use($listener) {
         $event = $listener->onHookTrigger(current_filter(), $args);
         if ($event instanceof Event) {
             $this->listenerEvents[] = $event;
         }
     };
     add_action($hook, $cb, 999, 10);
 }