Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+2 votes
541 views
in Plugins by
Or the opposite. Widget visible only to logged in users.
Q2A version: 1.7 and 1.8

1 Answer

+4 votes
by
selected by
 
Best answer

You cant write PHP code inside the widget so you need to modify the plugin code.

1. Open file qa-wa-layer.php and locate this foreach loop: https://github.com/svivian/q2a-widget-anywhere/blob/41172e294af6a1efade322da4465897348fb3869/qa-wa-layer.php#L81

2. Edit it this way:

foreach ($this->wanyw_widgets as $wid) { 
    if ($wid['position'] !== $pos) { 
        continue; 
    } 
 
    switch ($wid['id']) { 
        case 1: 
            if (qa_is_logged_in()) { 
                $this->output($wid['content']); 
            } 
            break; 
        case 2: 
            if (!qa_is_logged_in()) { 
                $this->output($wid['content']); 
            } 
            break; 
        default: 
            $this->output($wid['content']); 
    } 
}

3. Edit the case 1 and case 2 so that the number is actually the widget ID. You can see the widget ID when you edit a widget, in the URL, e.g. here is a 1 in the URL: admin/widgetanyw?editid=1

In this case, 1 is for logged in users only. And 2 is for anonyous users only.

by
Thank you very much, Pupi. :)
by
How to do the same based on points ?
Like if the user have less than 200 points show him a HTML box otherwise not.
...