admin管理员组文章数量:1414857
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.
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.
Share Improve this question asked Aug 22, 2019 at 11:42 cag8fcag8f 1,9973 gold badges21 silver badges31 bronze badges 3- 1 Have you checked the answer? Did it help? – Sally CJ Commented 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 Commented Aug 26, 2019 at 12:02
- 1 Sure, take your time. – Sally CJ Commented Aug 27, 2019 at 2:42
1 Answer
Reset to default 2The 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:
plugin_row_meta
— allows you to add custom meta/content at the bottom of the "Description" column.manage_plugins_custom_column
— use this to display/echo
the content for a custom column.manage_plugins_columns
— allows you to add a custom column, but to make it sortable, you need to also add it using the hook below. Note: This hook is defined inwp-admin/includes/screen.php
.manage_plugins_sortable_columns
— this hook is defined in the parent list table class, and the hook allows you to add a sortable column.
Working Example
Preview
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;
}
本文标签: How to display additional info in the plugins admin table
版权声明:本文标题:How to display additional info in the plugins admin table? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745223765a2648513.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论