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

    https://www.ads-software.com/extend/plugins/edit-flow/

Viewing 15 replies - 31 through 45 (of 47 total)
  • Plugin Contributor Daniel Bachhuber

    (@danielbachhuber)

    Had to take a break this weekend for WordCamp San Francisco but I’m still working on it.

    Awesome. Thanks.

    Plugin Contributor Daniel Bachhuber

    (@danielbachhuber)

    Hey there,
    Third time’s the charm, right? ?? I think I finally have a fix for you. Try replacing those existing code snippets with the following block:

    add_filter( 'admin_init', array( 'ef_check_timestamp_on_publish' ) );
    add_filter( 'wp_insert_post_data', array( '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: https://core.trac.www.ads-software.com/browser/tags/3.2.1/wp-includes/post.php#L2694
     * Original thread: https://www.ads-software.com/support/topic/plugin-edit-flow-custom-statuses-create-timestamp-problem
     * Core ticket: https://core.trac.www.ads-software.com/ticket/18362
     */
    function ef_check_timestamp_on_publish() {
    	global $edit_flow, $pagenow, $wpdb;
    
    	if ( !isset( $edit_flow ) || $pagenow != 'post.php' || !isset( $_POST['publish'] ) )
    		return false;
    
    	// 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: https://core.trac.www.ads-software.com/browser/tags/3.2.1/wp-includes/post.php#L2506
     * Original thread: https://www.ads-software.com/support/topic/plugin-edit-flow-custom-statuses-create-timestamp-problem
     * Core ticket: https://core.trac.www.ads-software.com/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;
    }

    Wanted to chime in here. I just changed a bunch of posts that were Drafts to a new custom status. Now all of those that hadn’t been created with a publishing date attached to them have now been associated with today’s date.

    Publish Immediately is no longer an option (going back from a date to “Immediately” seems to be a WordPress core issue noted in other support threads as well) and I can’t disassociate it from a date, either today or in the future.

    It clutters the calendar view this way having TBD posts now assigned to a specific day. Hoping for a more permanent fix other than the hack above. thx guys.

    Plugin Contributor Daniel Bachhuber

    (@danielbachhuber)

    @redhooded Did you add this code snippet to the functions.php file in your theme? I was able to bulk edit posts just fine with it.

    Hi Daniel,

    I replaced the exiting code with the whole block you just posted but I got this:

    Warning: call_user_func_array() expects parameter 1 to be a valid callback, array must have exactly two members in /home/longtail/public_html/wp-includes/plugin.php on line 405

    Warning: Cannot modify header information – headers already sent by (output started at /home/longtail/public_html/wp-includes/plugin.php:405) in /home/longtail/public_html/wp-includes/functions.php on line 861

    Warning: Cannot modify header information – headers already sent by (output started at /home/longtail/public_html/wp-includes/plugin.php:405) in /home/longtail/public_html/wp-includes/functions.php on line 862

    I am not sure what happened.

    BTW I am running WP Multi-site.

    Plugin Contributor Daniel Bachhuber

    (@danielbachhuber)

    Gah, I posted it wrong. Sorry about that… not my week. Try this (same thing, but adjusted the filter and action so they don’t cause errors):

    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: https://core.trac.www.ads-software.com/browser/tags/3.2.1/wp-includes/post.php#L2694
     * Original thread: https://www.ads-software.com/support/topic/plugin-edit-flow-custom-statuses-create-timestamp-problem
     * Core ticket: https://core.trac.www.ads-software.com/ticket/18362
     */
    function ef_check_timestamp_on_publish() {
    	global $edit_flow, $pagenow, $wpdb;
    
    	if ( !isset( $edit_flow ) || $pagenow != 'post.php' || !isset( $_POST['publish'] ) )
    		return false;
    
    	// 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: https://core.trac.www.ads-software.com/browser/tags/3.2.1/wp-includes/post.php#L2506
     * Original thread: https://www.ads-software.com/support/topic/plugin-edit-flow-custom-statuses-create-timestamp-problem
     * Core ticket: https://core.trac.www.ads-software.com/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;
    }

    Great! I am testing now; will let you know. Thanks.

    Plugin Contributor Daniel Bachhuber

    (@danielbachhuber)

    Awesome! Let me know how it turns out.

    Daniel,

    Great work! Ok so it is almost perfect; here is one issue left with bulk editing (I think as I have been testing on two separate sites with unchanged core code and consistently seeing the same result); here is the scenario:

    1. Two test articles created at the same time one using only WP statuses (Draft —> Pending Review —> Save) and other WP and Edit Flow custom ones (Draft or Pending Review —> Pending Publication or any other Edit Flow custom ones —> Save)

    2. Waited for time to pass say 1hr; go to All Posts, select those two respective articles, choose Edit under Bulk Actions drop-down, click Apply to bring up the bulk editing window, change status to Publish, and click Update.

    3. Two articles were updated:
    a. One using only WP statuses showed “1min ago Published” under Date column under All Posts

    b. One using both WP and Edit Flow showed “1hour ago Published” under Date column under All Posts

    Beside the issue above, publishing individual article via the post page is perfectly fine now displaying the correct timestamp and can be filtered by published date i.e. by month flawlessly.

    Basically, that “Update” call-to-action in Bulk Edit somehow still calls up the “Old Date” when the article got switched from WP status say Pending Review —> Pending Publication – my guess.

    Plugin Contributor Daniel Bachhuber

    (@danielbachhuber)

    Awesome to hear this is fixed… thanks so much for helping me test it out.

    I’ll take a look at the bulk editing bug when I have a chance in the next few days. I’ve confirmed it on my end.

    Perfect. Thanks for keeping cranking on this.

    Plugin Contributor Daniel Bachhuber

    (@danielbachhuber)

    I’ve figured it out. If you’d like, I can post an updated snippet. I think I’d prefer to refrain from posting about it because I’d rather just focus on getting the next release out and not have to worry about people copy and pasting code.

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