Hooks in WordPress

Continuing the series of articles, for writing plugins WordPress I want to show some more useful code snippets.
Begin, as in previous articles. Create a file in the plugins folder and name it mytestplugin.php. Add the code to the generated file :

Now we have inserted the minimum, which is needed to install and activate the plugin, then often after development it is necessary to think about a license for it. Many developers use the license GPL or similar to it. To describe the license, add the following lines to the plugin file:

 

Moving on to plugin programming and basic important concepts.

Consider the basic concept of plugin development, which works on the basis of hooks or they are also called hooks (hook). How hooks work is very simple., each of the elementary functions WordPress before returning some result of your work or performing some important action (database query, data processing, output on display), tries to use additional lines of code intended for it in plugin files.

 

An example of using hooks in WordPress

Before as WordPress adds a title to a post, first he checks, does any plugin have registered functions for a hook called "the_title».

 

An example of using such a hook in a WordPress plugin

The title text before the output will be passed through a special function my_own_function_for_title() specified in the plugin file or in the file function.php, after which the result will be displayed.

 

An example of how the my_own_function_for_title function works()

If you need to add some information to the header or change it, the filter hook for "the_title” and it contains the function, which makes all the necessary changes to the headers.

All hooks in WordPress are divided into two categories - Filters and Actions. (filters and actions respectively).

First clues filters (filters) really meant forfiltering» (changes) any data, before they are rendered on the page or added to the database for storage. This is spam filtering., errors or just erroneous input in forms.

Second (actions, actions) designed to replace various kernel actions with your own actions (for example, database query string changes), in programming, such a change in the actions of the basic functionality is also called overload.

In WordPress have your own API for working with plugins and a number of ready-made hooks. You can read about all standard hooks in the official documentation WordPress Plugin API true in english. And if you find a place, where such a hook is simply necessary, then you can offer it and how to do it is written here.

The information is taken from the official documentation and slightly processed by me. ). Good luck developing your own WordPress plugins. Stay tuned for new articles.


Купить хостинг WordPress
/* WordPress tutor
Online tutoring services. List of courses I teach
  • Basic web design course;
  • Site layout;
  • General course on CMS WordPress and continuation of the course on template development;
  • Website development in PHP.
Read more on the page WordPress tutor
*/

Hooks in WordPress

Continuing the series of articles, After writing WordPress plugins, I want to show you a few more useful pieces of code.
Let's start, as in previous articles. Create a file in the plugins folder and name it mytestplugin.php. We add the code to the created file:
(more…)

Nikolaenko Maxim

Director of web studies ProGrafika. I am developing, website design and promotion. Always glad to new blog readers and good clients.


You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Templates for WordPress
The best hosting in Ukraine
Stable hosting for Drupal