@@ -115,6 +115,7 @@ public function init(): void {
115
115
add_action ( 'eml_http_directory_import_file_before_to_list ' , array ( $ this , 'check_runtime ' ), 10 , 2 );
116
116
add_action ( 'eml_sftp_directory_import_file_before_to_list ' , array ( $ this , 'check_runtime ' ), 10 , 2 );
117
117
add_filter ( 'eml_help_tabs ' , array ( $ this , 'add_help ' ), 20 );
118
+ add_filter ( 'eml_file_import_attachment ' , array ( $ this , 'add_file_date ' ), 10 , 3 );
118
119
119
120
// add admin actions.
120
121
add_action ( 'admin_action_eml_reset_thumbnails ' , array ( $ this , 'reset_thumbnails_by_request ' ) );
@@ -420,7 +421,7 @@ public function add_url( string $url, bool $add_to_queue = false ): bool {
420
421
*
421
422
* @since 2.0.0 Available since 2.0.0
422
423
*
423
- * @param string $post_array The attachment settings.
424
+ * @param array $post_array The attachment settings.
424
425
* @param string $url The requested external URL.
425
426
* @param array $file_data List of file settings detected by importer.
426
427
*/
@@ -1783,4 +1784,32 @@ public function check_srcset_meta( array $image_meta, array $size_array, string
1783
1784
// return resulting meta.
1784
1785
return $ image_meta ;
1785
1786
}
1787
+
1788
+ /**
1789
+ * Add file date to post array to set the date of the external file.
1790
+ *
1791
+ * @param array $post_array The attachment settings.
1792
+ * @param string $url The requested external URL.
1793
+ * @param array $file_data List of file settings detected by importer.
1794
+ *
1795
+ * @return array
1796
+ * @noinspection PhpUnusedParameterInspection
1797
+ */
1798
+ public function add_file_date ( array $ post_array , string $ url , array $ file_data ): array {
1799
+ // bail if setting is disabled.
1800
+ if ( 1 !== absint ( get_option ( 'eml_use_file_dates ' ) ) ) {
1801
+ return $ post_array ;
1802
+ }
1803
+
1804
+ // bail if no last-modified is given.
1805
+ if ( empty ( $ file_data ['last-modified ' ] ) ) {
1806
+ return $ post_array ;
1807
+ }
1808
+
1809
+ // add the last-modified date.
1810
+ $ post_array ['post_date ' ] = gmdate ( 'Y-m-d H:i:s ' , $ file_data ['last-modified ' ] );
1811
+
1812
+ // return the resulting array.
1813
+ return $ post_array ;
1814
+ }
1786
1815
}
0 commit comments