Support » Plugin: Edit Flow » [Plugin: Edit Flow] Custom statuses create timestamp problem

  • Resolved ebedgert

    (@ebedgert)


    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/

Viewing 15 replies - 1 through 15 (of 47 total)
  • Plugin Author Daniel Bachhuber

    (@danielbachhuber)

    Hand Built

    Hey, if this is still an issue for you, which version of Edit Flow are you using?

    Thanks,

    Daniel

    nycgadgetgirl

    (@nycgadgetgirl)

    I’ve noticed this as well and have the same problem with posts being published with the wrong date because of it. I’m using Edit Flow 0.6.2 in WordPress 3.1

    Has a fix been found for this? I’m also having trouble with this problem. Do share!

    Not AFAIK. I’m now using WordPress 3.1.1 and Edit Flow 0.6.3 and still have this problem.

    Hi,

    This is still an issue; I am using wp 3.2.1 and Edit Flow 0.6.4. Please help! Thanks.

    Plugin Author Daniel Bachhuber

    (@danielbachhuber)

    Hand Built

    Hey folks,
    I did some testing this morning, confirmed the bug, and discovered the source of the problem. Unfortunately, it’s a WordPress core bug that we can’t easily provide a fix for. Here are the two tickets I’ve filed:

    If you’re interested in the technical details, I’d recommend checking those out. I’ll update this thread if/when they get fixed and committed.

    Cheers,

    Daniel

    Daniel, thank you for putting in the time and effort to track this down and report it to WordPress!

    Plugin Author Daniel Bachhuber

    (@danielbachhuber)

    Hand Built

    Nevermind, I think I have a temporary fix for this. Let me test it and get back to you.

    Plugin Author Daniel Bachhuber

    (@danielbachhuber)

    Hand Built

    Hey folks,
    I think you’re in luck. If you copy and paste the following snippet into your theme’s functions.php file, it should fix the timestamps bug:

    function ef_fix_custom_status_timestamp( $data ) {
    	global $edit_flow;
    	// Don't run this if Edit Flow isn't active
    	if ( !isset( $edit_flow ) )
    		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;
    	}
    	// Fix for a core bug. See: http://core.trac.wordpress.org/ticket/18361
    	if ( in_array( $data['post_status'], $status_slugs ) ) {
    		$data['post_date_gmt'] = '0000-00-00 00:00:00';
    	}
    	return $data;
    }
    add_filter( 'wp_insert_post_data', 'ef_fix_custom_status_timestamp' );

    Please confirm one way or another.

    Thanks,

    Daniel

    Hi Daniel,

    I tested several times and here are my findings:

    1. Switching between different statuses e.g. from Pending Review (which is WP default status) to Pending Publication now does not show “Published on:….” and instead just like how I think it should be which is “Publish Immediately” (since the post has not been published). This is a good thing!

    However, after several hours have passed, I decided to publish a few “test” articles in Pending Publication status and found that those carried and displayed the timestamp at the time when I switched them from Pending Review to Pending Publication. I thought I made some mistakes but repeated tests conclusively showed the same result. So all I can say is that moving articles from a WP statuses like Draft or Pending Review to Pending Publication or any other custom statuses controlled by Edit Flow still automatically affixes a timestamp to the post – and when you pulbish the post it carries the old affixed timestamp not the current one.

    2. So I thought maybe I just deal with WP statuses ONLY like changing current drafts from Draft to Pending Review, waited for a couple hours and then published them. The result in this case showed correctly the current timestamp at the time of publication; thus, based on my testing, I assume using the WP statuses won’t cause this issue.

    3. Then I decided to do a bit research on the internet and found out that you can actually change the meta-box or UI of the statuses concerning the timestamp by messing around and changing this code in wp-admin/includes/meta-boxes.php:

    From this:

    } else { // draft, 1 or more saves, date specified
    		$stamp = __('Publish on: <b>%1$s</b>');
    	}
    	$date = date_i18n( $datef, strtotime( $post->post_date ) );

    To this:

    } else { // draft, 1 or more saves, date specified
    		$stamp = __('Publish <b>immediately</b>');
           $date = date_i18n( $datef, strtotime( $post->post_date ) );

    and you would also get the “Publish Immediately” for every status. However, the problem still persists as soon as you switch from a WP status Draft or Pending Review to any of Edit Flow’s custom status the timestamp get affixed immediately and will be registered as the published timestamp at the time of publication.

    So in a nutshell, even though the fix shows “Publish Immediately” but the timestamp still gets affixed to the post as soon as you change from Draft or Pending Review to any of the Edit Flow’s custom statuses.

    Sorry for the long post but hopefully this helps you to understand and find a solution. Thanks so much for your time and patience.

    David

    Also, if you look at this code from the same file wp-admin/includes/meta-boxes:

    <?php
    // translators: Publish box date formt, see http://php.net/date
    $datef = __( 'M j, Y @ G:i' );
    if ( 0 != $post->ID ) {
    	if ( 'future' == $post->post_status ) { // scheduled for publishing at a future date
    		$stamp = __('Scheduled for: <b>%1$s</b>');
    	} else if ( 'publish' == $post->post_status || 'private' == $post->post_status ) { // already published
    		$stamp = __('Published on: <b>%1$s</b>');
    	} else if ( '0000-00-00 00:00:00' == $post->post_date_gmt ) { // draft, 1 or more saves, no date specified
    		$stamp = __('Publish <b>immediately</b>');
    	} else if ( time() < strtotime( $post->post_date_gmt . ' +0000' ) ) { // draft, 1 or more saves, future date specified
    		$stamp = __('Schedule for: <b>%1$s</b>');
    	} else { // draft, 1 or more saves, date specified
    		$stamp = __('Publish on: <b>%1$s</b>');
    	}
    	$date = date_i18n( $datef, strtotime( $post->post_date ) );
    } else { // draft (no saves, and thus no date specified)
    	$stamp = __('Publish <b>immediately</b>');
    	$date = date_i18n( $datef, strtotime( current_time('mysql') ) );
    }

    You see this particular comment: // draft, 1 or more saves, date specified at the top of these three lines:

    } else { // draft, 1 or more saves, date specified
    		$stamp = __('Publish on: <b>%1$s</b>');
    	}
    	$date = date_i18n( $datef, strtotime( $post->post_date ) );

    I assume that as you switch from a WP Draft or Pending Review status to any of the Edit Flow’s custom ones, it automatically adds the timestamp based on this logic stated by the comment – but this is only my assumption.

    So if it is the case, then can we remove that “multiple” save option within these three lines and thereby solve the issue?

    Plugin Author Daniel Bachhuber

    (@danielbachhuber)

    Hand Built

    Taking another look. Changing core code in the metabox unfortunately won’t solve the problem. It’s wonkiness with how the post data is being saved…

    Plugin Author Daniel Bachhuber

    (@danielbachhuber)

    Hand Built

    Hey folks,
    I worked on this for a couple more hours this morning and produced a better patch/hack. Replace the method above with this new one and let me know what you think:

    /**
     * Normalize post_date_gmt if it isn't set to the past or the future, and bump timestamp if it's set to a nonsense date
     * Original thread: http://wordpress.org/support/topic/plugin-edit-flow-custom-statuses-create-timestamp-problem
     * Core ticket: http://core.trac.wordpress.org/ticket/18361
     */
    function ef_fix_custom_status_timestamp( $data ) {
    	global $edit_flow, $ef_normalize_post_date_gmt, $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';
    	$status_slugs[] = 'auto-draft';
    	// On publish, update the post_date timestamp if post_date_gmt is set to a nonsense date
    	if ( in_array( $data['post_status'], $status_slugs ) && ( '0000-00-00 00:00:00' == $data['post_date_gmt'] ) && isset( $_POST['publish'] ) )
    		$data['post_date'] = current_time('mysql');
    	return $data;
    }
    add_filter( 'wp_insert_post_data', 'ef_fix_custom_status_timestamp' );

    Cheers,

    Daniel

    Hi Daniel,

    I still got the timestamp affixed automatically when changing to any of the Edit Flow’s custom statuses even thought it shows “Publish Immediately” versus Published On:…; and that timestamp is recorded as published date when publishing. I ran several tests for the last couple hours and got the same results.

    Plugin Author Daniel Bachhuber

    (@danielbachhuber)

    Hand Built

    Did you create new posts for your tests or use previously existing posts? If the latter, there’s unfortunately not much we can do but the former should be fixed now (or at least according to my testing).

Viewing 15 replies - 1 through 15 (of 47 total)
  • The topic ‘[Plugin: Edit Flow] Custom statuses create timestamp problem’ is closed to new replies.