WordPress.org

Make WordPress Core

Opened 8 weeks ago

Closed 6 weeks ago

Last modified 6 weeks ago

#48097 closed defect (bug) (invalid)

Fix `user_registered` in WP_Insert_User function

Reported by: mehrshaddarzi Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Date/Time Keywords:
Focuses: Cc:
PR Number:

Description

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 8 weeks ago.

Download all attachments as: .zip

Change History (5)

@mehrshaddarzi
8 weeks ago

#1 @SergeyBiryukov
8 weeks 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
8 weeks ago

@SergeyBiryukov

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 https://core.trac.wordpress.org/browser/tags/5.2.3/src/wp-includes/post.php?marks=3541#L3541 .The post_date that entered into the database exactly on the local WordPress Time.

#3 @jrf
6 weeks ago

@rarst Maybe something you want to look at ? 👆

#4 @Rarst
6 weeks 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 6 weeks ago by Rarst (previous) (diff)
Note: See TracTickets for help on using tickets.