From ddf9318bf59b0335b2c8fc7e0eaf9c8e1c992b09 Mon Sep 17 00:00:00 2001 From: John Smith Date: Wed, 2 Sep 2026 13:48:28 -0400 Subject: [PATCH] fix(comic): preserve original twitter publication date and GMT with edit_date=true --- .../abilities/class-content-abilities.php | 12 ++++- .../comic/class-comic-write-operations.php | 52 ++++++++++++++++++- 2 files changed, 61 insertions(+), 3 deletions(-) diff --git a/includes/abilities/class-content-abilities.php b/includes/abilities/class-content-abilities.php index c103b58..c730dd5 100644 --- a/includes/abilities/class-content-abilities.php +++ b/includes/abilities/class-content-abilities.php @@ -713,7 +713,17 @@ class EMCP_Tools_Content_Abilities { if ( ! empty( $input['slug'] ) ) { $postarr['post_name'] = sanitize_title( $input['slug'] ); } if ( isset( $input['parent'] ) ) { $postarr['post_parent'] = absint( $input['parent'] ); } if ( isset( $input['menu_order'] ) ) { $postarr['menu_order'] = (int) $input['menu_order']; } - if ( ! empty( $input['date'] ) ) { $postarr['post_date'] = sanitize_text_field( $input['date'] ); } + if ( ! empty( $input['date'] ) ) { + $ts = is_numeric( $input['date'] ) ? (int) $input['date'] : strtotime( (string) $input['date'] ); + if ( $ts ) { + $postarr['post_date'] = function_exists( 'get_date_from_gmt' ) ? get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $ts ) ) : gmdate( 'Y-m-d H:i:s', $ts ); + $postarr['post_date_gmt'] = gmdate( 'Y-m-d H:i:s', $ts ); + $postarr['edit_date'] = true; + } else { + $postarr['post_date'] = sanitize_text_field( $input['date'] ); + $postarr['edit_date'] = true; + } + } if ( ! empty( $input['comment_status'] ) ) { $postarr['comment_status'] = ( 'open' === $input['comment_status'] ) ? 'open' : 'closed'; } if ( ! empty( $input['status'] ) ) { diff --git a/includes/abilities/comic/class-comic-write-operations.php b/includes/abilities/comic/class-comic-write-operations.php index 8b8570c..4c013b8 100644 --- a/includes/abilities/comic/class-comic-write-operations.php +++ b/includes/abilities/comic/class-comic-write-operations.php @@ -41,7 +41,31 @@ class EMCP_Tools_Comic_Write_Operations { ); if ( ! empty( $args['date'] ) ) { - $post_data['post_date'] = sanitize_text_field( (string) $args['date'] ); + $ts = is_numeric( $args['date'] ) ? (int) $args['date'] : strtotime( (string) $args['date'] ); + if ( $ts ) { + $post_data['post_date'] = function_exists( 'get_date_from_gmt' ) ? get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $ts ) ) : gmdate( 'Y-m-d H:i:s', $ts ); + $post_data['post_date_gmt'] = gmdate( 'Y-m-d H:i:s', $ts ); + $post_data['edit_date'] = true; + } else { + $post_data['post_date'] = sanitize_text_field( (string) $args['date'] ); + $post_data['edit_date'] = true; + } + } + + if ( ! empty( $args['author_id'] ) ) { + $post_data['post_author'] = absint( $args['author_id'] ); + } elseif ( ! empty( $args['author'] ) ) { + if ( is_numeric( $args['author'] ) ) { + $post_data['post_author'] = absint( $args['author'] ); + } elseif ( is_string( $args['author'] ) && function_exists( 'get_user_by' ) ) { + $user = get_user_by( 'login', $args['author'] ); + if ( ! $user ) { + $user = get_user_by( 'slug', $args['author'] ); + } + if ( $user instanceof \WP_User ) { + $post_data['post_author'] = $user->ID; + } + } } $post_id = wp_insert_post( $post_data, true ); @@ -177,7 +201,31 @@ class EMCP_Tools_Comic_Write_Operations { $post_data['post_status'] = sanitize_key( (string) $args['status'] ); } if ( isset( $args['date'] ) ) { - $post_data['post_date'] = sanitize_text_field( (string) $args['date'] ); + $ts = is_numeric( $args['date'] ) ? (int) $args['date'] : strtotime( (string) $args['date'] ); + if ( $ts ) { + $post_data['post_date'] = function_exists( 'get_date_from_gmt' ) ? get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $ts ) ) : gmdate( 'Y-m-d H:i:s', $ts ); + $post_data['post_date_gmt'] = gmdate( 'Y-m-d H:i:s', $ts ); + $post_data['edit_date'] = true; + } else { + $post_data['post_date'] = sanitize_text_field( (string) $args['date'] ); + $post_data['edit_date'] = true; + } + } + + if ( ! empty( $args['author_id'] ) ) { + $post_data['post_author'] = absint( $args['author_id'] ); + } elseif ( ! empty( $args['author'] ) ) { + if ( is_numeric( $args['author'] ) ) { + $post_data['post_author'] = absint( $args['author'] ); + } elseif ( is_string( $args['author'] ) && function_exists( 'get_user_by' ) ) { + $user = get_user_by( 'login', $args['author'] ); + if ( ! $user ) { + $user = get_user_by( 'slug', $args['author'] ); + } + if ( $user instanceof \WP_User ) { + $post_data['post_author'] = $user->ID; + } + } } if ( count( $post_data ) > 1 ) {