$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.236

Latest news

  • ProcessWire Weekly #549
    In the 549th issue of ProcessWire Weekly we’re going to check out the latest core updates, highlight one older yet still very relevant third party module, and more. Read on!
    Weekly.pw / 17 November 2024
  • Custom Fields Module
    This week we look at a new ProFields module named Custom Fields. This module provides a way to rapidly build out ProcessWire fields that contain any number of subfields/properties within them.
    Blog / 30 August 2024
  • Subscribe to weekly ProcessWire news

“I am currently managing a ProcessWire site with 2 million+ pages. It’s admirably fast, and much, much faster than any other CMS we tested.” —Nickie, Web developer