3

I am trying to add a custom column un users.php but it stays empty.

I have successfully added a column to the users admin page with this code in my theme's functions.php file:

function add_user_test_column( $columns ) {
    $columns['test1'] = 'Test';
    return $columns;
} 
add_filter( 'manage_users_columns', 'add_user_test_column' );

I have tried to add something to the column with this code but the colum stays empty:

function add_test_column_data($v = '', $column_name, $user_id ) {
    if( 'test1' == $column_name ) {
        return 'test'.$column_name.$user_id;
    }
}
add_filter( 'manage_users_custom_column', 'add_test_column_data', 10,3);

I can see that the function is firing because if I modify the return to an echo like this :

function add_test_column_data($v = '', $column_name, $user_id ) {
    if( 'test1' == $column_name ) {
        echo 'test'.$column_name.$user_id;
    }
}

I can see the "test test test test test test" echo'd along the top of the user table.
As you can see, the variables passed into the function are not taken into account. I have also tried reducing the priority (3rd argument to the add_filter function) from 10 to 1, with no effect.

So my questions are:
Why is the return from this function not working?
Why are the variables passed into the function not taken into account?
Where should I look to debug this?

I should add that this is not a vanilla install. I have taken over a complex site on wordpress 3.4.2 with lots of extensions and > 100 000 users. (and I have never used Wordpress before... ).

Thanks in advance for your suggestions.

Keith

1 Answer 1

8

I have the same problem on WP 3.2.1.

There was a filter conflict because a plugin (User Access Manager) calls manage_users_custom_column filter too.

I change priority and it solved the problem :

add_filter( 'manage_users_custom_column', 'custom_user_column_value', 15, 3 );

Hope that helps :)

2
  • Priority still makes the difference today! May 25, 2022 at 10:17
  • @MrJoshFisher ;) May 26, 2022 at 11:11

Your Answer

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

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