[wp-trac] [WordPress Trac] #28216: Allow to register pre-instantiated widgets

WordPress Trac noreply at wordpress.org
Thu May 14 09:04:13 UTC 2015

#28216: Allow to register pre-instantiated widgets
 Reporter:  Denis-de-Bernardy  |       Owner:
     Type:  defect (bug)       |      Status:  new
 Priority:  normal             |   Milestone:  Awaiting Review
Component:  Widgets            |     Version:  3.9.1
 Severity:  normal             |  Resolution:
 Keywords:  reporter-feedback  |     Focuses:

Comment (by Denis-de-Bernardy):

 Sure. If you want your widgets to use a dependency injection, they need to
 be instantiated like so:

 $my_widget = new MyWidget($dep1, $dep2);
 wp_register_widget($my_widget); // or perhaps more appropriately,

 ... but as things stand, WP expects a call more like:

 wp_register_widget('MyWidget'); // and now $dep1 and $dep2 dependencies
 are missing.

 To work around the issue, you currently need to edit the widget factory's
 private variables.

Ticket URL: <https://core.trac.wordpress.org/ticket/28216#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform

More information about the wp-trac mailing list