Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),

### Fixed

* fix: update post date to current time when publishing from custom status by @GaryJones in [#856](https://github.com/Automattic/Edit-Flow/pull/856)
* fix: resolve calendar drag-and-drop not persisting post date changes by @GaryJones in [#854](https://github.com/Automattic/Edit-Flow/pull/854)
* fix: guard against null return from get_edit_post_link() and get_permalink() by @GaryJones in [#853](https://github.com/Automattic/Edit-Flow/pull/853)
* fix: prevent get_custom_statuses() from corrupting WordPress's term cache by @GaryJones in [#852](https://github.com/Automattic/Edit-Flow/pull/852)
Expand Down
58 changes: 58 additions & 0 deletions modules/custom-status/custom-status.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public function init() {
add_action( 'admin_init', [ $this, 'check_timestamp_on_publish' ] );
add_filter( 'wp_insert_post_data', [ $this, 'fix_custom_status_timestamp' ], 10, 2 );
add_filter( 'wp_insert_post_data', [ $this, 'maybe_keep_post_name_empty' ], 10, 2 );
add_filter( 'wp_insert_post_data', [ $this, 'update_post_date_on_publish_from_custom_status' ], 10, 2 );
add_filter( 'pre_wp_unique_post_slug', [ $this, 'fix_unique_post_slug' ], 10, 6 );
add_filter( 'preview_post_link', [ $this, 'fix_preview_link_part_one' ] );
add_filter( 'post_link', [ $this, 'fix_preview_link_part_two' ], 10, 3 );
Expand Down Expand Up @@ -1396,6 +1397,63 @@ public function fix_custom_status_timestamp( $data, $postarr ) {
return $data;
}

/**
* Update post_date to current time when publishing from a custom status.
*
* When a post with a custom status (like "Pitch" or "Assigned") is published,
* the post_date should reflect the actual publication time, not the original
* creation time. This matches WordPress core behavior for 'draft' and 'pending'.
*
* @since 0.10.0
*
* @see https://github.com/Automattic/Edit-Flow/issues/750
*
* @param array $data An array of slashed, sanitized post data.
* @param array $postarr An array of sanitized post data.
* @return array Modified post data with updated post_date if applicable.
*/
public function update_post_date_on_publish_from_custom_status( $data, $postarr ) {
// Only process when transitioning to 'publish' status.
if ( 'publish' !== $data['post_status'] ) {
return $data;
}

// Must be an existing post (have an ID) for this to be a status transition.
if ( empty( $postarr['ID'] ) ) {
return $data;
}

// Get the current post from the database to check its current status.
$current_post = get_post( $postarr['ID'] );
if ( ! $current_post ) {
return $data;
}

// If already published, scheduled, or private, don't change the date.
$published_statuses = [ 'publish', 'future', 'private' ];
if ( in_array( $current_post->post_status, $published_statuses, true ) ) {
return $data;
}

// If the post had an explicitly set GMT date (scheduled), don't change it.
if ( ! empty( $current_post->post_date_gmt )
&& '0000-00-00 00:00:00' !== $current_post->post_date_gmt ) {
return $data;
}

// If the user is explicitly setting a different date in this update, respect it.
// Compare the incoming post_date with the current post_date.
if ( ! empty( $postarr['post_date'] ) && $postarr['post_date'] !== $current_post->post_date ) {
return $data;
}

// Update post_date to current time.
$data['post_date'] = current_time( 'mysql' );
$data['post_date_gmt'] = current_time( 'mysql', true );

return $data;
}

/**
* A new hack! hack! hack! until core better supports custom statuses`
*
Expand Down
Loading
Loading