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;

 

kurio has reacted to this post.
kurio
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.

kurio has reacted to this post.
kurio

@rohit045  but where to insert this script?

@asgaros You recommend the code, but I don’t know where to put it? Is that nice? Will you ever answer this?

Since I also have BuddyPress, my solution is so.

I added this code to the functions.php of the Childtheme.

 

// Funktion, um bei BuddyPress zu sehen wann man sich registriert hat.
function bp_show_registration_date() {
$user_id = bp_displayed_user_id();
$user_data = get_userdata($user_id);
$registered = $user_data->user_registered;
echo ‘<br/><b>Mitglied seit:</b> ‘ . date(“d.m.Y”, strtotime($registered));
}
add_action(‘bp_before_member_header_meta’, ‘bp_show_registration_date’);

 

You can find the registration date in BuddyPress’s profile.

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.

OK, this is your file, but where do I add the one that recommends @asgaros ? I also want to add that I do not have BuddyPress.