@@ -1337,69 +1337,71 @@ public function pull_content( $sites = array() ) {
13371337
13381338 $ post_types_processed = array ();
13391339
1340- if ( count ( $ posts ) > 0 ) {
1340+ if ( is_array ( $ posts ) && count ( $ posts ) > 0 ) {
13411341 Syndication_Logger::log_post_info ( $ site_id , $ status = 'start_import ' , $ message = sprintf ( __ ( 'starting import for site id %d with %d posts ' , 'push-syndication ' ), $ site_id , count ( $ posts ) ), $ log_time = null , $ extra = array () );
13421342 } else {
13431343 Syndication_Logger::log_post_info ( $ site_id , $ status = 'no_posts ' , $ message = sprintf ( __ ( 'no posts for site id %d ' , 'push-syndication ' ), $ site_id ), $ log_time = null , $ extra = array () );
13441344 }
13451345
1346- foreach ( $ posts as $ post ) {
1346+ if ( is_array ( $ posts ) && ! empty ( $ posts ) ) {
1347+ foreach ( $ posts as $ post ) {
13471348
1348- if ( ! in_array ( $ post ['post_type ' ], $ post_types_processed ) ) {
1349- remove_post_type_support ( $ post ['post_type ' ], 'revisions ' );
1350- $ post_types_processed [] = $ post ['post_type ' ];
1351- }
1352-
1353- if ( empty ( $ post ['post_guid ' ] ) ) {
1354- Syndication_Logger::log_post_error ( $ site_id , $ status = 'no_post_guid ' , $ message = sprintf ( __ ( 'skipping post no guid ' , 'push-syndication ' ) ), $ log_time = null , $ extra = array ( 'post ' => $ post ) );
1355- continue ;
1356- }
1357- $ post_id = $ this ->find_post_by_guid ( $ post ['post_guid ' ], $ post , $ site );
1358-
1359- if ( $ post_id ) {
1360- $ pull_edit_shortcircuit = apply_filters ( 'syn_pre_pull_edit_post_shortcircuit ' , false , $ post , $ site , $ transport_type , $ client );
1361- if ( true === $ pull_edit_shortcircuit ) {
1362- Syndication_Logger::log_post_info ( $ site_id , $ status = 'skip_pre_pull_edit_post ' , $ message = sprintf ( __ ( 'skipping post per syn_pre_pull_edit_post_shortcircuit ' , 'push-syndication ' ) ), $ log_time = null , $ extra = array ( 'post ' => $ post ) );
1363- continue ;
1349+ if ( ! in_array ( $ post ['post_type ' ], $ post_types_processed ) ) {
1350+ remove_post_type_support ( $ post ['post_type ' ], 'revisions ' );
1351+ $ post_types_processed [] = $ post ['post_type ' ];
13641352 }
1365- // if updation is disabled continue
1366- if ( $ this -> push_syndicate_settings [ ' update_pulled_posts ' ] != ' on ' ) {
1367- Syndication_Logger::log_post_info ( $ site_id , $ status = 'skip_update_pulled_posts ' , $ message = sprintf ( __ ( 'skipping post update per update_pulled_posts setting ' , 'push-syndication ' ) ), $ log_time = null , $ extra = array ( 'post ' => $ post ) );
1353+
1354+ if ( empty ( $ post [ ' post_guid ' ] ) ) {
1355+ Syndication_Logger::log_post_error ( $ site_id , $ status = 'no_post_guid ' , $ message = sprintf ( __ ( 'skipping post no guid ' , 'push-syndication ' ) ), $ log_time = null , $ extra = array ( 'post ' => $ post ) );
13681356 continue ;
13691357 }
1370- $ post ['ID ' ] = $ post_id ;
1358+ $ post_id = $ this -> find_post_by_guid ( $ post ['post_guid ' ], $ post , $ site ) ;
13711359
1372- $ post = apply_filters ( 'syn_pull_edit_post ' , $ post , $ site , $ client );
1360+ if ( $ post_id ) {
1361+ $ pull_edit_shortcircuit = apply_filters ( 'syn_pre_pull_edit_post_shortcircuit ' , false , $ post , $ site , $ transport_type , $ client );
1362+ if ( true === $ pull_edit_shortcircuit ) {
1363+ Syndication_Logger::log_post_info ( $ site_id , $ status = 'skip_pre_pull_edit_post ' , $ message = sprintf ( __ ( 'skipping post per syn_pre_pull_edit_post_shortcircuit ' , 'push-syndication ' ) ), $ log_time = null , $ extra = array ( 'post ' => $ post ) );
1364+ continue ;
1365+ }
1366+ // if updation is disabled continue
1367+ if ( $ this ->push_syndicate_settings ['update_pulled_posts ' ] != 'on ' ) {
1368+ Syndication_Logger::log_post_info ( $ site_id , $ status = 'skip_update_pulled_posts ' , $ message = sprintf ( __ ( 'skipping post update per update_pulled_posts setting ' , 'push-syndication ' ) ), $ log_time = null , $ extra = array ( 'post ' => $ post ) );
1369+ continue ;
1370+ }
1371+ $ post ['ID ' ] = $ post_id ;
13731372
1374- $ result = wp_update_post ( $ post , true );
1373+ $ post = apply_filters ( ' syn_pull_edit_post ' , $ post , $ site , $ client );
13751374
1376- do_action ( ' syn_post_pull_edit_post ' , $ result, $ post , $ site , $ transport_type , $ client );
1375+ $ result = wp_update_post ( $ post , true );
13771376
1378- $ updated_post_ids [] = ( int ) $ result ;
1377+ do_action ( ' syn_post_pull_edit_post ' , $ result , $ post , $ site , $ transport_type , $ client ) ;
13791378
1380- } else {
1381- $ pull_new_shortcircuit = apply_filters ( 'syn_pre_pull_new_post_shortcircuit ' , false , $ post , $ site , $ transport_type , $ client );
1382- if ( true === $ pull_new_shortcircuit ) {
1383- Syndication_Logger::log_post_info ( $ site_id , $ status = 'syn_pre_pull_new_post_shortcircuit ' , $ message = sprintf ( __ ( 'skipping post per syn_pre_pull_edit_post_shortcircuit ' , 'push-syndication ' ) ), $ log_time = null , $ extra = array ( 'post ' => $ post ) );
1384- continue ;
1385- }
1386- $ post = apply_filters ( 'syn_pull_new_post ' , $ post , $ site , $ client );
1379+ $ updated_post_ids [] = (int ) $ result ;
13871380
1388- $ result = wp_insert_post ( $ post , true );
1381+ } else {
1382+ $ pull_new_shortcircuit = apply_filters ( 'syn_pre_pull_new_post_shortcircuit ' , false , $ post , $ site , $ transport_type , $ client );
1383+ if ( true === $ pull_new_shortcircuit ) {
1384+ Syndication_Logger::log_post_info ( $ site_id , $ status = 'syn_pre_pull_new_post_shortcircuit ' , $ message = sprintf ( __ ( 'skipping post per syn_pre_pull_edit_post_shortcircuit ' , 'push-syndication ' ) ), $ log_time = null , $ extra = array ( 'post ' => $ post ) );
1385+ continue ;
1386+ }
1387+ $ post = apply_filters ( 'syn_pull_new_post ' , $ post , $ site , $ client );
13891388
1390- do_action ( ' syn_post_pull_new_post ' , $ result, $ post , $ site , $ transport_type , $ client );
1389+ $ result = wp_insert_post ( $ post , true );
13911390
1392- if ( !is_wp_error ( $ result ) ) {
1393- update_post_meta ( $ result , 'syn_post_guid ' , $ post ['post_guid ' ] );
1394- update_post_meta ( $ result , 'syn_source_site_id ' , $ site_id );
1395- }
1391+ do_action ( 'syn_post_pull_new_post ' , $ result , $ post , $ site , $ transport_type , $ client );
13961392
1397- $ updated_post_ids [] = (int ) $ result ;
1393+ if ( !is_wp_error ( $ result ) ) {
1394+ update_post_meta ( $ result , 'syn_post_guid ' , $ post ['post_guid ' ] );
1395+ update_post_meta ( $ result , 'syn_source_site_id ' , $ site_id );
1396+ }
1397+
1398+ $ updated_post_ids [] = (int ) $ result ;
1399+ }
13981400 }
1399- }
14001401
1401- foreach ( $ post_types_processed as $ post_type ) {
1402- add_post_type_support ( $ post_type , 'revisions ' );
1402+ foreach ( $ post_types_processed as $ post_type ) {
1403+ add_post_type_support ( $ post_type , 'revisions ' );
1404+ }
14031405 }
14041406
14051407 update_post_meta ( $ site_id , 'syn_last_pull_time ' , current_time ( 'timestamp ' , 1 ) );
0 commit comments