WordPress has a powerful plugin API, providing us with a lot of filters and actions throughout. They allow affecting the functionality of WordPress core without actually changing it.

[biginfobox textcolor=”#ffffff” title=”Have you tried Editr WP plugin yet?” href=”https://wp-doin.com/editrwp-demo/” button_title=”Editr WP” target=”_blank”]It lets you create your own interactive embeds! [/biginfobox]

What if we wanted to develop something similar in our plugin?

Say we are releasing a GNU GPL plugin, that we constantly update. In case someone altered the behavior of it his changes would easily be overwritten. WP Plugin API saves the day here. We’ll make usage of it and create our own Plugin API for the plugin created.

Let us assume we’re creating a simple plugin which collects user input from a form and saves the data in the database. Say extended user profiles. Storing the values in a custom database table, this could be:

– a list of locations one user has been to

– each location could be stored in one table and user to location relation could be stored in the other

What if we wanted to save the data somewhere else? Send it to a MailChimp campaign (for whatever reason)? Here’s where do_action function comes in handy.

The code above is fairly straightforward – we’re adding the do_action call wherever in our code. And then we’re assigning a hook  to it. The plugin will then execute our hooked code during the process.

This gives the people who browse our code an ability to alter the plugin’s functionality without touching it’s core. That kind of API is part of the biggest plugins out there, for i.a. WooCommerce or Gravity Forms.




WP doin dev & security
WP doin dev & security

Oh hi there 👋
It’s nice to meet you.

Sign up to receive WordPress tips in your inbox, every month.

I don’t spam! Read my privacy policy for more info.