Skip to:

How to: ddlb of user roles

  • Hi,

    I am trying to create a ddlb with all user roles as options. I just can’t manage to create one. I can make one manually, putting the user roles in by hand (html), but I want to pull them from the database and create a ddlb from it.

    Any ideas? Want to use it in a plugin I am working on, so a function would be nice.



Viewing 12 replies - 1 through 12 (of 12 total)
  • What’s a ddlb?

    What have you tried?

    What is the problem you’re having?



    ddlb == Drop Down List Box?



    I don’t believe the roles are stored in the database, I think they’re all stored and defined in bb-includes/capabilities.php. So, I don’t believe you can pull them from anywhere other than there. Maybe I missed it and they are defined in the database somewhere, but I don’t think so.

    There is already a drop down of roles in the admin section, when you go to edit a user’s profile, you can mark them member, inactive, blocked, etc. Take a look at lines 1309 – 1317 in bb-includes/template-functions.php

    <th scope="row"><?php _e('User Type:'); ?></th>
    <td><select name="role">
    <?php foreach( $roles as $r => $n ) : ?>
    <option value="<?php echo $r; ?>"<?php if ( array_key_exists($r, $user->capabilities) ) echo ' selected="selected"'; ?>><?php echo $n; ?></option>
    <?php endforeach; ?>

    Will that do what you want?

    Hi guys,

    Sorry ddlb = drop down listbox

    @ chris: yes i did try that one already, but it gave me a empty ddlb (proberbly because the user’s role couldn’t be defined) .

    @livibetter: din’t try it but that will give (I think) all roles, but not in a ddlb.

    For forums there is a function: bb_forum_dropdown, but I couldn’t adapt it to get user roles, so I think a whole new function must be written to put it in the plugin I am working on. I have the feeling all the pieces are there, but I have no idea how to put them together :)



    @Null: of course, you get all roles’ data. I meant you can get each role’s name from the returning result of $bb_roles->get_roles() (I thought you was going to do something special). However chrishajer has told you the useful information for all your need, you just need to read from to 1311. If you really want to do something with bbPress, you have to read the source of bbPress.



    > yes i did try that one already, but it gave me a

    > empty ddlb (proberbly because the user’s role

    > couldn’t be defined) .

    It has nothing to do with the current user’s role not being defined. That is a list box that appears in the admin section with all roles listed. That will provide you with all roles. I would suspect you need to be logged in as admin to see it though. Where are you trying to use it, and for what? Maybe someone can help you with a little more information.



    Check this:

    I did that using the stuff I mentioned in this post. So, it works as an administrator since they can edit other users. There is a drop down with all 6 roles listed.

    Okay chris, now try this:

    Make a clean php file.

    Now add that code you mentioned

    Make the php page a plugin and activate it.

    Now go to your admin -> pluginpage and you’ll see an empty ddlb too :)

    It works in your PNG image example, cause you just copied the code in the same page. It will always work that way, but not in a clean file…


    Haven’t you noticed this line from bbPress source (L1296 in template-functions.php)?

    $roles = $bb_roles->role_names;

    I think chrishajer and me thought you knew how to program with PHP (by checking your website). Yes, chrishajer gave you a piece of code that is a hint not a just-can-work code at everywhere. I thought you can code with PHP, and you should be able to put the rest on your own code. However, I was wrong or you think someone else has taken care of the rest for you?

    you also need to do global $bb_roles;, in case you really can not code with PHP.

    (edit: Sorry for this emotional post to everyone else)



    I’m not a programmer. I don’t know that much about bbPress. I’ve never written a bbPress plugin. But from reading the source and looking at other admin plugins, I was able to make this work. I’m sure you can too.

    … sorry for asking for help…. thought forums where here for that…

    I can’t program, never said I did, I build things with trial and error, learning that way. Reading and trying to understand how and why things works. So if I get just a piece of code I’ll try that and try other suggestions too. I am more a reverse engineer. The site and things I’ve builded can be done in 2 hours if you are a phpprogrammer, I do it in two weeks or more, but I get it done (don’t give up) and am proud if I acomplisch what I wanted.

    Assuming someone can program cause his plugin is awesome wont work everytime :). Most things I can figure out myself, but if some small stupid thing like a ddlb takes too much time I am gonna ask the forums (duh). Kinda get the feeling now that, if you can’t program, you shouldn’t do it or ask for help…

    Like the post above from Chris, you’ve managed to make it work and you are assuming I can figure this out too cause it was apparently easy for you to figure out. But I don’t think like a programmer, it’s hard for an person like me to figure it all out. I don’t know where all code is pulled from or is placed. I use bbpulp a lot to find the needed code, but that isn’t always enough.

    I’m glad Chris found an answer, but then I ask: how did you do it? Can you show me the code and explain some of it so I can learn from it…

    Better look like it like this, I can build a car, but I don’t know how to construct it. I know I need an engine, but I don’t know how the engine works. I know what it does, I know I need it… and so I puzzel the car together. A mechanic will do it in 1 week, I’ll do it in 1 year…

    I am weird, I know :)

    Well I just wanted to get this of my chest and also mention I aint attacking anyone (especially Chris, just jused your post as an excample)

    So no hard feelings (from me anyway) and thanks for your time


Viewing 12 replies - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.
Skip to toolbar