WordPress.org

Ready to get started?Download WordPress

Forums

How to develop plugin addons or extensions (2 posts)

  1. Jose Llanos
    Member
    Posted 9 months ago #

    I have developed a plugin, now I wish to extend it's functionality by creating an add-on, but I don't know how to...

    Can anyone please give me an example, I hear people saying use hooks and filters and actions but I am still on the learning phase, any advice is greatly appreciated.

    Thanks

  2. bcworkz
    Member
    Posted 9 months ago #

    It depends on how tightly or independent the extension integrates with the base. It could be a separate plugin that checks for the base on activation, or it could be an extra file in the same plugin folder that's conditionally included by the base file. Or something in between. There's no "official" structure. Do what makes sense for your situation, within the constraints of PHP and WordPress.

    Definitely get a handle on action and filter hooks. It is the primary way our code interacts with the WordPress core. You can start with going through the Plugin API. There's hundreds of places in WordPress core you can hook into, and good themes and plugins have their own hooks as well.

    A hook is initiated by core code. It basically is saying "Hey! I've got this bit of data (or something just happened or is about to happen), anyone want to do something about it before I continue? This is your opportunity for your code to say "Yes, thank you! Let me see the data." You then can do whatever, then finally say "OK, I've done my thing, here's the latest data version, carry on!"

    That's the idea, but the dialog is technically flawed. What really happens is you add your function name, which you wish to be called at a certain point, to a list maintained by WordPress. When that certain point is reached, all the functions in the list associated with that certain point are called in turn before WordPress continues on with the normal process. Bear in mind that other plugins, themes, or even core code can be hooked into the same filter or action. It's important to play well with others and not do anything that prevents other elements from using the same resource.

Reply

You must log in to post.

About this Topic