vendredi 8 janvier 2016

How to define multiple widget classes within a single plugin

I'm trying to add two widgets to a Wordpress plugin I'm developing. What is the correct way to call multiple classes?

I have a plugin folder containing my-plugin.php:

class WidgetA extends WP_Widget {
  function widget_a() {
    ...
  }
  function form($instance) {
    ...
  }
  function update($new_instance, $old_instance) {
    ...
  }
  function widget($args, $instance) {
    ...
  } 
}
add_action('widgets_init', create_function('', 'return register_widget("WidgetA");'));

class WidgetB extends WP_Widget {
  function widget_b() {
    ...
  }
  function form($instance) {
    ...
  }
  function update($new_instance, $old_instance) {
    ...
  }
  function widget($args, $instance) {
    ...
  } 
}
add_action('widgets_init', create_function('', 'return register_widget("WidgetB");'));

If I delete WidgetA then WidgetB functions correctly, and vice versa. But nothing is displayed if I include both classes.

What is the correct way to define two widgets/ classes in a plugin?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire