Способ первый
В этом случае попытки изменить дату публикации будут безуспешными, хотя ссылка "Изменить" останется:
function deny_post_date_change( $data, $postarr ) {
unset( $data['post_date'] );
unset( $data['post_date_gmt'] );
return $data;
}
add_filter( 'wp_insert_post_data', 'deny_post_date_change', 0, 2 );Способ второй
В этом случае применим CSS и ссылка отображаться не будет:
function hide_publication_date_elements() { ?>
<style type="text/css">
a.edit-timestamp, #timestampdiv {display:none;}
</style><?php
}
add_action( 'admin_enqueue_scripts', 'hide_publication_date_elements' );Способ третий
function insert_post_data_handler( $data , $postarr ) {
if ( $data['post_status'] === 'auto-draft' ){
// Do Nothing, WordPress Does not generate date from POST/GET request
} elseif ( $data['post_status'] !== 'publish' ){
// Must be a draft, so automatically make the post date the current date/time
$datetime = date("Y-m-d H:i:s");
$data['post_date'] = $datetime;
$data['post_date_gmt'] = $datetime;
$data['post_modified'] = $datetime;
$data['post_modified_gmt'] = $datetime;
} elseif ( $data['post_status'] === 'publish' ){
// Could either be an update to a post, or a brand new post
if ( isset( $postarr['original_post_status'] ) ){
if( $postarr['original_post_status'] !== 'publish' && $data['post_status'] === 'publish' ){
// This is a brand new post
$datetime = date("Y-m-d H:i:s");
$data['post_date'] = $datetime;
$data['post_date_gmt'] = $datetime;
} else {
// This must be an update, do not change the date
global $post;
$org_datetime = $post->post_date;
$current_datetime = date("Y-m-d H:i:s");
$data['post_date'] = $org_datetime;
$data['post_date_gmt'] = $org_datetime;
$data['post_modified'] = $current_datetime;
$data['post_modified_gmt'] = $current_datetime;
}
} elseif( $postarr['original_post_status'] === 'publish' && $data['post_status'] !== 'publish' ){
// Sorry, not allowing anyone to revert to draft/pending once published
die('The status can not be reverted once posted');
}
} else {
die('Uncaught exception');
}
return $data;
}
add_filter( 'wp_insert_post_data', 'insert_post_data_handler', '99', 2 );