Home>Support>Extending / renaming existing widgets

Extending / renaming existing widgets

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.

This is our free support forum. Replies can take several days. If you need fast email support, please purchase a SiteOrigin Premium license.

  1. 2 months, 15 days ago Andrew Misplon
    Hi, I Work Here

    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.

  2. 2 months, 15 days ago C

    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.

  3. 2 months, 15 days ago Andrew Misplon
    Hi, I Work Here

    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.

  4. 2 months, 15 days ago Alex S
    Hi, I Work Here

    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

  5. 2 months, 14 days ago C

    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.

  6. 2 months, 11 days ago Andrew Misplon
    Hi, I Work Here

    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

Replies on this thread are closed. Please create a new thread if you have a question, or purchase a SiteOrigin Premium license if you need one-on-one email support.

Get The Most Out of SiteOrigin with SiteOrigin Premium

Find Out More