Date/Time: Replace all instances of date() with gmdate().

Use of `date()` in core depends on PHP timezone set to UTC and not changed by third party code (which cannot be guaranteed).

`gmdate()` is functionally equivalent, but is not affected by PHP timezone setting: it's always UTC, which is the exact behavior the core needs.

Props nielsdeblaauw, Rarst.
Fixes #46438. See #44491.
Built from https://develop.svn.wordpress.org/trunk@45424


git-svn-id: http://core.svn.wordpress.org/trunk@45235 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov
2019-05-26 00:12:54 +00:00
parent 17cc8cd0f8
commit c77e771c84
26 changed files with 60 additions and 60 deletions

View File

@@ -6031,8 +6031,8 @@ function wp_check_for_changed_slugs( $post_id, $post, $post_before ) {
* @param WP_Post $post_before The Previous Post Object
*/
function wp_check_for_changed_dates( $post_id, $post, $post_before ) {
$previous_date = date( 'Y-m-d', strtotime( $post_before->post_date ) );
$new_date = date( 'Y-m-d', strtotime( $post->post_date ) );
$previous_date = gmdate( 'Y-m-d', strtotime( $post_before->post_date ) );
$new_date = gmdate( 'Y-m-d', strtotime( $post->post_date ) );
// Don't bother if it hasn't changed.
if ( $new_date == $previous_date ) {
return;
@@ -6286,7 +6286,7 @@ function _get_last_post_time( $timezone, $field, $post_type = 'any' ) {
$date = $wpdb->get_var( "SELECT post_{$field} FROM $wpdb->posts WHERE post_status = 'publish' AND post_type IN ({$post_types}) ORDER BY post_{$field}_gmt DESC LIMIT 1" );
break;
case 'server':
$add_seconds_server = date( 'Z' );
$add_seconds_server = gmdate( 'Z' );
$date = $wpdb->get_var( "SELECT DATE_ADD(post_{$field}_gmt, INTERVAL '$add_seconds_server' SECOND) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type IN ({$post_types}) ORDER BY post_{$field}_gmt DESC LIMIT 1" );
break;
}