🐛fix: Use feed publication date as post_date on import
Extracted the wp_insert_post/wp_update_post argument construction into a private build_postarr() helper so the post_date/post_date_gmt derivation from the feed timestamp can be exercised in isolation. Added smoke tests that pin down the create-path behavior (feed timestamp becomes post_date) and the fallback path (no feed date leaves post_date unset for WordPress to fill in at import time). Added minimal get_date_from_gmt and get_gmt_from_date stubs to the test bootstrap so the new tests run without WordPress loaded.
This commit is contained in:
@@ -31,5 +31,29 @@ function wp_parse_args( $args, $defaults = array() ) {
|
||||
return array_merge( $defaults, $args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Minimal get_date_from_gmt stub matching WordPress's MySQL-string behavior.
|
||||
*
|
||||
* @param string $date_string GMT timestamp in MySQL date format.
|
||||
* @return string Timestamp converted to the site's local timezone.
|
||||
*/
|
||||
function get_date_from_gmt( $date_string ) {
|
||||
return get_gmt_from_date( $date_string );
|
||||
}
|
||||
|
||||
/**
|
||||
* Minimal get_gmt_from_date stub: the inverse of get_date_from_gmt.
|
||||
*
|
||||
* @param string $date_string Local timestamp in MySQL date format.
|
||||
* @return string Timestamp converted to GMT (UTC).
|
||||
*/
|
||||
function get_gmt_from_date( $date_string ) {
|
||||
$timestamp = strtotime( $date_string . ' UTC' );
|
||||
if ( false === $timestamp ) {
|
||||
return $date_string;
|
||||
}
|
||||
return gmdate( 'Y-m-d H:i:s', $timestamp );
|
||||
}
|
||||
|
||||
require_once dirname( __DIR__ ) . '/src/Options.php';
|
||||
require_once dirname( __DIR__ ) . '/src/Import/Importer.php';
|
||||
|
||||
Reference in New Issue
Block a user