# How Can I Add Code To A Preexisting Function Without Editing it

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?

-
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

 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();