@@ -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"}]] ' ;
@@ -537,6 +558,17 @@ public function save_feedzy_import_feed_meta( $post_id, $post ) {
537
558
$ data_meta ['import_auto_translation ' ] = isset ( $ data_meta ['import_auto_translation ' ] ) ? $ data_meta ['import_auto_translation ' ] : 'no ' ;
538
559
// Check feeds external image URL checkbox checked OR not.
539
560
$ data_meta ['import_use_external_image ' ] = isset ( $ data_meta ['import_use_external_image ' ] ) ? $ data_meta ['import_use_external_image ' ] : 'no ' ;
561
+
562
+ // $data_meta['feedzy_post_author'] should be the author username. We convert it to the author ID.
563
+ if ( ! empty ( $ data_meta ['import_post_author ' ] ) ) {
564
+ $ author = get_user_by ( 'login ' , $ data_meta ['import_post_author ' ] );
565
+ if ( $ author ) {
566
+ $ data_meta ['import_post_author ' ] = $ author ->ID ;
567
+ } else {
568
+ $ data_meta ['import_post_author ' ] = '' ;
569
+ }
570
+ }
571
+
540
572
foreach ( $ data_meta as $ key => $ value ) {
541
573
$ value = is_array ( $ value ) ? implode ( ', ' , $ value ) : implode ( ', ' , (array ) $ value );
542
574
if ( 'source ' === $ key ) {
@@ -1344,6 +1376,7 @@ private function run_job( $job, $max ) {
1344
1376
$ import_auto_translation = get_post_meta ( $ job ->ID , 'import_auto_translation ' , true );
1345
1377
$ import_auto_translation = $ this ->feedzy_is_agency () && 'yes ' === $ import_auto_translation ? true : false ;
1346
1378
$ import_translation_lang = get_post_meta ( $ job ->ID , 'import_auto_translation_lang ' , true );
1379
+ $ import_post_author = get_post_meta ( $ job ->ID , 'import_post_author ' , true );
1347
1380
$ max = $ import_feed_limit ;
1348
1381
1349
1382
if ( metadata_exists ( 'post ' , $ job ->ID , 'import_post_status ' ) ) {
@@ -1776,6 +1809,8 @@ function ( $attr, $key ) {
1776
1809
$ item_post_excerpt = apply_filters ( 'feedzy_parse_custom_tags ' , $ item_post_excerpt , $ item_obj );
1777
1810
}
1778
1811
1812
+ $ post_author = ! empty ( $ import_post_author ) ? $ import_post_author : $ job ->post_author ;
1813
+
1779
1814
$ new_post = apply_filters (
1780
1815
'feedzy_insert_post_args ' ,
1781
1816
array (
@@ -1785,7 +1820,7 @@ function ( $attr, $key ) {
1785
1820
'post_date ' => $ post_date ,
1786
1821
'post_status ' => $ import_post_status ,
1787
1822
'post_excerpt ' => $ item_post_excerpt ,
1788
- 'post_author ' => $ job -> post_author ,
1823
+ 'post_author ' => $ post_author ,
1789
1824
),
1790
1825
$ item_obj ,
1791
1826
$ post_title ,
0 commit comments