Using Actions and Filters in the GavernWP WordPress Framework
Actions Hooks and Filters Hooks
WordPress hooks are, essentially, triggers of sorts that allow users to, with short snippets of code, modify areas a WordPress theme or plugin, or add their own code to various parts of CMS. With action hooks and filters plugin or theme creator, and even relatively low programming blogger can easily and safely change almost any functionality without touching/modifying the original files the source code of WordPress. Because you leave the core files untouched, you can painlessly upgrade your blog/website with each new version of CMS. Hooks may seem a little advanced, but with a little practice, hooks are quite efficient at modifying a WP theme.
The two types of WordPress hooks are:
Action is a PHP function, which do not return any results, but is executed at specific points throughout the WordPress Core. Events during the loading of the theme when you can latch in a specific function. Developers, like we, are creating a custom Action using the Action API to add or remove code from an existing Action by specifying any existing Hook. This process is called “hooking“.
WordPress invokes actions by using the function:
do_action ('action-name', parameters… )
A list with all available hooks and actions you will find here…
Filters as the name suggests – filter the data. Filter hooks work on some WP content. They receive some data in the input parameter (always before some content will be used), they can be converted or downloaded from somewhere alternatives, and finally they have given to the output of the same or different data, but so that they can be used by a programmer in exactly the same order in which they occurred be used in the original data. Generally filters pass the content as arguments and expect the return value to be the filtered content. Allows you to modify data while it passes to the theme or to the browser screen.
WordPress invokes filters by using the function:
apply_filter (‘filters-name', parameters… )
A list of available Filters for GavernWP you can find here
This article was first published