fix: prevent PHP warnings when pull_content receives non-array posts#151
Merged
GaryJones merged 1 commit intoAutomattic:developfrom Jan 3, 2026
Conversation
0ac8526 to
0eab816
Compare
0eab816 to
ab31137
Compare
ab31137 to
6b33a5d
Compare
When a syndication client's get_posts() method returns a non-array value (e.g., false, null), the pull_content() method would trigger PHP warnings from count() and foreach operations on non-array values. Added is_array() checks before array operations to handle cases where the client returns an error or empty response. Also fixed indentation issue where syn_last_pull_time update was incorrectly nested inside the posts processing block, causing it to not update when there were no posts to process. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Gary Jones <gary@garyjones.io> Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
3d8d1d7 to
6d35469
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Prevents PHP warnings when
pull_content()receives non-array responses from syndication clients.Problem
When a client's
get_posts()method returns a non-array value (e.g.,false,null, or an error), the code would trigger PHP warnings:count()on non-array → Warning on PHP 7.2+, TypeError on PHP 8+foreachon non-array → WarningSolution
Added
is_array($posts)checks before:count($posts)at line 1340foreach($posts as $post)loop at line 1346Also fixed an indentation bug where
syn_last_pull_timewas incorrectly nested inside the posts processing block, causing it to not update when there were no posts to process.Test plan
false,null, and empty arraysyn_last_pull_timeis updated even when no posts are returnedCo-authored-by: Gary Jones gary@garyjones.io
🤖 Generated with Claude Code