Skip to content

Bug: return false aborts entire sync loop on first API failure #1109

Description

@Valyrian-Code

While reviewing sync-sched.php, I noticed that API failures inside the event sync loop currently terminate the entire sync process instead of skipping the failed event.

Current code (sync-sched.php, lines 53–55):

if ( is_wp_error( $data ) || ( wp_remote_retrieve_response_code( $data ) != 200 ) ) {
    return false;
}

This code runs inside a loop iterating through active events:

while ( $the_query->have_posts() )

Since the file is included from sync_sched(), return false exits the entire included file, not just the current iteration.

Impact

If a single sched.com API request fails (temporary 5xx, timeout, rate limit, etc.):

  • processing stops for all remaining events
  • later speaker/session data never gets synced
  • sync failures happen silently
  • update_option( 'lfevents_sync_sched_last_run', ... ) is skipped
  • downstream speaker blocks may show stale or missing session data

This effectively turns one transient API failure into a full sync interruption.

Proposed fix

Skip only the failed event instead of aborting the entire sync process:

if ( is_wp_error( $data ) || ( wp_remote_retrieve_response_code( $data ) != 200 ) ) {
    continue;
}

This allows the loop to continue syncing the remaining events even if one API request fails.

GIF

Would like to work on this fix and open a PR for it, if that sounds good.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions