Add custom columns to Users listing table

Add custom columns to Users listing table

After you add custom fields to users, you definitely need to show this new info in Users listing table.

function wcr_user_columns($defaults) {
    $defaults['type'] = __('User type');
    $defaults['age'] = __('Age');

    return $defaults;
}

function wcr_user_columns_values($value, $column_name, $id) {

    switch ($column_name) {
        case 'type':
            return get_the_author_meta('type', $id) ? : 'N/A';
            break;
        case 'age';
            return get_the_author_meta('age', $id) ? : 'N/A';
            break;
    }

}

// do the magic
add_filter('manage_users_columns', 'wcr_user_columns', 10, 1);
add_action('manage_users_custom_column', 'wcr_user_columns_values', 10, 3);
Leave a Reply

Get our Wordpress
freebies to your inbox