Skip to content

Instantly share code, notes, and snippets.

@RalfAlbert
Created January 1, 2013 13:35
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save RalfAlbert/4427538 to your computer and use it in GitHub Desktop.
Save RalfAlbert/4427538 to your computer and use it in GitHub Desktop.
WordPress: Show date of registration in user profile
<?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 ) )
);
}
@Guust-Flater
Copy link

This looks very promising!
I am just struggling with where to add the action and how.
I have been following the instructions here to customise the BP pages, and have been trying to add some code to members-loop.php, but I cannot get anything to show on the front end.

@qstudio
Copy link

qstudio commented Dec 12, 2022

$udata = get_userdata( $user-ID );

should be

$udata = get_userdata( $user->ID );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment