Created
January 21, 2022 03:28
-
-
Save cryptexvinci/1d9a25b213877ec08bd3a2817eae8b5d to your computer and use it in GitHub Desktop.
Add custom Ultimate member fields Column to Users list table on WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Display UM Country Column Label | |
function um_add_meta_user_table( $column ) { | |
$column['country'] = 'Country'; | |
return $column; | |
} | |
add_filter( 'manage_users_columns', 'um_add_meta_user_table' ); | |
// Display UM Country Column Value | |
function um_add_meta_user_table_row( $val, $column_name, $user_id ) { | |
if ($column_name == 'country') { | |
return get_user_meta( $user_id, 'country', true ); | |
} | |
return $val; | |
} | |
add_filter( 'manage_users_custom_column', 'um_add_meta_user_table_row', 10, 3 ); | |
// Make the Country column sortable | |
function um_user_sortable_columns( $columns ) { | |
$columns['country'] = 'country'; | |
return $columns; | |
} | |
add_filter( 'manage_users_sortable_columns', 'um_user_sortable_columns' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment