Title: [Plugin: Edit Flow] Custom statuses create timestamp problem
Last modified: August 19, 2016

---

# [Plugin: Edit Flow] Custom statuses create timestamp problem

 *  Resolved [ebedgert](https://wordpress.org/support/users/ebedgert/)
 * (@ebedgert)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/plugin-edit-flow-custom-statuses-create-timestamp-problem/)
 * The editors on our website have become very reliant on the custom statuses in
   EditFlow (we have the initial version). However, I noticed that EditFlow’s custom
   statuses automatically apply a timestamp to a post even if it has not yet been
   published. This timestamp is “sticky” and cannot be removed by going back into
   Draft status. It can only be edited manually. (By comparison, in WordPress without
   custom statuses, Draft and Pending do not attach a timestamp.)
 * This sometimes causes a problem because the story will sit in the editing queue
   for days with the timestamp of its creation, but the editors will forget to manually
   change the timestamp before publishing the story. So, a story that was published
   on Oct 19 will say Oct 15 (the day the post was created and given a custom status).
   This has caused some problems with story display on the website (it doesn’t show
   up where expected); also broken links when we include the wrong-dated story in
   an email, and then someone realizes the date is wrong and changes it manually.(
   I’d like the editors to just remember to change the date manually before publishing,
   but there’s only so many times you can tell ’em…)
 * Is this something that can be addressed in a future version? I’m not sure why
   posts in an unpublished state need to have a timestamp automatically affixed 
   to them. I’d like to be able to use the “Publish Immediately” option from posts
   that are in a custom status state, but currently that doesn’t seem possible (
   unless this has been dealt with in a subsequent release already).
 * [http://wordpress.org/extend/plugins/edit-flow/](http://wordpress.org/extend/plugins/edit-flow/)

Viewing 2 replies - 46 through 47 (of 47 total)

[←](https://wordpress.org/support/topic/plugin-edit-flow-custom-statuses-create-timestamp-problem/page/3/?output_format=md)
[1](https://wordpress.org/support/topic/plugin-edit-flow-custom-statuses-create-timestamp-problem/?output_format=md)
[2](https://wordpress.org/support/topic/plugin-edit-flow-custom-statuses-create-timestamp-problem/page/2/?output_format=md)
[3](https://wordpress.org/support/topic/plugin-edit-flow-custom-statuses-create-timestamp-problem/page/3/?output_format=md)
4

 *  [saomay](https://wordpress.org/support/users/saomay/)
 * (@saomay)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/plugin-edit-flow-custom-statuses-create-timestamp-problem/page/4/#post-1728640)
 * Hi Daniel,
 * Is there a way you can send it to me at rougesmoke (at) yahoo.com so in that 
   way you can continue with the next release? Thanks for considering.
 * David.
 *  Plugin Contributor [Daniel Bachhuber](https://wordpress.org/support/users/danielbachhuber/)
 * (@danielbachhuber)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/plugin-edit-flow-custom-statuses-create-timestamp-problem/page/4/#post-1728641)
 * Not a problem, here it is:
 *     ```
       add_action( 'admin_init', 'ef_check_timestamp_on_publish' );
       add_filter( 'wp_insert_post_data', 'ef_fix_custom_status_timestamp' );
       /**
        * This is a hack! hack! hack! until core is fixed/better supports custom statuses
        *
        * When publishing a post with a custom status, set the status to 'pending' temporarily
        * Works around this limitation: http://core.trac.wordpress.org/browser/tags/3.2.1/wp-includes/post.php#L2694
        * Original thread: http://wordpress.org/support/topic/plugin-edit-flow-custom-statuses-create-timestamp-problem
        * Core ticket: http://core.trac.wordpress.org/ticket/18362
        */
       function ef_check_timestamp_on_publish() {
       	global $edit_flow, $pagenow, $wpdb;
   
       	// Handles the transition to 'publish' on edit.php
       	if ( isset( $edit_flow ) && $pagenow == 'edit.php' && isset( $_REQUEST['bulk_edit'] ) ) {
       		// For every post_id, set the post_status as 'pending' only when there's no timestamp set for $post_date_gmt
       		if ( $_REQUEST['_status'] == 'publish' ) {
       			$post_ids = array_map( 'intval', (array) $_REQUEST['post'] );
       			foreach ( $post_ids as $post_id ) {
       				$wpdb->update( $wpdb->posts, array( 'post_status' => 'pending' ), array( 'ID' => $post_id, 'post_date_gmt' => '0000-00-00 00:00:00' ) );
       			}
       		}
       	}
   
       	// Handles the transition to 'publish' on post.php
       	if ( isset( $edit_flow ) && $pagenow == 'post.php' && isset( $_POST['publish'] ) ) {
       		// Set the post_status as 'pending' only when there's no timestamp set for $post_date_gmt
       		if ( isset( $_POST['post_ID'] ) ) {
       			$post_id = (int) $_POST['post_ID'];
       			$wpdb->update( $wpdb->posts, array( 'post_status' => 'pending' ), array( 'ID' => $post_id, 'post_date_gmt' => '0000-00-00 00:00:00' ) );
       		}
       	}
   
       }
       /**
        * This is a hack! hack! hack! until core is fixed/better supports custom statuses
        *
        * Normalize post_date_gmt if it isn't set to the past or the future
        * Works around this limitation: http://core.trac.wordpress.org/browser/tags/3.2.1/wp-includes/post.php#L2506
        * Original thread: http://wordpress.org/support/topic/plugin-edit-flow-custom-statuses-create-timestamp-problem
        * Core ticket: http://core.trac.wordpress.org/ticket/18362
        */
       function ef_fix_custom_status_timestamp( $data ) {
       	global $edit_flow, $pagenow;
       	// Don't run this if Edit Flow isn't active, or we're on some other page
       	if ( !isset( $edit_flow ) || $pagenow != 'post.php' || !isset( $_POST ) )
       		return $data;
       	$custom_statuses = get_terms( 'post_status', array( 'get' => 'all' ) );
       	$status_slugs = array();
       	foreach( $custom_statuses as $custom_status )
       	    $status_slugs[] = $custom_status->slug;
       	$ef_normalize_post_date_gmt = true;
       	// We're only going to normalize the post_date_gmt if the user hasn't set a custom date in the metabox
       	// and the current post_date_gmt isn't already future or past-ized
       	foreach ( array('aa', 'mm', 'jj', 'hh', 'mn') as $timeunit ) {
       		if ( !empty( $_POST['hidden_' . $timeunit] ) && (($_POST['hidden_' . $timeunit] != $_POST[$timeunit] ) || ( $_POST['hidden_' . $timeunit] != $_POST['cur_' . $timeunit] )) ) {
       			$ef_normalize_post_date_gmt = false;
       			break;
       		}
       	}
       	if ( $ef_normalize_post_date_gmt )
       		if ( in_array( $data['post_status'], $status_slugs ) )
       			$data['post_date_gmt'] = '0000-00-00 00:00:00';
       	return $data;
       }
       ```
   

Viewing 2 replies - 46 through 47 (of 47 total)

[←](https://wordpress.org/support/topic/plugin-edit-flow-custom-statuses-create-timestamp-problem/page/3/?output_format=md)
[1](https://wordpress.org/support/topic/plugin-edit-flow-custom-statuses-create-timestamp-problem/?output_format=md)
[2](https://wordpress.org/support/topic/plugin-edit-flow-custom-statuses-create-timestamp-problem/page/2/?output_format=md)
[3](https://wordpress.org/support/topic/plugin-edit-flow-custom-statuses-create-timestamp-problem/page/3/?output_format=md)
4

The topic ‘[Plugin: Edit Flow] Custom statuses create timestamp problem’ is closed
to new replies.

 * ![](https://ps.w.org/edit-flow/assets/icon-256x256.png?rev=3433533)
 * [Edit Flow](https://wordpress.org/plugins/edit-flow/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/edit-flow/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/edit-flow/)
 * [Active Topics](https://wordpress.org/support/plugin/edit-flow/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/edit-flow/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/edit-flow/reviews/)

## Tags

 * [bugs](https://wordpress.org/support/topic-tag/bugs/)
 * [custom statuses](https://wordpress.org/support/topic-tag/custom-statuses/)

 * 47 replies
 * 6 participants
 * Last reply from: [Daniel Bachhuber](https://wordpress.org/support/users/danielbachhuber/)
 * Last activity: [14 years, 9 months ago](https://wordpress.org/support/topic/plugin-edit-flow-custom-statuses-create-timestamp-problem/page/4/#post-1728641)
 * Status: resolved