1

When I open Dashboard-->Plugins, the page lists all of my installed plugins in an admin table. It displays two columns: 'Plugin' and 'Description' (screenshot). How can I add a new column to this table, and display data of my choosing? I am aware of WP_List_Table(), and have used it in the past to create a new admin table, on a new admin page. But can I use it to modify the existing plugins table?

Alternatively, if I could add additional information to the existing 'Description' column--as other plugins do (screenshot--that would be acceptable.

3
  • 1
    Have you checked the answer? Did it help?
    – Sally CJ
    Aug 26, 2019 at 8:25
  • Looks to be promising, but I'll really need ~2-3 more days to have a thorough read. I'll make sure to reply here.
    – cag8f
    Aug 26, 2019 at 12:02
  • 1
    Sure, take your time.
    – Sally CJ
    Aug 27, 2019 at 2:42

1 Answer 1

2

The table of plugins on the plugins admin screen uses WP_Plugins_List_Table which extends the WP_List_Table class. And there are hooks which you can use to modify the table columns, content, etc. Here are some of the hooks, which are relevant in your case:

Working Example

Preview

enter image description here

The Code

Note: The screen ID of the plugins admin screen (wp-admin/plugins.php) is plugins.

// Add the "Main File" column.
add_filter( 'manage_plugins_columns', 'my_add_main_file_column' );
function my_add_main_file_column( $columns ) {
    $columns['main_file'] = 'Main File';
    return $columns;
}

// Display the content for the "Main File" column.
add_action( 'manage_plugins_custom_column', 'my_the_main_file_column', 10, 2 );
function my_the_main_file_column( $column_name, $plugin_file ) {
    if ( 'main_file' === $column_name ) {
        echo $plugin_file;
    }
}

// Add custom content in the "Description" column.
add_filter( 'plugin_row_meta', 'my_add_custom_plugin_meta' );
function my_add_custom_plugin_meta( $plugin_meta ) {
    $plugin_meta[] = 'Custom data here';
    return $plugin_meta;
}
2
  • 1
    OK I had a look, and everything seems to do exactly what I want. Thanks very much for all that, including the sample code--it worked perfectly and illustrated everything I need. I was able to also convert your sample column into a sortable column, using your instructions. So let's call this answered--thanks again. Separately, what application do you use to create your screenshots? I use Microsoft Paint, but yours seems to have some nicer features.
    – cag8f
    Sep 1, 2019 at 11:36
  • 1
    You're welcome and see this regarding that separate thing. :)
    – Sally CJ
    Sep 4, 2019 at 0:16

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.