Had to take a break this weekend for WordCamp San Francisco but I’m still working on it.
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.ww.wp.xz.cn/browser/tags/3.2.1/wp-includes/post.php#L2694
* Original thread: http://ww.wp.xz.cn/support/topic/plugin-edit-flow-custom-statuses-create-timestamp-problem
* Core ticket: http://core.trac.ww.wp.xz.cn/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.ww.wp.xz.cn/browser/tags/3.2.1/wp-includes/post.php#L2506
* Original thread: http://ww.wp.xz.cn/support/topic/plugin-edit-flow-custom-statuses-create-timestamp-problem
* Core ticket: http://core.trac.ww.wp.xz.cn/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.
@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.
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.ww.wp.xz.cn/browser/tags/3.2.1/wp-includes/post.php#L2694
* Original thread: http://ww.wp.xz.cn/support/topic/plugin-edit-flow-custom-statuses-create-timestamp-problem
* Core ticket: http://core.trac.ww.wp.xz.cn/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.ww.wp.xz.cn/browser/tags/3.2.1/wp-includes/post.php#L2506
* Original thread: http://ww.wp.xz.cn/support/topic/plugin-edit-flow-custom-statuses-create-timestamp-problem
* Core ticket: http://core.trac.ww.wp.xz.cn/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.
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.
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.
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.