[wp-trac] [WordPress Trac] #62468: wp_update_post overwrites post_date when updating post_status

WordPress Trac noreply at wordpress.org
Mon Nov 18 22:29:51 UTC 2024


#62468: wp_update_post overwrites post_date when updating post_status
-------------------------------------------------+-------------------------
 Reporter:  aguerra07                            |      Owner:  (none)
     Type:  defect (bug)                         |     Status:  new
 Priority:  normal                               |  Milestone:  Awaiting
                                                 |  Review
Component:  Posts, Post Types                    |    Version:  6.7
 Severity:  normal                               |   Keywords:  has-patch
  Focuses:  performance, coding-standards, php-  |  needs-testing
  compatibility                                  |
-------------------------------------------------+-------------------------
 **Steps to reproduce the bug:**
 1. Create a post with the status `pending`.
 2. Use `wp_update_post` to update the post status to `future` and set
 `post_date` to a specific future date.
 3. Observe that the `post_date` value is reset, and the post is
 immediately published.

 **Expected behavior:**
 When updating the post status to `future` and setting a future
 `post_date`, the post should be scheduled for publication at the specified
 date and not published immediately.

 **Actual behavior:**
 The `post_date` is recalculated based on the current date and time due to
 the existing post status, causing the post to be published immediately.

 **Cause:**
 The `wp_update_post` function uses the current post status to determine
 whether the `post_date` should be modified. This logic does not account
 for updates to the post status in the same operation.

 **Suggested fix:**
 Adjust the logic in `wp_update_post` to prioritize updates to the post
 status before checking conditions that modify the `post_date`. Adding the
 `edit_date` flag to enforce the use of the provided `post_date` is a
 temporary workaround, but a deeper fix is needed to handle this logic
 cleanly.

 **Patch:**
 A proposed patch file is attached, which modifies the `wp_update_post`
 function to handle this scenario correctly.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/62468>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list