Please or Register to create posts and topics.

How can I display the registration date in the user block?

Hello

How can I display the registration date in the user block?

It’s best to make it visible only to logged-in users.

Nur ein Biker weiß, warum ein Hund seinen Kopf aus einem Autofenster steckt.
Only a biker knows why a dog sticks its head out a car window.

Hi @biker

Sorry for the late reply! 🙂 The following code should help you to receiver the registration-date of a user:

$userData = get_user_by('id', $user_id);
echo $userData->user_registered;

 

If you want to support the development of Asgaros Forum, you can leave a good review or donate. Thank you very much!

@asgaros

Thank you for your help.

To which file and where do I need to include this code?

 

Nur ein Biker weiß, warum ein Hund seinen Kopf aus einem Autofenster steckt.
Only a biker knows why a dog sticks its head out a car window.

You can “humanize” the registration date so it looks friendlier (instead of a raw timestamp) by formatting it into plain language, e.g., “Member since July 2011” or “Joined 14 years ago.” For example, in PHP/WordPress you could do:

if ( is_user_logged_in() ) {
$user = get_userdata( $user_id );
$reg_date = strtotime( $user->user_registered );
echo “Member since ” . date_i18n( “F Y”, $reg_date ); // e.g. “Member since July 2011”
// or relative: echo “Joined ” . human_time_diff( $reg_date, current_time(‘timestamp’) ) . ” ago”;
}

That way, the profile block will display a natural, human-readable date instead of a technical one.