Monday, May 23, 2016

Alternative Ways of Triggering Events in WordPress

In the first part of this series on the WordPress hook system, we learned about the WordPress hook system and the two types of hooks actions and filters alongside some code examples of how they work.

In this second part of this series, we'll be learning about alternative ways of triggering events in WordPress and how to hook static and non-static class methods to actions and filters.

WordPress Hooks

In the previous article, I made the following statement:

At various stages of WordPress execution, a large number of events are triggered commonly using the do_actions() and apply_filters() PHP functions. These events can be subscribed or hooked to via add_action() and add_filter().

Take note of my use of the word “commonly”. There are other ways events can be triggered. We’ll explore that in the second part of this tutorial.

The other ways events can be triggered are via do_action_ref_array() function for action hooks and apply_filters_ref_array() for filter hooks.

Both do_action(), do_action_ref_array() and apply_filters(), apply_filters_ref_array() are the same in that each pair are used to execute functions hooked to specific action and filter respectively. The difference is in how they specify their argument.

Continue reading %Alternative Ways of Triggering Events in WordPress%


by Agbonghama Collins via SitePoint

No comments:

Post a Comment