Вы здесь
Главная > Мой блог > WEB-разработка > Удалить колонку из списка пользователей в админке wordpress

Удалить колонку из списка пользователей в админке wordpress

How to remove column from WordPress users list? You may don’t wish to show some column to the non-admin users with access to the users list, for example.
WordPress “Users” table has 6 built-in columns: checkbox for row selection, Username, Name, E-mail, Role, Posts. Every column has its ID.
Look as them are defined at the WP_Users_List_Table::get_columns() method of wp-admin/includes/class-wp-users-list-table.php, line #269:

If for example you need to remove E-mail column you should unset a column with ’email’ ID. Let’s go to the final step:

We use manage_users_columns filter to achieve this purpose. This code removes ‘E-mail’ folder for users with ‘moderator’ role. Replace it with your own one.
In order to remove other column replace ’email’ column ID to that column ID: role, posts, etc.

Other variant for the list of roles:

Another variant for the list of users ID:

Put a selected variant of a code to your active theme functions.php file or into .php file at the wp-content/mu-plugins/ folder in order to start use it at your site.

A strange thing – manage_users_columns filter was not documented. I think that a reason is its complex definition. Look into the WP_List_Table class constructor:

This shows that there are a lot of useful filters which may help to manage columns list of any WordPress items list: posts, pages, media library items, any custom post type. What you should know in order to use such filter is just a screen ID of that table list. For example:

List Screen ID Filter Columns ID
Posts edit-post manage_edit-post_columns cb, title, author, categories, tags, ‘taxonomy-‘ . $taxonomy, comments, date
Media upload manage_upload_columns cb, title, author, categories, tags, ‘taxonomy-‘ . $taxonomy, parent, comments, date
Pages edit-page manage_edit-page_columns cb, title, author, comments, date
Comments edit-comments manage_edit-comments_columns cb, author, comment, response
Plugins plugins manage_plugins_columns cb, name, description
Users users manage_users_columns cb, username, name, email, role, posts

For custom post types you may use this filter: “manage_{$post_type}_posts_columns”.

Источник: https://www.role-editor.com

Добавить комментарий