Package: Plugin\Broker

class Omeka_Plugin_Broker

Plugin Broker for Omeka.

For example, $broker->callHook(‘add_action_contexts’, array(‘controller’ => $controller)) would call the ‘add_action_contexts’ on all plugins, and it would provide the controller object as the first argument to all implementations of that hook.

property _callbacks

protected array

Array of hooks that have been implemented for plugins.

property _filters

protected array

Stores all defined filters.

Storage in array where $_filters[‘filterName’][‘priority’][‘plugin’] = $hook;

property _current

protected string

The directory name of the current plugin (used for calling hooks)

addHook($hook, $callback, $plugin = null)

Add a hook implementation for a plugin.

  • $hook (string) – Name of the hook being implemented.
  • $callback (string) – PHP callback for the hook implementation.
  • $plugin (string|null) – Optional name of the plugin for which to add the hook. If omitted, the current plugin is used.
getHook($pluginDirName, $hook)

Get the hook implementation for a plugin.

  • $pluginDirName (string) – Name of the plugin to get the implementation from.
  • $hook (string) – Name of the hook to get the implementation for.



Set the currently-focused plugin by directory name.

The plugin helper functions do not have any way of determining what plugin to is currently in focus. These get/setCurrentPluginDirName methods allow the broker to know how to delegate to specific plugins if necessary.

  • $pluginDirName (string) – Plugin to set as current.

Get the directory name of the currently-focused plugin.

callHook($name, $args = array(), $plugin = null)

Call a hook by name.

Hooks can either be called globally or for a specific plugin only.

  • $name (string) – The name of the hook.
  • $args (array) – Arguments to be passed to the hook implementations.
  • $plugin (Plugin|string) – Name of the plugin that will invoke the hook.
addFilter($name, $callback, $priority = 10)

Add a filter implementation.

  • $name (string|array) – Name of filter being implemented.
  • $callback (callback) – PHP callback for filter implementation.
  • $priority

Retrieve the namespace to use for the filter to be added.

Returns:string Name of the current plugin (if applicable). Otherwise, a magic constant that denotes globally applied filters.

Retrieve the key used for indexing the filter. The filter name should be either a string or an array of strings. If the filter name is an object, that might cause fiery death when using the serialized value for an array key.

  • $name (string|array) – Filter name.

string Key for filter indexing.


Return all the filters for a specific hook in the correct order of execution.

  • $hookName (string|array) – Filter name.

array Indexed array of filter callbacks.

clearFilters($name = null)

Clear all implementations for a filter (or all filters).

  • $name (string|null) – The name of the filter to clear. If null or omitted, all filters will be cleared.
applyFilters($name, $value, $args = array())

Run an arbitrary value through a set of filters.

  • $name (mixed) – The filter name.
  • $value (mixed) – The value to filter.
  • $args (array) – Additional arguments to pass to filter implementations.

mixed Result of applying filters to $value.


Register the plugin broker so that plugin writers can use global functions like add_plugin_hook() to interact with the plugin API.