Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+2 votes
147 views
in Plugins by
edited by

I am building a new widget and I would like to ask if there is any way programmatically to let admins to add this widget more than one times in the same position. In my case at the position "Main area -Top". How can I achieve this behavior?

I checked the file admin-widgets.php and found this part of code:

$region = $regioncodes[substr($place, 0, 1)];

    $widgetallowed = method_exists($module, 'allow_region') && $module->allow_region($region);

    if ($widgetallowed) {
        foreach ($widgets as $widget) {
            if ($widget['place'] == $place && $widget['title'] == $editwidget['title'] && $widget['widgetid'] !== @$editwidget['widgetid'])
                $widgetallowed = false; // don't allow two instances of same widget in same place
        }
    }


But how can I override this code in my custom widget file as I dont want to modify core files?? I need the $widgetallowed var to be true. -> $widgetallowed = true;

Q2A version: 1.8.8

1 Answer

0 votes
by

No, you typically cannot add the same widget multiple times in the same position on most platforms. Each position usually allows only one instance of a widget.

...