WP_CLI::do_hook PHP Method

do_hook() public static method

See WP_CLI::add_hook() for details on WP-CLI's internal hook system. Commands can provide and call their own hooks.
public static do_hook ( string $when ) : null
$when string Identifier for the hook.
return null
    public static function do_hook($when)
    {
        self::$hooks_passed[] = $when;
        if (!isset(self::$hooks[$when])) {
            return;
        }
        foreach (self::$hooks[$when] as $callback) {
            if (func_num_args() > 1) {
                $args = array_slice(func_get_args(), 1);
                call_user_func_array($callback, $args);
            } else {
                call_user_func($callback);
            }
        }
    }

Usage Example

 /**
  * Invoke the subcommand with the supplied arguments.
  * Given a --prompt argument, interactively request input
  * from the end user.
  *
  * @param array $args
  * @param array $assoc_args
  */
 public function invoke($args, $assoc_args, $extra_args)
 {
     if (\WP_CLI::get_config('prompt')) {
         list($args, $assoc_args) = $this->prompt_args($args, $assoc_args);
     }
     $to_unset = $this->validate_args($args, $assoc_args, $extra_args);
     foreach ($to_unset as $key) {
         unset($assoc_args[$key]);
     }
     $path = get_path($this->get_parent());
     \WP_CLI::do_hook('before_invoke:' . implode(' ', array_slice($path, 1)));
     call_user_func($this->when_invoked, $args, array_merge($extra_args, $assoc_args));
 }