Opened 13 years ago
Closed 5 years ago
#20542 closed enhancement (invalid)
Extend register_widget to allow passing params as second argument
Reported by: | codearachnid | Owned by: | codearachnid |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.4 |
Component: | Widgets | Keywords: | |
Focuses: | Cc: |
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.
Attachments (2)
Change History (12)
#1
@
13 years ago
- Keywords needs-patch added
- Milestone changed from Awaiting Review to Future Release
#3
@
12 years ago
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.
#6
follow-up:
↓ 7
@
11 years ago
Re: 20542.diff, I've seen cases where a plugin expects the array keys of $wp_widget_factory->widgets
to be the actual class names. That being said, they could (and perhaps should) be doing get_class()
on the array values, but they'd need to be updated to do so.
#7
in reply to:
↑ 6
@
11 years ago
Replying to westonruter:
Re: 20542.diff, I've seen cases where a plugin expects the array keys of
$wp_widget_factory->widgets
to be the actual class names. That being said, they could (and perhaps should) be doingget_class()
on the array values, but they'd need to be updated to do so.
Unless $args is non-empty, the key is the name of the class, so this would still work for you average widget -Only time hash is added is if $args has a value of some sort
#9
@
8 years ago
- Keywords close reporter-feedback added
@codearachnid I believe this ticket is now invalid since you can pass in pre-instantiated widgets when calling register_widget()
. See #28216. Please confirm.
#10
@
5 years ago
- Keywords has-patch needs-refresh close reporter-feedback removed
- Milestone Future Release deleted
- Resolution set to invalid
- Status changed from new to closed
Hi there,
I'm going to close this ticket per Weston's comment above (poster 3years ago, not reporter feedback).
Feel free to reopen it if needed.
Cheers,
Jb
Can you explain more about the use case?