WordPress.org

Ready to get started?Download WordPress

Forums

Edit Flow
[resolved] Custom statuses create timestamp problem (48 posts)

  1. ebedgert
    Member
    Posted 3 years ago #

    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/

  2. Daniel Bachhuber
    Hand Built
    Plugin Author

    Posted 3 years ago #

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

    Thanks,

    Daniel

  3. nycgadgetgirl
    Member
    Posted 3 years ago #

    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

  4. mirakelsey
    Member
    Posted 3 years ago #

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

  5. nycgadgetgirl
    Member
    Posted 3 years ago #

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

  6. saomay
    Member
    Posted 3 years ago #

    Hi,

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

  7. Daniel Bachhuber
    Hand Built
    Plugin Author

    Posted 3 years ago #

    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

  8. nycgadgetgirl
    Member
    Posted 3 years ago #

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

  9. Daniel Bachhuber
    Hand Built
    Plugin Author

    Posted 3 years ago #

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

  10. Daniel Bachhuber
    Hand Built
    Plugin Author

    Posted 3 years ago #

    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

  11. saomay
    Member
    Posted 3 years ago #

    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

  12. saomay
    Member
    Posted 3 years ago #

    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?

  13. Daniel Bachhuber
    Hand Built
    Plugin Author

    Posted 3 years ago #

    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...

  14. Daniel Bachhuber
    Hand Built
    Plugin Author

    Posted 3 years ago #

    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

  15. saomay
    Member
    Posted 3 years ago #

    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.

  16. Daniel Bachhuber
    Hand Built
    Plugin Author

    Posted 3 years ago #

    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).

  17. saomay
    Member
    Posted 3 years ago #

    I created new posts because I realized that old posts will have this inherent issue. I waited for 5-40 minutes passed and published the Pending Publication articles and they all carry the timestamp at the time when I changed the post status say from Pending Review to Pending Publication.

    Did you create a new post, record the time and then publish it later and got the current time instead of the "old" time?

  18. saomay
    Member
    Posted 3 years ago #

    So for you to understand better:

    1. Created a new post with title say "Test 3:30PM" ----> Save as either Draft or Pending Review

    2. Changed status from Draft or Pending Review to ----> Pending Publication or any of the other Edit Flow's custom statuses and clicked Save (and verify that the Publish Immediately is there)

    3. Waited for 5-40 min and clicked Publish and the article shows the timestamp of 3:30PM NOT 3:35PM or later.

  19. Daniel Bachhuber
    Hand Built
    Plugin Author

    Posted 3 years ago #

    Ok, I'll take another look. To confirm, you're now using the new snippet instead of the old one?

  20. Daniel Bachhuber
    Hand Built
    Plugin Author

    Posted 3 years ago #

    Unfortunately, I'm not able to reproduce the bug with the new snippet. Everything is now working for me as I'd expect it would.

  21. saomay
    Member
    Posted 3 years ago #

    Hi Daniel,

    I apologize because in the my own way of messing around with the meta-boxes.php file I must have taken out something and it somehow still reported the issue; I replaced the modified file with the original and everything works perfectly now.

    I just really want to say thank you so much for cranking on this...you're awesome!

    David

  22. Daniel Bachhuber
    Hand Built
    Plugin Author

    Posted 3 years ago #

    Perfect, glad we got it fixed :) The fix will be a part of v0.7, so you can just keep the extra function in there until we get the next version out.

  23. saomay
    Member
    Posted 3 years ago #

    Hi Daniel,

    Thanks for the fix but upon closer look, even though the timestamp now shows the correct current time after clicking "Publish" on the post page as in "Published on:......" but the timestamp of the post on the blog as well as in the All Posts manage page showed an older timestamp. Again, this could be an issue with how the db records the timestamp when you change the custom statuses and how it is being queried and shown or displayed.

    So here what I did:

    1. Created a post on August 10th at 5:55PM with title "Test 5:50PM 08/10" which is a Wednesday.

    2. I switched from Pending Review to Pending Publication and saved the post with the respective status.

    3. I purposely waited for for midnight to pass up until 1:28AM August 11th which is a Thursday and clicked "Publish"

    4. I went to view the blog post and saw the date posted as August 10th NOT August 11th; I also clicked on All Posts and filtered by Published status, looked at the specific test post and saw under Date:

    8 hours ago
    Published

    It actually should be "2 min ago Published" because I just published it. Based on these two indicators, WP seems to go by a different timestamp or that the timestamp shown on the post itself is a current time at the time of clicking "Publish" but not the post time understood by WP. So I think there is still that issue of changing the custom statuses and the auto-affixed timestamp even though it is now not shown on the post page.

    Sorry but this is getting very interesting hope you think so too =)

  24. saomay
    Member
    Posted 3 years ago #

    BTW, I also created another test post but only changed the default WP status from Draft to Pending Review in the same 1, 2, 3 steps and the timestamp of the post shown on the blog as well as in All Posts filtered by Published status under Date is 100% correct.

  25. Daniel Bachhuber
    Hand Built
    Plugin Author

    Posted 3 years ago #

    Can you share screenshots of what you see?

  26. Daniel Bachhuber
    Hand Built
    Plugin Author

    Posted 3 years ago #

    Also, please deactivate all other plugins and make sure you're running WordPress core with no modifications

  27. saomay
    Member
    Posted 3 years ago #

    Hi Daniel,

    You can do this test to see the issue right away (I just did and confirmed):

    In essence you create two posts at the same time approximately:

    1. Create a post named "Test - WP Statuses - Put the current time here"; save as Draft and change to Pending Review and then save again (you can keep switching between the two many times as you wish but don't change it to any of the Edit Flow's ones).

    2. Create another post named "Test - Edit Flow - Put the current time here"; save as Draft or Pending Review and then change it to any of the Edit Flow's custom statuses such as Pending Publication in my case and save.

    Now wait for 5 min then publish both of them approximately at the same time back to back. Immediately after that, click on All Posts, filter by Published status and look under Date. Based on my own testing, you would probably something like this see under Date:

    1. For "Test - WP Statuses - Put the current time here": 1 min ago Published (because you just published it)

    2. For "Test - Edit Flow - Put the current time here": 6 min ago Published (because I assume the timestamp somehow is still affixed at the time when you change from a WP status to a Edit Flow's)

    The lapse in time indicates that #2 is not showing the right published time/date.

    I have captured screenshots of All Posts filtered by Published status and also the edit page versions of each post showing exactly what I describe above here: http://www.flickr.com/photos/rougesmoke/

  28. saomay
    Member
    Posted 3 years ago #

    I just tested by deactivating all plugins with original WP core files except for Edit Flow and got the same result in terms of the lapsed time even though two test posts, one using/switching between only WP statuses and the other switch between WP and Edit Flow's, were published at the same time. The "Published on:..." timestamp are identical and can still be viewed by clicking on Edit for each respective post.

  29. Daniel Bachhuber
    Hand Built
    Plugin Author

    Posted 3 years ago #

    User error on my part: I made modifications to a core file and forgot to revert them. Looking for another solution now.

  30. saomay
    Member
    Posted 3 years ago #

    Thanks for keeping up the effort; let me know if you need anything else from me.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic