farly (@farly)

Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • In reply to: Custom User Groups

    Okay I had to change it a bit:

    <?php
    /*
    Plugin Name: Add custom usergroups
    Description: Adds custom usergroups
    Author: fel64, farly
    */
    add_filter('get_roles', 'add_custom_usergroups');

    function add_custom_usergroups( $roles ) {

    //define custom groups

    //$groups['GROUPNAME'] = array('CAPABILITIES LIKE','HUMAN GROUPNAME', array(EXTRA CAPABILITY, EXTRA CAPABILITY));

    $groups['probemitglied'] = array('member','Mitglied auf Probe', array());
    $groups['mitglied'] = array('member','Mitglied', array());
    $groups['kernmitglied'] = array('member','Kernmitglied', array());
    $groups['koordinator'] = array('moderator','Koordinator', array());
    $groups['leiter'] = array('administrator','Leiter', array());

    foreach ($groups as $key => $g) {
    $roles[$key] = $roles[$g[0]]; //duplicate member capabilities
    $roles[$key]['name'] = __($g[1]); // change name
    foreach( $g[2] as $capability ) {
    $roles[$key]['capabilities'][$capability] = true; // add extra capabilities
    }
    }
    return $roles;
    }
    ?>

    In reply to: Custom User Groups

    Thanks!

    I modified this approach slightly and ended up with this:

    <?php
    /*
    Plugin Name: Add custom usergroups
    Description: Adds custom usergroups
    Author: fel64, farly
    */
    add_filter('get_roles', 'add_custom_usergroups');

    function add_custom_usergroups( $roles ) {

    //define custom groups
    $groups['mitglied_probe'] = array('Mitglied auf Probe', array('rulord_level1'));
    $groups['mitglied'] = array('Mitglied', array('rulord_level1', 'rulord_level2'));
    $groups['kernmitglied'] = array('Kernmitglied', array('rulord_level1', 'rulord_level2', 'rulord_level3'));
    $groups['koordinator'] = array('Koordinator', array('rulord_level1', 'rulord_level2', 'rulord_level3', 'rulord_level4'));
    $groups['leiter'] = array('Leiter', array('rulord_level1', 'rulord_level2', 'rulord_level3', 'rulord_level4', 'rulord_level5'));

    foreach ($groups as $key => $g) {
    $roles[$key] = $roles['member']; //duplicate member capabilities
    $roles[$key] =& $user[$key]; //convenience
    $user[$key]['name'] = __($g[0]);
    foreach( $g[1] as $capability ) {
    $user[$key]['capabilities'][$capability] = true;
    }
    }
    return $roles;

    }
    ?>

    It works for me so far :)

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