@@ -161,6 +161,7 @@ public function enqueue_styles() {
161
161
'media_iframe_button ' => __ ( 'Set default image ' , 'feedzy-rss-feeds ' ),
162
162
'action_btn_text_1 ' => __ ( 'Choose image ' , 'feedzy-rss-feeds ' ),
163
163
'action_btn_text_2 ' => __ ( 'Replace image ' , 'feedzy-rss-feeds ' ),
164
+ 'author_helper ' => __ ( 'If the author you are looking for isn \'t found, you can input the author username. ' , 'feedzy-rss-feeds ' ),
164
165
),
165
166
)
166
167
);
@@ -326,6 +327,11 @@ public function feedzy_import_feed_options() {
326
327
$ post_types = get_post_types ( '' , 'names ' );
327
328
$ post_types = array_diff ( $ post_types , array ( 'feedzy_imports ' , 'feedzy_categories ' ) );
328
329
$ published_status = array ( 'publish ' , 'draft ' );
330
+ $ authors = get_users ( array ( 'number ' => 100 ) );
331
+ $ authors_array = array ();
332
+ foreach ( $ authors as $ author ) {
333
+ $ authors_array [] = $ author ->user_login ;
334
+ }
329
335
$ keyword_filter_fields = array ( __ ( 'Title ' , 'feedzy-rss-feeds ' ) );
330
336
if ( feedzy_is_pro () ) {
331
337
$ keyword_filter_fields = array_merge (
@@ -364,6 +370,21 @@ public function feedzy_import_feed_options() {
364
370
$ import_auto_translation = get_post_meta ( $ post ->ID , 'import_auto_translation ' , true );
365
371
$ import_auto_translation = 'yes ' === $ import_auto_translation ? 'checked ' : '' ;
366
372
$ import_translation_lang = get_post_meta ( $ post ->ID , 'import_auto_translation_lang ' , true );
373
+ $ import_post_author = get_post_meta ( $ post ->ID , 'import_post_author ' , true );
374
+
375
+ /**
376
+ * This code snippet retrieves the post author for backward compatibility for existing imports as well as for any new imports.
377
+ * It checks if the $import_post_author variable is not empty, otherwise it defaults to the current post's author.
378
+ */
379
+ $ import_post_author = ! empty ( $ import_post_author ) ? $ import_post_author : $ post ->post_author ;
380
+ $ author = get_user_by ( 'ID ' , $ import_post_author );
381
+ if ( $ author ) {
382
+ $ import_post_author = $ author ->user_login ;
383
+ if ( ! in_array ( $ import_post_author , $ authors_array , true ) ) {
384
+ $ authors_array [] = $ import_post_author ;
385
+ }
386
+ }
387
+
367
388
// default values so that post is not created empty.
368
389
if ( empty ( $ import_title ) ) {
369
390
$ import_title = '[[{"value":"%5B%7B%22id%22%3A%22%22%2C%22tag%22%3A%22item_title%22%2C%22data%22%3A%7B%7D%7D%5D"}]] ' ;
@@ -508,6 +529,17 @@ public function save_feedzy_import_feed_meta( $post_id, $post ) {
508
529
$ data_meta ['import_auto_translation ' ] = isset ( $ data_meta ['import_auto_translation ' ] ) ? $ data_meta ['import_auto_translation ' ] : 'no ' ;
509
530
// Check feeds external image URL checkbox checked OR not.
510
531
$ data_meta ['import_use_external_image ' ] = isset ( $ data_meta ['import_use_external_image ' ] ) ? $ data_meta ['import_use_external_image ' ] : 'no ' ;
532
+
533
+ // $data_meta['feedzy_post_author'] should be the author username. We convert it to the author ID.
534
+ if ( ! empty ( $ data_meta ['import_post_author ' ] ) ) {
535
+ $ author = get_user_by ( 'login ' , $ data_meta ['import_post_author ' ] );
536
+ if ( $ author ) {
537
+ $ data_meta ['import_post_author ' ] = $ author ->ID ;
538
+ } else {
539
+ $ data_meta ['import_post_author ' ] = '' ;
540
+ }
541
+ }
542
+
511
543
foreach ( $ data_meta as $ key => $ value ) {
512
544
$ value = is_array ( $ value ) ? implode ( ', ' , $ value ) : implode ( ', ' , (array ) $ value );
513
545
if ( 'source ' === $ key ) {
@@ -1284,6 +1316,7 @@ private function run_job( $job, $max ) {
1284
1316
$ import_auto_translation = get_post_meta ( $ job ->ID , 'import_auto_translation ' , true );
1285
1317
$ import_auto_translation = $ this ->feedzy_is_agency () && 'yes ' === $ import_auto_translation ? true : false ;
1286
1318
$ import_translation_lang = get_post_meta ( $ job ->ID , 'import_auto_translation_lang ' , true );
1319
+ $ import_post_author = get_post_meta ( $ job ->ID , 'import_post_author ' , true );
1287
1320
$ max = $ import_feed_limit ;
1288
1321
1289
1322
if ( metadata_exists ( 'post ' , $ job ->ID , 'import_post_status ' ) ) {
@@ -1716,6 +1749,8 @@ function ( $attr, $key ) {
1716
1749
$ item_post_excerpt = apply_filters ( 'feedzy_parse_custom_tags ' , $ item_post_excerpt , $ item_obj );
1717
1750
}
1718
1751
1752
+ $ post_author = ! empty ( $ import_post_author ) ? $ import_post_author : $ job ->post_author ;
1753
+
1719
1754
$ new_post = apply_filters (
1720
1755
'feedzy_insert_post_args ' ,
1721
1756
array (
@@ -1725,7 +1760,7 @@ function ( $attr, $key ) {
1725
1760
'post_date ' => $ post_date ,
1726
1761
'post_status ' => $ import_post_status ,
1727
1762
'post_excerpt ' => $ item_post_excerpt ,
1728
- 'post_author ' => $ job -> post_author ,
1763
+ 'post_author ' => $ post_author ,
1729
1764
),
1730
1765
$ item_obj ,
1731
1766
$ post_title ,
0 commit comments