I'm having a weird behavior and i would like to know... why. I did a widget plugin for WordPress to allow setting various stuff (like width, position, color and so on) and I'm trying to use it on frontend, but i'm stuck on the most basic thing.
I'm having this code that it works ok:
add_filter( 'widget_display_callback', 'capture_widget', 100, 3 );
function capture_widget( $instance, $widget_class, $args ) {
$widget_class->widget( $args, $instance );
echo $widget_class->widget_options['classname'];
return false;
}
The thing is that i want to move everything into a class. So i did this:
class MyWidgets {
function __construct() {
add_filter( 'widget_display_callback ', array( $this, 'widget_display' ), 100, 3 );
}
public function widget_display( $instance, $widget_class, $args ){
$widget_class->widget( $args, $instance );
echo $widget_class->widget_options['classname'];
return false;
} // widget_display
}
new MyWidgets();
And... it stopped working. Everything is placed in exactly same file, yet only first version it works. I have no error whatsoever, it just doesn't do anything. I tried to move the add_filter( 'widget_display_callback', 'capture_widget', 100, 3 );
part inside of __construct
method (but i let it to call the outside-of-the-class function) and it keeps working, it just doesn't play nice when it comes to call a self-contained method.
Any good reason? Did i miss something?
Thanks!
'widget_display_callback '
→ remove the space between k and single quote