Opened 13 months ago

Last modified 12 months ago

#20542 new enhancement

Extend register_widget to allow passing params as second argument

Reported by: codearachnid Owned by: codearachnid
Priority: normal Milestone: Future Release
Component: Widgets Version: 3.4
Severity: normal Keywords: needs-patch
Cc: kpayne@…

Description

I ran into an issue recently where I needed to make multiple calls of register_widget('my_custom_class'); on the same class and have multiple unique widgets registered.

The problem I ran into is that every time the same class is called it will overwrite the last instance of the same class during the widget constructor request parent::__construct('unique_id', 'widget title'); This does not allow for reuse of the same class to instantiate multiple widgets. I found that if I were to extend the register method in WP_Widget_Factory to pass through arguments into the extended WP_Widget constructor that I can reuse the same class for multiple widget registations. I am working out the logic to implement this directly into /wp-includes/widgets.php for future functionality improvement.

Change History (3)

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to Future Release
  • Cc kpayne@… added

Can you explain more about the use case?

The benefit is the ability to reuse the same class logic to instantiate multiple widgets (not talking about the current multiple use instances). A sample use case is in the http://wordpress.org/extend/plugins/widget-builder/ plugin where the same widget builder class is called multiple times with different widget parameters and by extending the widget factory was able to accomplish what I am proposing to patch in core.

Note: See TracTickets for help on using tickets.