Make WordPress Core

Ticket #35874: fix-update-post.patch

File fix-update-post.patch, 1.3 KB (added by redsweater, 8 years ago)

Fixes to wp_update_post to prevent accidentally stripping the date from posts

  • src/wp-includes/post.php

    diff --git src/wp-includes/post.php src/wp-includes/post.php
    index 6360735..4997766 100644
    function wp_update_post( $postarr = array(), $wp_error = false ) { 
    35383538                $post_cats = $post['post_category'];
    35393539
    35403540        // Drafts shouldn't be assigned a date unless explicitly done so by the user.
    3541         if ( isset( $post['post_status'] ) && in_array($post['post_status'], array('draft', 'pending', 'auto-draft')) && empty($postarr['edit_date']) &&
    3542                          ('0000-00-00 00:00:00' == $post['post_date_gmt']) )
    3543                 $clear_date = true;
    3544         else
    3545                 $clear_date = false;
     3541        $clear_date = false;
     3542        if ( isset( $post['post_status'] ) && in_array($post['post_status'], array('draft', 'pending', 'auto-draft')) ) {
     3543                // edit_date will only be set for date edits made throug wp-admin, not through XMRLPC API
     3544                $missing_admin_edit_flag = empty( $postarr['edit_date'] );
     3545                $missing_post_date = ( '0000-00-00 00:00:00' == $post['post_date_gmt'] );
     3546                $missing_post_date_gmt = ( '0000-00-00 00:00:00' == $post['post_date'] );
     3547                if ( $missing_admin_edit_flag && $missing_post_date && $missing_post_date_gmt ) {
     3548                        $clear_date = true;
     3549                }
     3550        }
    35463551
    35473552        // Merge old and new fields with new fields overwriting old ones.
    35483553        $postarr = array_merge($post, $postarr);