Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extend admin users list page?

Tags:

php

wordpress

Below is a image of the WordPress admin user list:

All I want to do is add an extra column called add badges. Column value should be a link to a another page.

I tried editing core files but it ended up realizing it's a bad practice since, because if I make changes I will lose the changes with the next update.

What WordPress does is that it uses $wp_list_table = _get_list_table('WP_Users_List_Table'); to get the table and $wp_list_table->display(); to display the table.

How to add a field to the table and to extend the admin users list page?

like image 674
Techie Avatar asked Aug 31 '13 16:08

Techie


1 Answers

You need the filters manage_users_columns and manage_users_custom_column.

Code from Showing user ID on user main page from screen options:

add_filter( 'manage_users_columns', 'column_register_wpse_101322' );
add_filter( 'manage_users_custom_column', 'column_display_wpse_101322', 10, 3 );

function column_register_wpse_101322( $columns ) 
{
    $columns['uid'] = 'ID';
    return $columns;
}

function column_display_wpse_101322( $empty, $column_name, $user_id ) 
{
    if ( 'uid' != $column_name )
        return $empty;

    return "<strong>$user_id</strong>";
}
like image 168
brasofilo Avatar answered Oct 03 '22 10:10

brasofilo