Skip to:
Content
Pages
Categories
Search
Top
Bottom

Adding a new User Type

  • How can I add a new user category/group/type? I have the private forum plugin setup and I want to allow a specific group of people access to it. My only option of doing that right now is to put those people in the moderator group. This seems like it should be a simple thing to do (I know this feature is fairly common on all other forum scripts) so am I just overlooking it?

    Any help is appreciated!

Viewing 12 replies - 1 through 12 (of 12 total)
  • It’s pretty simple, but you need a plugin to do it. Here’s how it probably goes.

    <?php
    /*
    Plugin Name: Add lusers
    Description: adds the luser role
    Author: fel64
    */
    add_filter('get_roles', 'addlusers');

    function addlusers( $roles ) {
    $roles['luser'] = $roles['member']; //duplicate member capabilities
    $roles['luser'] =& $luser; //convenience
    $luser['name'] = __('Luser');
    $lusercaps = array('be_sucky', 'be_awesome', 'see_secrets');
    foreach( $lusercaps AS $cap ) {
    $luser['capabilities'][$cap] = true;
    }
    return $roles;
    }
    ?>

    I hope that’s not too complex, I took some shortcuts. Basically all you have to do is put that in an empty text file, save as lusers.php (or whatever), upload to your server and activate. You just need to customise a few lines: change all the instances of luser to whatever you want, and customise the extra capabilities you want them to have if any. These capabilities will be on top of the ones normal members have. (Poo, I just realised the $bb_roles->add_role() function makes it all much easier. Ah well, at least this way you can use the member as your base.)

    Then go to the members’ profiles and make them all lusers. Or whatever.

    How about removing a user group?

    Nevermind, If I just deactivate the plugin it will remove them.

    I still can’t use these users groups with the private forums plugin. I want to make a new user group so that only they have access to the private forum.

    Im in the same boat, I know things like BB(something) has it so you can set mods to see this group or that group and super mods can post in those but regulars can see the groups. So like Unregistered;rights=1 Member;rights= 2 Student;rights=3 Teacher;rights=4 Mod;rights=5 SuperMod;rights=6

    Where the #= the level of forum they can access like setting thread “teachers” to level 4 would make it so anything lower could not access it. And level 5 would make it so mods can see it but not post. & Level 6 would be like a place where you place questionable threads.

    I really don’t know alot about php yet but in due time I’m sure I will. Is there a way to make it like this?

    Not easily. You can stop people seeing certain forums using a plugin, but you can’t stop them seeing other groups (unless you remove that bit from the template, but there’s no backend method). Presumably you can use it to set multiple forum restrictions. And you can create new user groups (just adopt my plugin to create more groups). So everything but hiding the groups is fairly easy.


    meinwalter
    Member

    @meinwalter

    “Then go to the members’ profiles and make them all lusers.”

    after i have activated the plugin i can not select luser. What to do?


    SteveG190
    Member

    @steveg190

    I’ve tried using fel64′s method above but I’m not able to make it work at all, so I thought I would try something different. Since he mentioned using the $bb_roles->add_role() that already exists in functions.bb-capabilites.php I thought I could work with that. Bascially, I want to put my own additions and modified base roles (aside from admin and keymaster, obviously) into a plugin that replaces the existing roles function. I’ve sucessfuly done this via a dirty hack of the core file but I’d really love to migrate my changes to a plugin.

    Is it not possible to just do bascially a copy-paste of the bb_init_roles function from functions.bb-capabilites.php, rename it, make new roles and modify existing ones, then use something like add_filter('init_roles','my_bb_init_roles') to hook it to init_roles? Obviously I’m a complete noob to this since my attempts are completely failing and what I know is just scraped together from looking at other plugins and some limited reading on making WordPress plugins. Any assistance here would be greatly appreciated.


    lelandf
    Member

    @lelandf

    Okay, it took me a couple hours but I finally got this to work (sorta) using a variation of fel64′s code. I was using it to create a special usergroup with the same capabilities as regular members for use with the Hidden Forums plugin.

    The original code kinda worked, because it did create a new user group with the name I had chosen. I soon realized, however, the users in the user group I made had no capabilities and therefore couldn’t post, edit their profile at all, etc. I was expecting they would have the same capabilities as members.

    So I made a few changes and…here’s the plugin code I used:

    <?php
    /*
    Plugin Name: Add lusers
    Description: adds the luser role
    Author: fel64
    */

    add_filter('get_roles', 'addlusers');

    function addlusers( $roles ) {
    $roles['luser'] =& $luser; //convenience
    $luser['name'] = __('Luser');
    $lusercaps = array('participate','edit_favorites','edit_tags','edit_topics','edit_posts','edit_profile','write_topics','write_posts','change_password','read');
    foreach( $lusercaps AS $cap ) {
    $luser['capabilities'][$cap] = true;
    }
    return $roles;
    }
    ?>

    Basically I removed the first line of the function, because for some reason it wasn’t working. I then copied all the capabilities of a regular member in an array format. You can get other capabilities (like for moderators, admins, and key masters) from the capabilities.php file in /bb-includes/.

    Just save the code in a .php file and upload it to your plugins folder and activate. You would also probably want to change the “Luser” name to something else.

    Now I know this probably isn’t the best way to do it, but it worked for me, so I thought I’d share it here. Hopefully some of you get some use out of it.


    FirstAngel
    Member

    @firstangel

    I have saved, uploaded, activated. No new membergroup anywhere :(

    In 1.0 Release Candidate 1, roles change dramatically from 0.9.x. I appreciate there is Role Manager, but I wanted a simple fix for an existing tweak based on Fel’s original code.

    The code below creates a new role, adds capabilities that mimic the ‘member’ role, plus extra capabilities you specify.

    global $bb_roles; // Get the master list of roles
    $key = 'role_internal_name'; // Edit: Name of new role, as used internally by BBPress
    $name = __('Role Public Name'); // Edit: Name of new role, as shown in public
    $cap = array ( 'view_by_ip', ); // Edit: Add extra capabilities within this array. Must be pre-defined capabilities. Empty if you just wish to apply member capabilities.
    $r = new BP_Role(); // New role class
    $r->name = $key; // Assign the internal name
    $r->capabilities = $bb_roles->role_objects[ 'member' ]->capabilities; // Copies member capabilities to the new role
    foreach ( $cap as $add ) $r->capabilities[ $add ] = 1; // Adds extra capabilities
    $bb_roles->role_objects[ $key ] = $r; // Adds the new role to $bb_roles
    $bb_roles->role_names[ $key ] = $name; // Adds the new role to the list of role names

    Hooked using: add_action/add_filter( ‘bb_got_roles’, ‘my_function_name’ );

    I have no idea whether this is the most efficient way of doing this. So I’d welcome improvements.


    Michael3185
    Member

    @michael3185

    I like the idea of roles, but am using the latest stable release 0.9.0.4 Nobody’s said here which version this attempt at role creation is for..?

    Fel’s code works for 0.9.x. My code works for 1.0.

    Worth making clear that 0.9 code will stop working once you upgrade to 1.0: Users with bespoke roles loose their capabilities, although those old roles do remain in the database, so can be found by new code.

Viewing 12 replies - 1 through 12 (of 12 total)

You must be logged in to reply to this topic.