Created
December 22, 2020 10:14
-
-
Save doubleedesign/9a56c8e0982824d3de278a9101a24606 to your computer and use it in GitHub Desktop.
Add a join date column to the users table in wp-admin
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 | |
/** | |
* 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