Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+3 votes
1.9k views
in Q2A Core by
How can I add new user type and assign permission to them?

 

I want to create User Type "writer"  and aaisgn permissions to it.
Q2A version: 2.6.3

2 Answers

0 votes
by

Other similar questions:

http://www.question2answer.org/qa/35313/new-user-level-permisssion?show=35313#q35313

http://www.question2answer.org/qa/29416/custom-user-types?show=29416#q29416

I don't believe this is very straight forward. I used Windows Grep to search all of the files in my Q2A application and found 11 core files under qa-include that contained the word "expert", most at least 2 times. Even if you added a user level to these files, you'd have to be very careful whenever you updated your site as you would overwrite your changes. I also have 2 plugins that reference the user types, so you'd need to be careful there as well.

These are the files that contained "expert":

  • qa-app-admin
  • qa-app-options
  • qa-app-users-edit
  • qa-app-users
  • qa-external-users-wp
  • qa-lang-options
  • qa-lang-users
  • qa-page-account
  • qa-page-admin-default
  • qa-page-user-profile
  • qa-page-users-special
0 votes
by
I could achieve this by overriding user edit page, this can be done as a plugin. you do not need to modify Q2A core file.

if($this->template == 'user'){ //lets first override user template and set our custom permission.
            if(qa_get_state() == 'edit'){
                $this->content['form_profile']['fields']['level']['options'][21] = Writer;
                $form_profile_fields_level_options = $this->content['form_profile']['fields']['level']['options'];
            }else{
                if($this->content['raw']['account']['level'] == 21){
                    $this->content['form_profile']['fields']['level']['value'] = "Writer";

// Anything else you want to show on the profile.
                }
            }

// Then, say you want to override a question page and set certain permission for writer,

if($this->template == 'question'){

          if(qa_get_logged_in_level() == 21){

            // your code here.
           }

}

hope that helps.
...