Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion includes/class-e-reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ protected function get_content( $format, \WP_Post $post ) {
array(
'title' => $post_title,
'author' => $post->author_name,
'date' => get_the_time( 'l, F j, Y', $post ),
'date' => $this->get_post_display_date( $post, 'l, F j, Y' ),
)
);

Expand All @@ -161,6 +161,29 @@ protected function get_content( $format, \WP_Post $post ) {
return $content;
}

/**
* Get the date to show for a post in generated e-reader content.
*
* Collected posts can preserve the original article date as metadata. Prefer
* that value in the chapter byline, while leaving ordinary posts on their
* WordPress publish date.
*
* @param \WP_Post $post The post.
* @param string $format Date format.
* @return string Formatted date.
*/
protected function get_post_display_date( \WP_Post $post, $format ) {
$published_time = get_post_meta( $post->ID, 'published_time', true );
if ( $published_time ) {
$timestamp = is_numeric( $published_time ) ? (int) $published_time : strtotime( (string) $published_time );
if ( $timestamp ) {
return date_i18n( $format, $timestamp );
}
}

return get_the_time( $format, $post );
}

protected function update_author_name( \WP_Post $post ) {
if ( ! isset( $post->author_name ) ) {
$author = self::get_post_author( $post );
Expand Down
16 changes: 16 additions & 0 deletions tests/Test_E_Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,22 @@ function () {
$this->assertSame( 'Zetaphor', $post->author_name );
}

/**
* Test collected article dates replace the saved post date in chapter bylines.
*/
public function test_collected_article_date_replaces_post_date_in_chapter_byline() {
$post = new \WP_Post();
$post->ID = 124;
$post->post_author = 1;
update_post_meta( $post->ID, 'published_time', '2026-06-29T16:44:13+00:00' );

$ereader = new E_Reader_Download( 'Test' );
$method = new \ReflectionMethod( $ereader, 'get_post_display_date' );
$method->setAccessible( true );

$this->assertSame( 'Monday, June 29, 2026', $method->invoke( $ereader, $post, 'l, F j, Y' ) );
}

/**
* Test same-site upload image URLs are embedded in generated ePubs.
*/
Expand Down