Hooks API

WordPoints 2.1.0 introduced a completely new Hooks API that underlies the events and reactions on the Points Types administration screen. In a nutshell, the Hooks API is a highly glorified version of the WordPress action API. The action API can be used by developers to say “when x happens, do y,” while the WordPoints Hooks API can be used to allow the end-user to compose what responses should be taken in regard to which events.

Initially based on the old Points Hooks, this new API is much more granular and also more flexible. This allows for new features to be introduced across events with a single class, rather than it having to be implemented for each event separately, as with the old points hooks. With the new API, each class is fine-tuned to a much more restricted purpose, rather than encompassing the entire event/reaction feature from the point of hooking into a WordPress action to when the points are awarded. This granularity makes each individual piece of the API much simpler and more easily digestible.

However, this granularity does come with a trade-off, and that is that the API as a whole is more complex, because it has more different parts, though each of those pieces is smaller. The key to understanding the API is to digest it one piece at a time. Soon, you’ll be familiar with each of the different types of building blocks that make up the API, and adding your own new ones will be simple.

You probably don’t need to understand the whole API all at once, depending on what you are currently trying to accomplish with it. Here is a list of the different parts of the API to help you figure out which part you should focus on right now:

  • If you want to add a new event to the Points Types screen, you should check out Actions and Events.
  • If you want to add new settings for reactions, you need to have a look at Extensions.
  • If you are hoping to do something other than award points with reactions, you need to look at Reactors.
  • If you want to add a new type of condition, you should have a look at Conditions.
  • If you want to add new possibilities for who will be awarded points to existing events, see the Args docs.
  • If you want to add new attributes to existing entities so that you can set conditions based on those attributes, see the Entities API.