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.

This is what I am trying to do:

Lets say I have a parent plugin, Plugin X, and a child plugin (an extension, whose purpose is to enhance X) Y.

There is a function in plugin X that I wish to add code to, from plugin Y. In other words, I am writing plugin Y.

Using WordPress, I know there is a way to override Plugin X's like such:

  • remove action plugin X's function
  • add action Y's function
  • function thatIgotfromXmodified { }

But is there any other way? I don't want to have to modify my plugin everytime Plugin X's author changes the functions code, so that users of my plugin get all the benefits of X's new version.

It looks like if Plugin X's author adds something like an action filter, I can hook into that somehow and add code there? Not sure if it matters or not but the function I am editing is backend code (ie no output to user).

Suggestions? Ideas?

share|improve this question
    
Is the function in the plugin pluggable? Does it have a function_exists conditional around it? –  Brian Fegter Aug 25 '12 at 1:55
    
@BrianFegter No. I don't want to plug the whole function either, since its large, and I just need to add a couple lines of code. Is there something that Plugin X could add to their function that would allow code to be added at a particular point in the function by a extension? –  Chris Aug 25 '12 at 2:00
    
If you're looking to DO something, they would need to add an action. If you're looking to CHANGE data, they would need to add a filter. –  Brian Fegter Aug 25 '12 at 2:36
add comment

1 Answer

up vote 0 down vote accepted

This would depend on the way the plugin was structured. If it is just procedural then your pretty much out of luck. If it is written within a class you can extend or create a new instance of it and override methods. As an example in my media tools plugin I use a portion of Regenerate Thumbnails by calling

 if ( class_exists( 'Regenerate_Thumbnails' ) {
        $regen = new Regenerate_Thumbnails();

        $regen->class_method();

        $regen->another_method();  
    }
}

To override a method:

 if ( class_exists( 'Regenerate_Thumbnails' ) {

   My_Class extends Regenerate_Thumbnails {

         function __construct() {
            parent::__construct();
         }

     parent_function_to_override() {
        //do stuff
        }
}
}

$barorfoo = new My_Class();
$barorfoo->parent_function_to_override();

Again this totally depends on the way the parent plugin is constructed.

share|improve this answer
add comment

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.