Duplicate widgets in profile

I've been having this issue for a while ive been using widget manager and alot of my profiles have duplicate widgets.

 

I tried re pin them and un pin them. That just made the duplication worse..

Is their a way I can just delete all widgets then just re add them?

something like:

$content2= elgg_get_entities(array(
            "type" => "object",
            "subtype" => "widget",
            'limit' => 1000));


         foreach($content2 as $content){
            $widget_guid = $content->guid;           

            $widget = get_entity($widget_guid);
            $widget->delete();
         }

 

I'm to scared to run this... dont want to wipe out something thats needed.

  • Yes, that is a valid way of removing widgets.

    However you'll want to remove only the widgets that are in the profile context:

    if ($widget->context == 'profile') {
        $widget->delete();
    }

  • Also, you don't need get_entity() because elgg_get_entities() returns ElggWidget objects.

    So you can just do:

    $widgets = elgg_get_entities(array(
        "type" => "object",
        "subtype" => "widget",
        'limit' => false,
    ));

    foreach ($widgets as $widget) {
        if ($widget->context == 'profile') {
            $widget->delete();
        }
    }

  • Awesome! Thanks Juho!

     

    Im getting this error now. but its been working so far

    Fatal error: Unsupported operand types in /home/content/40/11160640/html//mod/elggx_userpoints/start.php on line 293