Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.

Only administrators may access "users" page

+2 votes
asked Sep 22, 2012 in Q2A Core by deividman
How do I do it?
Q2A version: 1.5.2

2 Answers

+3 votes
answered Nov 20, 2012 by jakinda
I achieved it by defining the following function in qa-base.php:

function qa_admin_gatekeeper(){
    $user_id =    qa_get_logged_in_userid();
    $user_level = qa_get_logged_in_level();
    if( (!$user_id) || (($user_level != QA_USER_LEVEL_EXPERT) &&
                ($user_level != QA_USER_LEVEL_EDITOR) &&
                ($user_level != QA_USER_LEVEL_MODERATOR) &&
                ($user_level != QA_USER_LEVEL_ADMIN)&&
                ($user_level != QA_USER_LEVEL_SUPER))){
                // don't allow access to this page to non-admin users
                header('Location: ../');


Then go to: qa-page-users.php,  find this code:

require_once QA_INCLUDE_DIR.'qa-db-users.php';
require_once QA_INCLUDE_DIR.'qa-db-selects.php';
require_once QA_INCLUDE_DIR.'qa-app-format.php';

and call the function, qa_admin_gatekeeper(); immediately after it.
commented Nov 20, 2012 by Pady Srini
I vote for this change to get into next version.
commented Nov 21, 2012 by Sammrat Ventures
Count me in. Good direction
commented Nov 25, 2012 by deividman
thanks for answer!
commented Nov 14, 2014 by Sammrat Ventures
worked perfectly, hope this gets included in the future versions.
+1 vote
answered Nov 23, 2012 by jatin.soni

You can redirect with header location to the home page or whenever you want. However I am not sure either it is appropriate way or not. But if it is so than you need to write just simple code with header location at the top of your theme file.


function doctype()
if(($this->template == 'users') AND (qa_get_logged_in_level() < QA_USER_LEVEL_ADMIN)){
header('Location: '.qa_path_html('qa').'');
I also would like to know either this is correct way or not?
commented Nov 25, 2012 by deividman
thanks for answer!