Skip to content

Commit 0ac8526

Browse files
committed
Add checks to prevent PHP warnings in class-wp-push-syndication-server
1 parent 61c7e51 commit 0ac8526

File tree

1 file changed

+46
-45
lines changed

1 file changed

+46
-45
lines changed

includes/class-wp-push-syndication-server.php

Lines changed: 46 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,72 +1331,73 @@ public function pull_content( $sites = array() ) {
13311331

13321332
$post_types_processed = array();
13331333

1334-
if ( count( $posts ) > 0 ) {
1334+
if ( is_array( $posts ) && count( $posts ) > 0 ) {
13351335
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() );
13361336
} else {
13371337
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() );
13381338
}
13391339

1340-
foreach( $posts as $post ) {
1340+
if ( is_array( $posts ) && ! empty( $posts) ) {
1341+
foreach( $posts as $post ) {
13411342

1342-
if ( ! in_array( $post['post_type'], $post_types_processed ) ) {
1343-
remove_post_type_support( $post['post_type'], 'revisions' );
1344-
$post_types_processed[] = $post['post_type'];
1345-
}
1346-
1347-
if ( empty( $post['post_guid'] ) ) {
1348-
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 ) );
1349-
continue;
1350-
}
1351-
$post_id = $this->find_post_by_guid( $post['post_guid'], $post, $site );
1352-
1353-
if ( $post_id ) {
1354-
$pull_edit_shortcircuit = apply_filters( 'syn_pre_pull_edit_post_shortcircuit', false, $post, $site, $transport_type, $client );
1355-
if ( true === $pull_edit_shortcircuit ) {
1356-
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 ) );
1357-
continue;
1343+
if ( ! in_array( $post['post_type'], $post_types_processed ) ) {
1344+
remove_post_type_support( $post['post_type'], 'revisions' );
1345+
$post_types_processed[] = $post['post_type'];
13581346
}
1359-
// if updation is disabled continue
1360-
if( $this->push_syndicate_settings['update_pulled_posts'] != 'on' ) {
1361-
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 ) );
1347+
1348+
if ( empty( $post['post_guid'] ) ) {
1349+
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 ) );
13621350
continue;
13631351
}
1364-
$post['ID'] = $post_id;
1352+
$post_id = $this->find_post_by_guid( $post['post_guid'], $post, $site );
13651353

1366-
$post = apply_filters( 'syn_pull_edit_post', $post, $site, $client );
1354+
if ( $post_id ) {
1355+
$pull_edit_shortcircuit = apply_filters( 'syn_pre_pull_edit_post_shortcircuit', false, $post, $site, $transport_type, $client );
1356+
if ( true === $pull_edit_shortcircuit ) {
1357+
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 ) );
1358+
continue;
1359+
}
1360+
// if updation is disabled continue
1361+
if( $this->push_syndicate_settings['update_pulled_posts'] != 'on' ) {
1362+
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 ) );
1363+
continue;
1364+
}
1365+
$post['ID'] = $post_id;
13671366

1368-
$result = wp_update_post( $post, true );
1367+
$post = apply_filters( 'syn_pull_edit_post', $post, $site, $client );
13691368

1370-
do_action( 'syn_post_pull_edit_post', $result, $post, $site, $transport_type, $client );
1369+
$result = wp_update_post( $post, true );
13711370

1372-
$updated_post_ids[] = (int) $result;
1371+
do_action( 'syn_post_pull_edit_post', $result, $post, $site, $transport_type, $client );
13731372

1374-
} else {
1375-
$pull_new_shortcircuit = apply_filters( 'syn_pre_pull_new_post_shortcircuit', false, $post, $site, $transport_type, $client );
1376-
if ( true === $pull_new_shortcircuit ) {
1377-
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 ) );
1378-
continue;
1379-
}
1380-
$post = apply_filters( 'syn_pull_new_post', $post, $site, $client );
1373+
$updated_post_ids[] = (int) $result;
13811374

1382-
$result = wp_insert_post( $post, true );
1375+
} else {
1376+
$pull_new_shortcircuit = apply_filters( 'syn_pre_pull_new_post_shortcircuit', false, $post, $site, $transport_type, $client );
1377+
if ( true === $pull_new_shortcircuit ) {
1378+
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 ) );
1379+
continue;
1380+
}
1381+
$post = apply_filters( 'syn_pull_new_post', $post, $site, $client );
13831382

1384-
do_action( 'syn_post_pull_new_post', $result, $post, $site, $transport_type, $client );
1383+
$result = wp_insert_post( $post, true );
13851384

1386-
if( !is_wp_error( $result ) ) {
1387-
update_post_meta( $result, 'syn_post_guid', $post['post_guid'] );
1388-
update_post_meta( $result, 'syn_source_site_id', $site_id );
1389-
}
1385+
do_action( 'syn_post_pull_new_post', $result, $post, $site, $transport_type, $client );
1386+
1387+
if( !is_wp_error( $result ) ) {
1388+
update_post_meta( $result, 'syn_post_guid', $post['post_guid'] );
1389+
update_post_meta( $result, 'syn_source_site_id', $site_id );
1390+
}
13901391

1391-
$updated_post_ids[] = (int) $result;
1392+
$updated_post_ids[] = (int) $result;
1393+
}
13921394
}
1393-
}
13941395

1395-
foreach ( $post_types_processed as $post_type ) {
1396-
add_post_type_support( $post_type, 'revisions' );
1396+
foreach ( $post_types_processed as $post_type ) {
1397+
add_post_type_support( $post_type, 'revisions' );
1398+
}
13971399
}
1398-
1399-
update_post_meta( $site_id, 'syn_last_pull_time', current_time( 'timestamp', 1 ) );
1400+
update_post_meta( $site_id, 'syn_last_pull_time', current_time( 'timestamp', 1 ) );
14001401
}
14011402

14021403
// Resume comment and term counting and cache invalidation.

0 commit comments

Comments
 (0)