public
Created

WordPress: Show date of registration in user profile

  • Download Gist
membersince.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
<?php
namespace ShowMemberSince;
 
add_action( 'plugins_loaded', 'ShowMemberSince\init' );
 
/**
* Adding needed action hooks
*/
function init(){
 
foreach( array( 'show_user_profile', 'edit_user_profile' ) as $hook )
add_action( $hook, 'ShowMemberSince\add_custom_user_profile_fields', 10, 1 );
 
}
 
/**
* Output table
* @param object $user User object
*/
function add_custom_user_profile_fields( $user ){
 
$table =
'<h3>%1$s</h3>
<table class="form-table">
<tr>
<th>
%1$s
</th>
<td>
<p>Member since: %2$s</p>
</td>
</tr>
</table>';
 
$udata = get_userdata( $user-ID );
$registered = $udata->user_registered;
 
printf(
$table,
'Registered',
date( "M Y", strtotime( $registered ) )
);
 
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.