WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a user role "author" with a modified capability to add users and give them the role of subscriber.

I'm trying to edit the Users List on the dashboard to display only the subscribers created by that user.

I took a stab at implementing code from this article, but was unsuccessful.

Remove Ability for Other Users to View Administrator in User List?

Can someone point me in the right direction?

share|improve this question
I think WordPress doesn't store information - who created that user, so you can't query for this. – Mamaduka Apr 9 '12 at 9:12

WordPress doesn't know which user created which, so first you need to store the creator's data in the newly created user meta so you can so something like this:

add_action( 'user_register', 'Store_creator' );
function Store_creator($user_id){
    $creator = wp_get_current_user();
    //only do this when none admin creates the user
    if ( $creator->roles[0] == 'administrator' ) return;


Then you customize the list of users he can see based on that meta:

function custom_pre_user_query($user_search) {
    global $wpdb;
    $user = wp_get_current_user();
    if ( $user->roles[0] != 'administrator' ) { 
        global $wpdb;
        $user_search->query_where = 
        str_replace('WHERE 1=1', 
            "WHERE 1=1 AND {$wpdb->users}.ID IN (
                 SELECT wp_usermeta.user_id FROM $wpdb->usermeta 
                    WHERE wp_usermeta.meta_key = '_creator' 
                    AND wp_usermeta.meta_value = {$user->ID})", 
share|improve this answer
Thanks for the quick response Bainternet. I've implemented the code and am running into a header already sent error. It appears from the wordpress core and not the theme. Warning: Cannot modify header information - headers already sent by (output started at /nfs/c08/h03/mnt/116004/domains/jokakecms.kitchensinkstudios.com/html/contentman‌​agedjokake/wp-includes/wp-db.php:955) in /nfs/c08/h03/mnt/116004/domains/jokakecms.kitchensinkstudios.com/html/contentman‌​agedjokake/wp-includes/functions.php on line 861 – certainstrings Apr 9 '12 at 19:36
Nothing in the code i posted echos out anything so i guess its the way you embbed the snippets. Create a pastebin with your code and link it, I'll take a look – Bainternet Apr 10 '12 at 2:17

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.