Make WordPress Core

Changeset 46795 for trunk


Ignore:
Timestamp:
11/28/2019 01:40:19 PM (5 years ago)
Author:
SergeyBiryukov
Message:

Date/Time: Make get_permalink() more resilient against PHP timezone changes.

Overriding default PHP timezone with date_default_timezone_set(), while not recommended, should not inadvertently result in changing existing permalinks.

Add a unit test.

Props Rarst, steevithak, archon810, maciejmackowiak, Ov3rfly, Cybr, hometowntrailers, scvleon, miette49.
Fixes #48623.

Location:
trunk
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/link-template.php

    r46383 r46795  
    167167
    168168    if ( '' != $permalink && ! in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft', 'future' ) ) ) {
    169         $unixtime = strtotime( $post->post_date );
    170169
    171170        $category = '';
     
    213212        }
    214213
    215         $date           = explode( ' ', gmdate( 'Y m d H i s', $unixtime ) );
    216         $rewritereplace =
    217         array(
     214        // This is not an API call because the permalink is based on the stored post_date value,
     215        // which should be parsed as local time regardless of the default PHP timezone.
     216        $date = explode( ' ', str_replace( array( '-', ':' ), ' ', $post->post_date ) );
     217
     218        $rewritereplace = array(
    218219            $date[0],
    219220            $date[1],
     
    228229            $post->post_name,
    229230        );
    230         $permalink      = home_url( str_replace( $rewritecode, $rewritereplace, $permalink ) );
    231         $permalink      = user_trailingslashit( $permalink, 'single' );
     231
     232        $permalink = home_url( str_replace( $rewritecode, $rewritereplace, $permalink ) );
     233        $permalink = user_trailingslashit( $permalink, 'single' );
     234
    232235    } else { // if they're not using the fancy permalink option
    233236        $permalink = home_url( '?p=' . $post->ID );
Note: See TracChangeset for help on using the changeset viewer.