Was working on this, thought to blog.

Sometimes it's needed to add extra column on user table to show extra property file a custom meta field or something like this. Let's say you want to list a column called "Customer Since" on user table which will display the registration date of your user.

Okay we'll do it now.

To achieve this we will have to use to action hook called "manage_users_columns" and "manage_users_custom_column"

First will have to add the extra column on the table.

function register_custom_user_column($columns) {
    $columns['customer_since'] = 'Customer Since';
    return $columns;
}

Now generate the value

function register_custom_user_column_view($value, $column_name, $user_id) {
    $user_info = get_userdata( $user_id );
    if($column_name == 'customer_since') return $user_info->user_registered;
    return $value;

}

Finally hook them

add_action('manage_users_columns', 'register_custom_user_column');
add_action('manage_users_custom_column', 'register_custom_user_column_view', 10, 3);

Aaand, that's it.




What's on your mind?


9 Comments

modmanpaul commented over 9 years ago

perfect thank you. I used this to display a custom user meta value I create on registration. can you tell me how to make this new column searchable? i don't need to sort by it but when I search for the value (a number) it says no users found