Skip to content

fix: prevent PHP warnings when pull_content receives non-array posts#151

Merged
GaryJones merged 1 commit intoAutomattic:developfrom
shantanu2704:fix/php-warnings-in-class-wp-push-syndication-server
Jan 3, 2026
Merged

fix: prevent PHP warnings when pull_content receives non-array posts#151
GaryJones merged 1 commit intoAutomattic:developfrom
shantanu2704:fix/php-warnings-in-class-wp-push-syndication-server

Conversation

@shantanu2704
Copy link
Contributor

@shantanu2704 shantanu2704 commented Dec 17, 2018

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+
  • foreach on non-array → Warning

Solution

Added is_array($posts) checks before:

  1. count($posts) at line 1340
  2. The foreach($posts as $post) loop at line 1346

Also fixed an indentation bug where syn_last_pull_time was incorrectly nested inside the posts processing block, causing it to not update when there were no posts to process.

Test plan

  • Added integration tests with mock client returning false, null, and empty array
  • Verified syn_last_pull_time is updated even when no posts are returned
  • All existing tests pass

Co-authored-by: Gary Jones gary@garyjones.io

🤖 Generated with Claude Code

@GaryJones GaryJones changed the base branch from master to develop February 11, 2024 12:25
@GaryJones GaryJones added this to the 2.1.0 milestone Jan 2, 2026
@GaryJones GaryJones self-assigned this Jan 3, 2026
@GaryJones GaryJones added the type: bug Something isn't working label Jan 3, 2026
@GaryJones GaryJones force-pushed the fix/php-warnings-in-class-wp-push-syndication-server branch from 0ac8526 to 0eab816 Compare January 3, 2026 13:02
@GaryJones GaryJones requested a review from a team as a code owner January 3, 2026 13:02
@GaryJones GaryJones force-pushed the fix/php-warnings-in-class-wp-push-syndication-server branch from 0eab816 to ab31137 Compare January 3, 2026 13:20
@GaryJones GaryJones changed the title Add checks to prevent PHP warnings in class-wp-push-syndication-server fix: prevent PHP warnings when pull_content receives non-array posts Jan 3, 2026
@GaryJones GaryJones force-pushed the fix/php-warnings-in-class-wp-push-syndication-server branch from ab31137 to 6b33a5d Compare January 3, 2026 13:26
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>
@GaryJones GaryJones force-pushed the fix/php-warnings-in-class-wp-push-syndication-server branch 2 times, most recently from 3d8d1d7 to 6d35469 Compare January 3, 2026 13:45
@GaryJones GaryJones merged commit 42710f3 into Automattic:develop Jan 3, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants