Is it possible to replace a function within a PHP class? Is it possible to replace a function within a PHP class? wordpress wordpress

Is it possible to replace a function within a PHP class?


It sounds like what you want to do is extend the class, and override that particular function.

Class Your_Tribe_Image_Widget extends Tribe_Image_Widget{   function example_function() {     // Call the base class functionality     // If necessary...     parent::example_function();     // Do something else useful   }}


You could probably have an include_once to the target plugin at the top of your file and then extend the class of the target plugin instead of the WP_Widget class:

include_once otherPlugin.phpclass My_Awesome_Plugin_Overloaded extends Someone_Elses_Awesome_Plugin{    function example_function(){         return 'woot';    }}


As long as the method in the existing class hasn't been marked as final, you can just subclass and override it

class My_Tribe_Image_Widget extends Tribe_Image_Widget {    //override this method    function example_function(){        // do something useful    }}