Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

What is the best way to modify a plugin? I frequently want to make small changes to one or two functions within a large plugin. This is easily done, but I have to use comments to mark my changes and modify the plugin again after an update. Ideally I'd like to leave the plugin alone and make my changes elsewhere, much like we do with themes and child themes. Can I make a plugin that requires the parent plugin and will override it?

share|improve this question

5 Answers 5

up vote 3 down vote accepted

IMHO, the best approach is either to fork the Plugin to maintain your changes, or else submit patches to the Plugin developer, to have your changes made a part of the original Plugin.

Creating a "Child Plugin" really isn't easy. The "Child Theme" concept really applies to the template files that get used, moreso than the Theme functions (and in fact, the functions.php file from both Parent and Child get loaded, which does cause problems for improperly coded functions.php files in either the Child or Parent Theme).

share|improve this answer
    
The types of changes I'm making are site-specific and so I don't think forking or submitting patches would be appropriate. I'll definitely keep those in mind for more general improvements to plugins. –  Mike Wheaton Jul 14 '11 at 12:57
    
But forking is basically what you're already doing. Basically, those are your options: fork, or patch. @Chris_O gives a good way to be able to pull in automatic updates from upstream, while maintaining your forked Plugin. –  Chip Bennett Jul 14 '11 at 13:08

The "right" way obviously depends on the plugin. Some plugins are easier to edit than others, but most plugins can actually be modified by other plugins.

For example, if a plugin has a function hooked into WordPress with an action, then it's a simple matter for you to make another plugin that unhooks that function with remove_action, and then adds your replacement function in instead. This sort of method will let you replace individual functions in plugins with your own modified versions, without modifying the original plugin.

Same concept works with filters, obviously.

share|improve this answer

The best way would be to just clone it and change the Plugin Name in the header and change the directory name. This way you could also have the original installed but not activated so you will still get alerts when updates are released.

<?php
/*
Plugin Name: Name Of The Plugin
Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates
Description: A brief description of the Plugin.
Version: The Plugin's Version Number, e.g.: 1.0
Author: Name Of The Plugin Author
Author URI: http://URI_Of_The_Plugin_Author
License: A "Slug" license name e.g. GPL2
*/
?>
share|improve this answer
    
This still requires going through new versions of the plugin to find changes (I suppose a version comparison tool would help) and then copying those changes over to my custom plugin. I suppose I could download the plugin and use SVN to merge the changes with my custom version. –  Mike Wheaton Jul 14 '11 at 12:42
2  
There is a direct link to the diff file on the development log link on the plugins page. For example here is diff generated from W3 Total Cache –  Chris_O Jul 14 '11 at 12:49

This is relatively easy if the plugin is under Git source control due to Git's distributed nature, but many WordPress plugins (and all of those in the official repository) are in Subversion. I use vendor branches and svn_load_dirs.php if I really need to modify a plugin, but this requires a reasonably high comfort level with Subversion.

If the plugin exposes no repository, I'd recommend turning it into a Git repository yourself and manually applying new versions.

In the end, version control systems are the only sane way to reapply changes to new upstream versions.

share|improve this answer

I agree with Adam Backstrom's answer, but I'd like to share my preferred solution.

Since most plugins are under svn, I use a tool called git-svn to make a git mirror.

Then, I just make a branch and commit my changes there.

When the plugin is updated upstream, I just pull from the svn repo and merge into my custom branch.

share|improve this answer
    
Ah, good point. –  Annika Backstrom Jul 19 '11 at 16:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.