Validate repo_info before accessing version#92
Open
apermo wants to merge 2 commits intoZodiac1978:developfrom
Open
Validate repo_info before accessing version#92apermo wants to merge 2 commits intoZodiac1978:developfrom
apermo wants to merge 2 commits intoZodiac1978:developfrom
Conversation
Contributor
Author
|
Fixed — moved the |
apermo
commented
Apr 14, 2026
| $report['repo_info'] = $returned_object; | ||
| // Cache the report. | ||
| set_site_transient( $cache_key, $report, self::CACHE_LIFETIME ); | ||
| } |
Contributor
Author
There was a problem hiding this comment.
@Zodiac1978 Maybe we could add an else branch here to log the error? Your thoughts?
plugins_api() can return a valid object (not WP_Error) that lacks expected properties like `version`. This happens with plugins like Search & Filter Pro whose slug collides with a wp.org entry returning invalid data. Guard against this in two places: - assemble_plugin_report(): reject API responses missing `version` before caching as repo_info - render_table_row(): add isset() check on version, consistent with tested/rating/last_updated guards Fixes Zodiac1978#56
Move the isset(version) check inside the non-error branch so the else is only reached for WP_Error, letting PHPStan narrow the type correctly.
3045426 to
f5de638
Compare
This was referenced Apr 14, 2026
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
plugins_api()responses missing theversionproperty before storing asrepo_info(prevents caching invalid data)isset( $report['repo_info']->version )guard in the version column ofrender_table_row()(protects against stale cache entries)This is consistent with how
tested,last_updated,num_ratings, andratingare already guarded withisset()on lines 536, 546, 554.Fixes #56
Context
plugins_api()can return a valid stdClass (not aWP_Error) that lacks expected properties. This happens when a premium plugin's slug collides with a wordpress.org entry that returns invalid data (e.g. Search & Filter Pro — see #56 comments). The object passes the! is_wp_error()check but accessing->versiontriggers PHP warnings.Test in WordPress Playground
Both Playground instances include a mu-plugin that strips the
versionproperty from Classic Editor'splugins_api()response, reproducing the Search & Filter Pro scenario from #56.Before (develop — shows the bug): Open in WordPress Playground
After (this branch — bug fixed): Open in WordPress Playground
Both instances include a mu-plugin that hooks
plugins_api_resultto strip theversionproperty from Classic Editor's API response, reproducing the Search & Filter Pro scenario. In the Before instance, this causes PHP warnings that corrupt the AJAX response — the Classic Editor row fails to load. In the After instance, the invalid response is handled gracefully.Pre-installed plugins:
Test plan