Override plugin widget class
-
One plugin we use has some widget declared as
if ( ! class_exists( 'thewidget' ) ) { class thewidget extends WP_Widget {...} } add_action( 'widgets_init', create_function( '', 'register_widget( "thewidget" );' ) );
We need to override this widget code (not creating an alternate version, but actually replacing it with the same name but different code) but we don’t know how to plug our own version of thewidget in either our theme’s functions.php or our, preferably, a custom plugin.
If we declare our own thewidget class, it throws a ‘Cannot redeclared class…’ error; we understand this is because at this point the plugin function has already run and the class already exists.We’ve tried wrapping our class declaration in a function and hooking this at various points to get our class declared before the plugin’s, but to no effect, it either is too late or gets ignored:
function thewidget_override() { class thewidget extends WP_Widget {...} } add_action('muplugins_loaded', 'thewidget_override', 10);
(this is ignored)
So, if our approach is correct, where should we hook our class definition?
Else, what would be the correct way to override this code?Thanks a lot for your help.
- The topic ‘Override plugin widget class’ is closed to new replies.