Show user registration time in WordPress

registerd_users

Would you like to see the date a user registered on the website? In this article we show how to display the user registration time in WordPress by adding an additional column to the users page.

Column Registration

First thing we need to do is register the new column in the users page. You can add this code to the theme in functions.php file or in a plugin.

function user_add_columns( $columns ){	
	$columns['user_registered'] = __( "Registered" );
	return $columns;
}
add_filter( 'manage_users_columns', 'user_add_columns' );

Showing the registration date

Once the column has been registered we can use the name assigned previously to display the date and when the user registered on the site.

function user_display_registerd_date( $void, $column_name, $user_id ){
	if( ! $column_name != 'user_registered' )
		return;	

	$user = get_userdata( $user_id );
	return mysql2date( 'Y/m/d', $user->user_registered, true );
}
add_filter( 'manage_users_custom_column', 'user_display_registerd_date' );

Sort column

The next code is optional, it will add the sort column functionality.

function user_sort_registered_column( $columns ){
	$columns['user_registered'] = 'user_registered';
	return $columns;
}
add_filter( 'manage_users_custom_column', 'user_sort_registered_column' );

Leave a Reply

Your email address will not be published. Required fields are marked *