/**
* Filter the_time function to show posts as being from another date/time.
*
* @param string $formatted The formatted time.
* @param string $format The time format used.
* @return string Modified formatted time.
*/
function cc_time_machine( $formatted, $format ) {
$offset = get_option( 'cc_time_offset' ); // Offset in days, can be negative.
if ( $offset ) {
global $post;
$timestamp = get_post_time( 'U', true, $post ); // UTC timestamp with GMT offset included.
$adjusted = $timestamp + ( (int) $offset * DAY_IN_SECONDS );
return date( $format, $adjusted );
}
// If option doesn't exist, then just return it unmodified.
return $formatted;
}
add_filter( 'the_time', 'cc_time_machine', 10, 2 );