I have created a widget that have to run some code using the wp_footer hook as well. But if you extend the WP_Widget, the wp_footer runs twice! Has someone already past for the same issue?
Here is an example:
/*
Plugin Name: Test
Description: Test Plugin by Romulo De Lazzari
Version: 1.0
Author: Romulo De Lazzari
*/
new Test();
class Test extends WP_Widget{
public function __construct(){
parent::__construct('test-widget', 'Test Widget');
add_action('widgets_init', array($this, 'register_my_widget'));
add_action('wp_footer', array($this, 'do_something'));
}
public function register_my_widget(){
return register_widget("Test");
}
public function do_something(){
echo "<p>Hello! This is a test!</p>";
}
public function widget($args, $instance) {
}
public function form($instance){
}
public function update($new_instance, $old_instance){
}
}
The method do_something() is running twice here, if I take off the "Widget part" it runs well. Could someone help me?
Thanks in advance, Romulo