Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+2 votes
617 views
in Plugins by
For now I am using:

unset($this->content['widgets']['main']['bottom'][1]);

However, what if I change the position of the widget later on, then the unset would not work anymore.

So what is the best way to remove a specific widget?

I am thinking of going over all widgets and checking their names, pseudocode:

foreach ... $this->content['widgets']
    if(get_class($widget)=='qa_related_qs') {
      unset(...);
   }

Any other idea?

2 Answers

0 votes
by

This is the solution I am using now, the widget I want to remove is: 'qa_related_qs'

    foreach($this->content['widgets'] as $widget) {
        $widgetkey = key($this->content['widgets']);
        $wcount = count($widget);
        if($wcount>0) {
            // $widget holds position like top, bottom, high
            // $wd is array index of each widget etc.
            foreach($widget as $wd) {
                for($i=0;$i<count($wd);$i++) {
                    if(get_class($wd[$i]) == 'qa_related_qs') {
                        // example: $this->content['widgets']['main']['bottom'][1]
                        // var_dump($this->content['widgets'][$widgetkey][key($widget)][$i]);
                        unset($this->content['widgets'][$widgetkey][key($widget)][$i]);
                    }
                };
            }
        }
    } // end foreach


Hope that helps.

0 votes
by
Hi kai, I used same method too. but I think removing it from the global variable $qa_layers & $qa_modules before plugin initialization is the best way since it'll prevent loading the plugin and wasting resources.
...