[wp-trac] [WordPress Trac] #45047: user_registered returned as UTC Timeinstead of Local Time
WordPress Trac
noreply at wordpress.org
Thu Oct 4 13:01:32 UTC 2018
#45047: user_registered returned as UTC Timeinstead of Local Time
-------------------------+-----------------------------
Reporter: kcrnc | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Users | Version:
Severity: normal | Keywords:
Focuses: |
-------------------------+-----------------------------
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
<?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.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/45047>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list