How To Extend A WordPress Plugin Without Losing Your Changes

While there is not an official way to create child plugins, the topic has been discussed in the WordPress community over the past few years. I caught up with Ian Dunn who submitted the idea three years ago to see if it still has merit.

From an architectural standpoint, creating a child plugin isn’t really practical. It works for themes because they have a very specific, defined set of behaviors, but plugins are completely different.

Ian recently published a post highlighting the right way to customize plugins. The first suggestion he offered is to get in touch with the plugin author and let them know what changes you’d like to see.

If that doesn’t work, the next step is to extend the plugin without modifying its core. The easiest way to accomplish this is to create a functionality plugin that will run alongside it. You can take things one step further by using Plugin Dependencies by Scribu to control when the functionality plugin is activated. Plugin Dependencies allow you to specify if a parent plugin is deactivated, it will also deactivate the plugin dependent upon it.

What Plugin Dependencies Does
What Plugin Dependencies Does

Hooks are a way for one piece of code to interact with and modify another piece of code. If the plugin you want to modify offers hooks, you can use them to extend the plugins functionality. According to Ian, if the developer added hooks, you just need to write a separate plugin that runs alongside the plugin you’re customizing and register callbacks for the custom hooks that the plugin provides.

Code Snippets In Action
Code Snippets In Action

Code Snippets by Shea Bunge is an easy way to manage code snippets to extend plugins. Code Snippets is cool because it adds a GUI to create and manage code snippets. The snippets are executed as if they are located within the themes functions.php file. This added benefit alleviates the possibility of functions.php filling up with hundreds of lines of extra code. Using Code Snippets to extend plugins instead of functions.php prevents the changes from being lost when a user switches themes.

In Summary

The mantra of never editing core WordPress files should be observed for plugins and themes. The goal is to extend or remove functionality without having those changes disappear after an upgrade. It’s frowned upon to place code snippets within a theme’s functions.php file. Instead, use a functionality plugin or use the Code Snippets plugin to manage them. Plugin authors are encouraged to add hooks where they’ll make the most impact. If you’re unsure on how to add custom hooks to your plugin, there is a great explanation available within the plugin developer handbook.

6

6 responses to “How To Extend A WordPress Plugin Without Losing Your Changes”

  1. I think that to some extent there’s a similar problem for themes too. Child themes are a genius thought but they are safe only if your customization is limited to the CSS. If you modify a core file you will lose all the updates that the theme’s author will make to this file. Eventually, you could end up breaking your theme if the modifications are important or necessary to keep the theme compatible with the last WordPress version.

Newsletter

Subscribe Via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.