fix(comic): preserve original twitter publication date and GMT with edit_date=true

This commit is contained in:
John Smith
2026-09-02 13:48:28 -04:00
parent 74f87902bd
commit ddf9318bf5
2 changed files with 61 additions and 3 deletions
+11 -1
View File
@@ -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'] ) ) {
@@ -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 ) {