Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add a join date column to the users table in wp-admin
<?php
/**
* Add custom columns in Users area in the CMS
* @param $columns
*
* @return mixed
*/
function doublee_manage_users_columns($columns) {
$columns['join_date'] = 'Join date';
return $columns;
}
add_filter('manage_users_columns', 'doublee_manage_users_columns');
/**
* Populate custom columns in Users area in the CMS
*
* @param $output
* @param $column_name
* @param $user_id
*
* @return string
* @throws Exception
*/
function doublee_manage_users_custom_columns($output, $column_name, $user_id) {
$userdata = get_userdata($user_id);
// Populate the join date column
if($column_name == 'join_date') {
$recorded_date = $userdata->user_registered;
$date = new DateTime($recorded_date);
$updated_date = $date->setTimezone(new DateTimeZone('Pacific/Auckland'));
$output = date_format($updated_date, 'Y-m-d H:i:s');
}
// Populate the listing count column
if($column_name == 'listing_count') {
$listings = get_user_meta($user_id, 'listings', true);
if($listings) {
$count = count( $listings );
$url = admin_url().'edit.php?post_type=product&author='.$user_id;
$output = '<a href="'.$url.'">'.$count.'</a>';
}
}
return $output;
}
add_filter('manage_users_custom_column', 'doublee_manage_users_custom_columns', 10, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment