Make WordPress Core

Opened 10 years ago

Closed 10 years ago

#27578 closed defect (bug) (duplicate)

Editing a draft does not set `post_date_gmt`, but quick editing a draft does

Reported by: denis-de-bernardy's profile Denis-de-Bernardy Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.9
Component: Posts, Post Types Keywords: has-patch needs-unit-tests
Focuses: administration Cc:

Description

(It's all in the title…)

Attachments (1)

27578.diff (519 bytes) - added by Denis-de-Bernardy 10 years ago.

Download all attachments as: .zip

Change History (7)

#1 @Denis-de-Bernardy
10 years ago

As a bonus, too, you cannot clear the date of the draft to make it so that it gets published immediately: you need to manually set the date to whenever.

Last edited 10 years ago by Denis-de-Bernardy (previous) (diff)

#2 @Denis-de-Bernardy
10 years ago

Trashing a draft sets its post_date_gmt field as well:

  1. Create a draft.
  2. Trash it.
  3. Restore it.
  4. The date no longer offers to publish immediately

#3 @Denis-de-Bernardy
10 years ago

A fix to all of these (bar clearing the date, but it works around the problem) is to change the following in wp_insert_post():

	if ( empty($post_date_gmt) || '0000-00-00 00:00:00' == $post_date_gmt ) {
		if ( !in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) )
			$post_date_gmt = get_gmt_from_date($post_date);
		else
			$post_date_gmt = '0000-00-00 00:00:00';
	}

To:

	if ( empty($post_date_gmt) || '0000-00-00 00:00:00' == $post_date_gmt ) {
		if ( !in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) )
			$post_date_gmt = get_gmt_from_date($post_date);
		else
			$post_date_gmt = '0000-00-00 00:00:00';
	}
	elseif ( in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) ) {
		$post_date_gmt = '0000-00-00 00:00:00';
	}
Last edited 10 years ago by Denis-de-Bernardy (previous) (diff)

#4 @Denis-de-Bernardy
10 years ago

Patch attached.

#5 @nacin
10 years ago

  • Keywords has-patch needs-unit-tests added

#6 @SergeyBiryukov
10 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #19907.

Note: See TracTickets for help on using tickets.