WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. saomay
    Member
    Posted 2 years ago #

    Hi Daniel,

    Hope you are doing well; any progress? Thanks.

  2. Daniel Bachhuber
    Hand Built
    Plugin Author

    Posted 2 years ago #

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

  3. saomay
    Member
    Posted 2 years ago #

    Awesome. Thanks.

  4. Daniel Bachhuber
    Hand Built
    Plugin Author

    Posted 2 years ago #

    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: 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;
    
    	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: 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;
    }
  5. redhooded
    Member
    Posted 2 years ago #

    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.

  6. Daniel Bachhuber
    Hand Built
    Plugin Author

    Posted 2 years ago #

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

  7. saomay
    Member
    Posted 2 years ago #

    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.

  8. saomay
    Member
    Posted 2 years ago #

    BTW I am running WP Multi-site.

  9. Daniel Bachhuber
    Hand Built
    Plugin Author

    Posted 2 years ago #

    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: 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;
    
    	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: 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;
    }
  10. saomay
    Member
    Posted 2 years ago #

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

  11. Daniel Bachhuber
    Hand Built
    Plugin Author

    Posted 2 years ago #

    Awesome! Let me know how it turns out.

  12. saomay
    Member
    Posted 2 years ago #

    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.

  13. saomay
    Member
    Posted 2 years ago #

    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.

  14. Daniel Bachhuber
    Hand Built
    Plugin Author

    Posted 2 years ago #

    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.

  15. saomay
    Member
    Posted 2 years ago #

    Perfect. Thanks for keeping cranking on this.

  16. Daniel Bachhuber
    Hand Built
    Plugin Author

    Posted 2 years ago #

    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.

  17. saomay
    Member
    Posted 2 years ago #

    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.

  18. Daniel Bachhuber
    Hand Built
    Plugin Author

    Posted 2 years ago #

    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;
    }

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic