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?

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

1 Answer 1


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})", 
  • 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/contentmanagedjokake/wp-includes/wp-db.php:955) in /nfs/c08/h03/mnt/116004/domains/jokakecms.kitchensinkstudios.com/html/contentmanagedjokake/wp-includes/functions.php on line 861 Apr 9, 2012 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, 2012 at 2:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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