Plugin can hook on events 'before' and 'after' other plugins #1169

Closed
mattab opened this Issue Feb 22, 2010 · 2 comments

Comments

Projects
None yet
1 participant
@mattab
Member

mattab commented Feb 22, 2010

See use case of plugin #1168

Hooks should be executed in a certain order, so that some plugins modify the data and other can access the recorded data. In some cases, it is not possible to add new hooks as a given data point (eg. the user IP) can be modified by several hooks.

The hook registration should maybe be a function call rather than the current array format. This function would have a priority parameter that would define, from 1 to 100, the priority at which the function should be called. For example, plugins that modify the data and needs to access its raw state, they would set priority=1. Plugins that record the data would set 100. Hooks that modify the value after basic filters would set priority=50.

The range could maybe be from 1 to 10. I am not sure of any code standard regarding this pattern? Also, this is similar to filter priority in wordpress hooks.

@mattab

This comment has been minimized.

Show comment
Hide comment
@mattab

mattab Nov 24, 2011

Member

(In [5474]) Refs #1169

  • A good example of why we need event priority/ordering so that a plugin can execute first or last or anytime, for a given hook.
    Imagegraph was missing a few plugin images because it was executed before the Goals plugin added additional ecommerce reports.
  • Adding debug define to force scheduled tasks to run
Member

mattab commented Nov 24, 2011

(In [5474]) Refs #1169

  • A good example of why we need event priority/ordering so that a plugin can execute first or last or anytime, for a given hook.
    Imagegraph was missing a few plugin images because it was executed before the Goals plugin added additional ecommerce reports.
  • Adding debug define to force scheduled tasks to run
@mattab

This comment has been minimized.

Show comment
Hide comment
@mattab

mattab Apr 6, 2014

Member

We have implemented a basic 3 level hook priority mechanism which lets you run your plugin's hook before or after other plugins.

This is documented in the developer guide http://developer.piwik.org/guides/piwiks-extensibility-points#handling-events

Callback Execution Order

Callbacks can be made to run before or after others. This is done when associating callbacks with events.

To make a callback execute before all others, associate the event with an array like the following:

public function getListHooksRegistered()
{
return array(
'API.getSegmentsMetadata' => array(
'before' => true,
'function' => 'getSegmentsMetadata'
)
);
}

To make a callback execute after other callbacks, associate the event with an array like the following:

public function getListHooksRegistered()
{
return array(
'API.getSegmentsMetadata' => array(
'after' => true,
'function' => 'getSegmentsMetadata'
)
);
}

Member

mattab commented Apr 6, 2014

We have implemented a basic 3 level hook priority mechanism which lets you run your plugin's hook before or after other plugins.

This is documented in the developer guide http://developer.piwik.org/guides/piwiks-extensibility-points#handling-events

Callback Execution Order

Callbacks can be made to run before or after others. This is done when associating callbacks with events.

To make a callback execute before all others, associate the event with an array like the following:

public function getListHooksRegistered()
{
return array(
'API.getSegmentsMetadata' => array(
'before' => true,
'function' => 'getSegmentsMetadata'
)
);
}

To make a callback execute after other callbacks, associate the event with an array like the following:

public function getListHooksRegistered()
{
return array(
'API.getSegmentsMetadata' => array(
'after' => true,
'function' => 'getSegmentsMetadata'
)
);
}

@mattab mattab added this to the Future releases milestone Jul 8, 2014

@mattab mattab added T: Task labels Jul 8, 2014

This issue was closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment