Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+5 votes
1.1k views
in Q2A Core by
How can I disable authors to close or hide their own questions and comments ?
Q2A version: 1.6.2
by
Anyone can help?

1 Answer

+4 votes
by
edited by

Add codes in your theme.php

function q_view_buttons($q_view) {
  if (!empty($q_view['form'])) {
    if(qa_get_logged_in_userid() == $q_view['raw']['userid']) {
      /*
      define('QA_USER_LEVEL_BASIC', 0);
      define('QA_USER_LEVEL_APPROVED', 10);
      define('QA_USER_LEVEL_EXPERT', 20);
      define('QA_USER_LEVEL_EDITOR', 50);
      define('QA_USER_LEVEL_MODERATOR', 80);
      define('QA_USER_LEVEL_ADMIN', 100);
      define('QA_USER_LEVEL_SUPER', 120);
      */
      if(qa_get_logged_in_level() < QA_USER_LEVEL_EXPERT) {
        if(isset($q_view['form']['buttons']['close']))
          unset($q_view['form']['buttons']['close']);
        if(isset($q_view['form']['buttons']['hide']))
          unset($q_view['form']['buttons']['hide']);
      }
    }
  }
  qa_html_theme_base::q_view_buttons($q_view);
}
by
@polle Upper logic does not consider external user. Because integration program (external user inner Q2A) is weak feature that tends to produce bug, I don't like it.
by
@sama55: Could you please tell me which exactly file do you mean by "theme.php"?
I added this code to "qa-theme-base.php" and "qa-theme.php" but nothing changed.
BTW, Does this code work for Q2A 1.6.3 at all?
by
> Does this code work for Q2A 1.6.3 at all?

Yes.

> Could you please tell me which exactly file do you mean by "theme.php"?

If you are using Snow theme, add codes at end (before of last "}" ) of qa-theme/Snow/qa-theme.php. I modified a little codes of christoph.

http://www.question2answer.org/qa/27468

    function q_view_buttons($q_view) {
      if (!empty($q_view['form'])) {
        if(qa_get_logged_in_userid() == $q_view['raw']['userid']) {
          /*
          define('QA_USER_LEVEL_BASIC', 0);
          define('QA_USER_LEVEL_APPROVED', 10);
          define('QA_USER_LEVEL_EXPERT', 20);
          define('QA_USER_LEVEL_EDITOR', 50);
          define('QA_USER_LEVEL_MODERATOR', 80);
          define('QA_USER_LEVEL_ADMIN', 100);
          define('QA_USER_LEVEL_SUPER', 120);
          */
          if(qa_get_logged_in_level() < QA_USER_LEVEL_EXPERT) {
            if(isset($q_view['form']['buttons']['close']))
              unset($q_view['form']['buttons']['close']);
            if(isset($q_view['form']['buttons']['hide']))
              unset($q_view['form']['buttons']['hide']);
          }
        }
      }
      qa_html_theme_base::q_view_buttons($q_view);
    }
    function a_item_buttons($a_item) {
        if (!empty($a_item['form'])) {
            if (qa_get_logged_in_userid() == $a_item['raw']['userid']) {
                /*
                  define('QA_USER_LEVEL_BASIC', 0);
                  define('QA_USER_LEVEL_APPROVED', 10);
                  define('QA_USER_LEVEL_EXPERT', 20);
                  define('QA_USER_LEVEL_EDITOR', 50);
                  define('QA_USER_LEVEL_MODERATOR', 80);
                  define('QA_USER_LEVEL_ADMIN', 100);
                  define('QA_USER_LEVEL_SUPER', 120);
                 */
                if (qa_get_logged_in_level() < QA_USER_LEVEL_EXPERT) {
                    if (isset($a_item['form']['buttons']['hide']))
                        unset($a_item['form']['buttons']['hide']);
                }
            }
        }
        qa_html_theme_base::a_item_buttons($a_item);
    }
    function c_item_buttons($c_item) {
        if (!empty($c_item['form'])) {
            if (qa_get_logged_in_userid() == $c_item['raw']['userid']) {
                /*
                  define('QA_USER_LEVEL_BASIC', 0);
                  define('QA_USER_LEVEL_APPROVED', 10);
                  define('QA_USER_LEVEL_EXPERT', 20);
                  define('QA_USER_LEVEL_EDITOR', 50);
                  define('QA_USER_LEVEL_MODERATOR', 80);
                  define('QA_USER_LEVEL_ADMIN', 100);
                  define('QA_USER_LEVEL_SUPER', 120);
                 */
                if (qa_get_logged_in_level() < QA_USER_LEVEL_EXPERT) {
                    if (isset($c_item['form']['buttons']['hide']))
                        unset($c_item['form']['buttons']['hide']);
                }
            }
        }
        qa_html_theme_base::c_item_buttons($c_item);
    }
...