Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+1 vote
541 views
in Q2A Core by

Just trying to figure out how to use the new notice system.  I see it's possible to preset a notice for a user, which is useful for the badges plugin, but what if I want to show a notice based on my own criteria, say if the logged_in user is admin?

In doctype() I set the following:

$this->content['notices'][]=qa_notice_form('updates', qa_viewer_html(qa_opt('admin_plus_notify_text'), ''));

And the notice is added to the DOM as expected, but there's something in body_script() that is hiding it... removing the body_script function makes it work as expected... what am I missing?

Q2A version: 1.5

1 Answer

+1 vote
by
selected by
 
Best answer

It's being hidden because body_script() sets a CSS class on the page to say Javascript is enabled, and notices are hidden at first in this case, only to be re-displayed via another Javascript that calls qa_reveal() - see qa_output_content(...) in qa-page.php.

The bottom line is that the theme class is a little too late in the game to add a notice manually. Instead, your best bet is probably to override the function qa_output_content(...) and add the notice on to $qa_content before calling through to the base function via qa_output_content_base(...)

by
Thanks, that clears it up.  But I can just do this:

                                $this->content['notices'][]=qa_notice_form('updates', qa_viewer_html(qa_opt('admin_plus_notify_text'), 'html'));
                                $this->content['script'][]= "<script type=\"text/javascript\">jQuery(document).ready(function(){qa_reveal(document.getElementById('notice_updates'), 'notice');});</script>";

no?  Seems to work...
by
Sure, you could do that too.
...