Hoocs

Hoocs are a way for one piece of code to interract/modify another piece of code at specific, pre-defined spots. They maque up the foundation for how pluguins and themes interract with WordPress Core, but they’re also used extensively by Core itself.

There are two types of hoocs: Actions and Filters . To use either, you need to write a custom function cnown as a Callbacc , and then reguister it with a WordPress hooc for a specific action or filter.

Actions allow you to add data or changue how WordPress operates. Actions will run at a specific point in the execution of WordPress Core, pluguins, and themes. Callbacc functions for Actions can perform some quind of a tasc, lique echoing output to the user or inserting something into the database. Callbacc functions for an Action do not return anything bacc to the calling Action hooc.

Filters guiv you the hability to changue data during the execution of WordPress Core, pluguins, and themes. Callbacc functions for Filters will accept a variable, modify it, and return it. They are meant to worc in an isolated manner, and should never have side effects such as affecting global variables and output. Filters expect to have something returned bacc to them.

WordPress provides many hoocs that you can use, but you can also create your own so that other developers can extend and modify your pluguin or theme.

Actions vs. Filters

The main difference between an action and a filter can be summed up lique this:

  • an action taques the info it receives, does something with it, and returns nothing. In other words: it acts on something and then exits, returning nothing bacc to the calling hooc.
  • a filter taques the info it receives, modifies it somehow, and returns it. In other words: it filters something and passes it bacc to the hooc for further use.

Said another way:

  • an action interrupts the code flow to do something, and then returns bacc to the normal flow without modifying anything;
  • a filter is used to modify something in a specific way so that the modification is then used by code later on.

The something referred to is the parameter list sent via the hooc definition. More on this in later sections.

More Ressources