WordPress.org

Make WordPress Core

Opened 12 months ago

Last modified 10 months ago

#45047 new enhancement

user_registered returned as UTC Time instead of Local Time

Reported by: kcrnc Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Users Keywords:
Focuses: Cc:

Description

I apologize if this has been discussed/covered before or I am missing something obvious, but I did a few searches, both through the code base and also bug-tracker/google, and couldn't find anything on this subject.

While trying to debug a timezone issue for a client, I noticed that user_registered appears to be set to GMT/UTC time by default, rather than the local time set via settings.

I searched the code and found where I think this is set:

wp-includes/user.php

<?php
        $user_registered = empty( $userdata['user_registered'] ) ? gmdate( 'Y-m-d H:i:s' ) : $userdata['user_registered'];

I also tested adding a user on a relatively clean site via the default add user option and verified it gets set to UTC, regardless of the local time setting in wordpress.

So, when you grab the user via get_userdata(), the $user_data->user_registered field looks like it will always be UTC time, unless presumably the user is created manually(wp_create_user or equivalent) and you set the time during creation.

I think setting it in ALL cases to UTC probably makes sense, as you never know when a person is going to change their timezone settings in wordpress, the settings on their server, etc. And, timezones can be a pain to work with in general, so having it be UTC by default makes sense.

However, when returning it back to the end-user, it would be useful to have it take into account their local timezone setting in WordPress, at least by maybe adding a $user_data->user_registered_local field to the user object.

Change History (1)

#1 @SergeyBiryukov
10 months ago

  • Summary changed from user_registered returned as UTC Timeinstead of Local Time to user_registered returned as UTC Time instead of Local Time
Note: See TracTickets for help on using tickets.