Skip to content

Add custom column for a PMPro user field to the WordPress all users list #313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions admin-pages/add-custom-column-users-list.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/**
* Adds a custom column to the Users List and show user meta data in the column.
*
* title: Adds a custom column to the Users List and show user meta data in the column.
* layout: snippet
* collection: admin-pages
* category: admin
*
* You can add this recipe to your site by creating a custom plugin
* or using the Code Snippets plugin available for free in the WordPress repository.
* Read this companion article for step-by-step directions on either method.
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
// Add 'Company' column to Users list header.
function my_pmpro_manage_users_columns( $columns ) {
$columns['company'] = 'Company';
return $columns;
}
add_filter( 'manage_users_columns', 'my_pmpro_manage_users_columns' );

// Add 'Company' column to Users list rows.
function my_pmpro_manage_users_custom_column( $value, $column_name, $user_id ) {
if ( 'company' === $column_name ) {
return get_user_meta( $user_id, 'company', true );
}
return $value;
}
add_action( 'manage_users_custom_column', 'my_pmpro_manage_users_custom_column', 10, 3 );