$hooks->runHooks() method

Provides the implementation for calling hooks in ProcessWire

Unlike __call, this method won't trigger an Exception if the hook and method don't exist. Instead it returns a result array containing information about the call.

Usage

// basic usage
$array = $hooks->runHooks(Wire $object, string $method, array $arguments);

// usage with all arguments
$array = $hooks->runHooks(Wire $object, string $method, array $arguments, $type = 'method');

Arguments

NameType(s)Description
objectWire
methodstring

Method or property to run hooks for.

argumentsarray

Arguments passed to the method and hook.

type (optional)string, array

May be any one of the following:

  • method: for hooked methods (default)
  • property: for hooked properties
  • before: only run before hooks and do nothing else
  • after: only run after hooks and do nothing else
  • Or array[] of hooks (from getHooks method) to run (does not call hooked method)

Return value

array

Returns an array with the following information: [return] => The value returned from the hook or NULL if no value returned or hook didn't exist. [numHooksRun] => The number of hooks that were actually run. [methodExists] => Did the hook method exist as a real method in the class? (i.e. with 3 underscores ___method). [replace] => Set by the hook at runtime if it wants to prevent execution of the original hooked method.


$hooks methods and properties

API reference based on ProcessWire core version 3.0.248

Latest news

  • ProcessWire Weekly #581
    The 581st issue of ProcessWire Weekly brings in all the latest news from the ProcessWire community. Modules, sites, and more. Read on!
    Weekly.pw / 28 June 2025
  • New ProcessWire admin redesign
    When you upgrade to ProcessWire 3.0.248 or newer (currently the dev branch), you’ll immediately notice something new and beautiful…
    Blog / 9 May 2025
  • Subscribe to weekly ProcessWire news

“We chose ProcessWire because of its excellent architecture, modular extensibility and the internal API. The CMS offers the necessary flexibility and performance for such a complex website like superbude.de. ProcessWire offers options that are only available for larger systems, such as Drupal, and allows a much slimmer development process.” —xport communication GmbH