Hi,
Is it possible to extend widgets in an object oriented manner e.g.
if ( ! class_exists( 'SiteOrigin_Widget_GoogleMap_Widget' ) ) { require_once WP_PLUGIN_DIR . '/so-widgets-bundle/widgets/google-map/google-map.php'; } class My_Map_Widget extends SiteOrigin_Widget_GoogleMap_Widget {
I tried the above but, after some odd behaviour in the page builder, instead settled on using the various filters available to extend existing widgets. This is probably the advised approach as I’d prefer to keep most of what the map widget has to offer however I’d prefer to avoid widgets in the admin starting with ‘SiteOrigin …’. This is coming purely from a UX point of view as it gives the user one more thing to think about.
If extending a widget class is not advisable for one reason or another then the option to rename built-in widgets would be a useful addition.
Hope you can help.
Hi, thanks for posting your question. If you have a moment, perhaps take a quick look at https://siteorigin.com/docs/widgets-bundle/getting-started/extending-existing-widgets/ and see if that helps you get started.
Perhaps helpful https://siteorigin.com/docs/widgets-bundle/advanced-concepts/filters/active-widgets/.
The name issue aside, there might be instances were filtering is easier https://siteorigin.com/docs/widgets-bundle/advanced-concepts/hooks-and-filters/#heading-widget-modifications.
Hope that helps to get started.
Hi Andrew,
Thanks for coming back to me.
That first link is what I was using for the filter-based approach. Like I say, that’s all working fine except for the name of the widget.
I feel like I’ve read somewhere that extending a widget class as I have above is not advised. When I did, both the original map widget and my customised one were available to activate and they seemed to conflict in the page builder.
Assuming I stick with the filters route, is there a way to change the name of the widget in the page builder. If not, could a filter be added to allow this?
Thanks again.
Hi, thanks. It’s a lower maintenance, lighter weight option to extend with filters if possible. If you extend with your own widget you can see the second link above to remove the original widget (active widgets page), hopefully that achieves what you’re after. I’ll find out a bit more about adding your own widget name and get back to you on that. Cheers.
Hi,
If your ultimate goal is to modify the widget names, you can do that using the siteorigin_panels_widgets filter. This filter will allow you to filter the widget names by modifying the title field.
Please note that the widget data is cached using the Transient API for 10 hours using the `siteorigin_panels_widgets` key, so you’ll need to manually clear it (or disable it) while testing.
Kind regards,
Alex
Thank you both for your help and taking the time to respond.
I didn’t start out with the sole goal of modifying the widget names, although I can see how that comes across in this thread and I think in the end that has been the main sticking point. Thank you Alex for providing the solution, that’s working well.
The OO approach was the first that sprung to mind, seemed more intuitive than using filters and matches the structure of the other bespoke widgets (which extend SiteOrigin_Widget) that I have already. I have a feeling the caching was not helping when testing so knowing about that transient will be useful if I ever revisit this. That said, I can see the benefit of filters as being the lower maintenance and lighter weight route so thanks for confirming that Andrew.
Feel free to mark this thread as resolved if that makes sense.
Thanks again.
Thanks for your detailed reply; that all makes sense. Please let us know if any queries or requests arise in the future. Cheers for now.
Andrew