Did you ever, by chance, find a solution to this? I’m needing similar functionality…
In the core, meta-boxes.php, this is the code which controls it:
if ( $can_publish ) : // Contributors don't get to choose the date of publish ?>
<div class="misc-pub-section curtime misc-pub-section-last">
<span id="timestamp">
<?php printf($stamp, $date); ?></span>
<a href="#edit_timestamp" class="edit-timestamp hide-if-no-js" tabindex='4'><?php _e('Edit') ?></a>
<div id="timestampdiv" class="hide-if-js"><?php touch_time(($action == 'edit'),1,4); ?></div>
</div><?php // /misc-pub-section ?>
<?php endif; ?>
I decided to go a different route from showing the box to contributors. Instead, I show a custom meta box to all users and take the date and time values from the inputs of that meta box for the date and time of the post.
The code I wrote is ghetto, but it works.
Here’s the code I used as a plugin:
function kurt_pagedate_change($id)
{
global $wpdb, $post_type;
$post_type_object = get_post_type_object($post_type);
$can_publish = current_user_can($post_type_object->cap->publish_posts);
// check if this is a page
if ( ($post_type == "event" || $post_type == "movie_show" || $post_type == "cclass") && isset($id))
{
if ( $_POST['event_date'] ) {
$form_date = $_POST['event_date'];
$form_time = $_POST['event_time'];
$form_date = $form_date." ".$form_time;
$date_obj = date_create($form_date);
// 0000-00-00 00:00:00
$form_date_formatted = date_format($date_obj, 'Y-m-d H:i:s');
// modify date
$now = $form_date_formatted;
$now_gmt = $form_date_formatted;
$query = "UPDATE {$wpdb->posts} SET post_date = '$now', post_date_gmt = '$now_gmt' WHERE ID = '$id'";
$wpdb->query($query);
if ( $can_publish ) : // Contributors don't get to "Schedule"
// set post status as future
$sql = "UPDATE {$wpdb->posts} SET post_status = 'future'
WHERE ID = '$id'";
$wpdb->get_results($sql);
endif;
} // end if event_date has value
} // end if page
}
/** Add actions **/
add_action('edit_post', 'kurt_pagedate_change');
add_action('publish_post', 'kurt_pagedate_change');
add_action('save_post', 'kurt_pagedate_change');
?>
Anonymous User 2630056
(@anonymized-2630056)
My code is simpler and it doesnt require modifying the core:
function mostrar_editar_fecha($post)
{
$post_type_object = get_post_type_object('post');
$can_publish = current_user_can($post_type_object->cap->publish_posts);
$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') ) );
}
if (!($can_publish)) : // Contributors don't get to choose the date of publish ?>
<div class="misc-pub-section curtime misc-pub-section-last">
<span id="timestamp">
<?php printf($stamp, $date); ?></span>
<a href="#edit_timestamp" class="edit-timestamp hide-if-no-js" tabindex='4'><?php _e('Edit') ?></a>
<div id="timestampdiv" class="hide-if-js"><?php touch_time(($action == 'edit'),1,4); ?></div>
</div>
<?php
endif;
}
add_action ('post_submitbox_misc_actions', 'mostrar_editar_fecha');