function roles_capabilities_add()
 {
     global $wpdb, $current_user;
     $objrole = new mgm_roles();
     $data = array();
     $arr_caps = $objrole->get_mgm_default_capabilities();
     foreach ($arr_caps as $key => $c) {
         $arr_caps[$key] = array('capability' => $c, 'name' => ucfirst(str_replace('_', ' ', $c)));
     }
     $data['capabilities'] = $arr_caps;
     $data['mgm_cap_hierarchy'] = $objrole->get_custom_capability_hierarchy();
     if (isset($_POST['add_roles'])) {
         extract($_POST);
         $status = 'error';
         $error = false;
         $rolename = trim(mgm_escape($rolename));
         if (empty($rolename)) {
             $message[] = __('Role cannot be blank.', 'mgm');
             $error = true;
         } elseif (!preg_match("/^[A-Za-z0-9_,\\s]+\$/", $rolename)) {
             $data['rolename'] = $rolename;
             $message[] = __('Role cannot contain special characters.', 'mgm');
             $error = true;
         } elseif (!$objrole->is_role_unique($rolename)) {
             $data['rolename'] = $rolename;
             $message[] = __('Role/capability already exists.', 'mgm');
             $error = true;
         }
         if (!isset($chk_capability) || isset($chk_capability) && empty($chk_capability)) {
             $message[] = __('Capability must be selected.', 'mgm');
             $error = true;
         } else {
             $data['chk_capability'] = $chk_capability;
         }
         if (!$error) {
             //save roles:
             if (!in_array($rolename, $objrole->default_roles) && !empty($chk_capability)) {
                 if ($objrole->add_role($rolename, $chk_capability)) {
                     $message[] = __('Successfully added the new role.', 'mgm');
                     $status = 'success';
                 } else {
                     $message[] = __('Error in creating role.', 'mgm');
                 }
             }
         }
         echo json_encode(array('status' => $status, 'message' => implode("<br/>", $message)));
         exit;
     }
     $this->load->template('members/roles_capabilities/add', array('data' => $data));
 }