Make WordPress Core

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#48097 closed defect (bug) (invalid)

Fix `user_registered` in WP_Insert_User function

Reported by: mehrshaddarzi's profile mehrshaddarzi Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Date/Time Keywords:
Focuses: Cc:


The WordPress local date [get_option( 'gmt_offset' ) * HOUR_IN_SECONDS] is not specified in the WordPress wp_insert_user function in user_registered parameter.

The wp-includes/user.php in Line 1724 is :

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

change to :

$user_registered = empty( $userdata['user_registered'] ) ? current_time( 'mysql' ) : $userdata['user_registered'];

Attachments (1)

48097.patch (751 bytes) - added by mehrshaddarzi 5 years ago.

Download all attachments as: .zip

Change History (5)

5 years ago

#1 @SergeyBiryukov
5 years ago

  • Keywords reporter-feedback added

Hi @mehrshaddarzi, welcome to WordPress Trac! Thanks for the patch.

Looking at the documentation for wp_pre_insert_user_data filter, the user_registered parameter is intentionally a UTC timestamp, not a local time.

Could you describe the problem the patch solves?

#2 @mehrshaddarzi
5 years ago


Yes, but this is a mistake because the gmdate() PHP function not considered WordPress gmt_offset Option.hense the correct time of registration is not entered into the database. If you see other functions such as wp_insert_post function .The post_date that entered into the database exactly on the local WordPress Time.

#3 @jrf
5 years ago

@rarst Maybe something you want to look at ? 👆

#4 @Rarst
5 years ago

  • Component changed from Users to Date/Time
  • Keywords has-patch reporter-feedback removed
  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

For some reason I got a really delayed ping...

Sergey is correct, user creation times are explicitly meant to be in UTC in database. I don't know why, but that's the way it is set up and documented. :)

These are not consistent with posts table, e.g. there are not separate local and UTC time fields.

I suspect there very well might be issues with treating them as local time here and there through core. If so that should be reported and fixed as output bug. The storage is working as documented.

Last edited 5 years ago by Rarst (previous) (diff)
Note: See TracTickets for help on using tickets.