Make WordPress Core

Opened 7 years ago

Closed 4 months ago

#47307 closed defect (bug) (worksforme)

wp_insert_post: status 'future' is saved although 'publish' selected

Reported by: daniol's profile daniol Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.1
Component: Posts, Post Types Keywords: has-patch
Focuses: administration Cc:

Description

If I change the title of the page using the customizer, the changes are not saved because the changeset post is saved with status 'future' although 'publish' selected.

I debugged the issue and found the following fragment of code of wp_insert_post is causing the issue:

<?php
if ( mysql2date( 'U', $post_date_gmt, false ) > mysql2date( 'U', $now, false ) ) {
 $post_status = 'future';
}

This piece of code has no sense, because when the status is set as "publish", we don't want to change artificially to "future" because the publish date is now.

It seems an issue with some versions of PHP/MYSQL, since is working on my local host (Windows) but not on the production server (PHP7.0, Ubuntu).

I debugged the components of the comparison:

$now => 2019-05-17 16:32:59
$post_date_gmt => 2019-05-17 18:32:59
mysql2date( 'U', $post_date_gmt, false ) => 1558110779
mysql2date( 'U', $now, false ) => 1558103579

The date/time configuration of the server is:

root@srvde1 ~ # date
Fri May 17 18:33:24 CEST 2019

There are other affected users over the years, searching on the Internet "customizer does not save changes".

Attachments (1)

status_published_date_fix.patch (774 bytes) - added by daniol 7 years ago.
Fix patch (V. 5.2)

Download all attachments as: .zip

Change History (2)

@daniol
7 years ago

Fix patch (V. 5.2)

#1 @SirLouen
4 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed
  • Version changed from 5.2 to 2.1

Reproduction Report

Description

❌ This report can't validate that the issue can be reproduced.

Environment

  • WordPress: 6.9-alpha-60093-src
  • PHP: 8.2.29
  • Server: nginx/1.29.1
  • Database: mysqli (Server: 8.4.6 / Client: mysqlnd 8.2.29)
  • Browser: Chrome 140.0.0.0
  • OS: Windows 10/11
  • Theme: Twenty Twenty 2.9
  • MU Plugins: None activated
  • Plugins:
    • Test Reports 1.2.0

Testing Instructions

  1. Change the timezone in Settings > General
  2. Confirm that the server has the same timezone with date
  3. Change the title of the site in the Customizer
  4. 👌 Title is changed correctly, the future assignment is not triggered.

Actual Results

  1. ❌ Error condition does not occur anymore.

Additional Notes

  1. PHP 7.0 is not supported anymore
  2. Looking at the code, this thing was introduced 20 years ago in #2426/[3514]. But it has undergone many changes, including this last one [46968], some months after, which could be the culprit.
Note: See TracTickets for help on using tickets.