Prevent fatal error in od_get_current_url_metrics_etag() when $wp_query->posts is null#2347
Prevent fatal error in od_get_current_url_metrics_etag() when $wp_query->posts is null#2347westonruter merged 3 commits intotrunkfrom
od_get_current_url_metrics_etag() when $wp_query->posts is null#2347Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @sjlangley. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Build for testing: |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## trunk #2347 +/- ##
=======================================
Coverage 69.21% 69.21%
=======================================
Files 90 90
Lines 7703 7703
=======================================
Hits 5332 5332
Misses 2371 2371
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR prevents a fatal error in od_get_current_url_metrics_etag() when WP_Query::$posts is null instead of an array. The fix addresses issue #2345 by adding a type check before passing the property to array_map().
Changes:
- Updated the condition check from
post_count > 0tois_array( $wp_query->posts )to handle null values - Added a test case to verify the function handles null
$wp_query->postswithout errors
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| plugins/optimization-detective/storage/data.php | Changed condition to explicitly check if $wp_query->posts is an array before using it with array_map() |
| plugins/optimization-detective/tests/storage/test-data.php | Added test case that simulates null $wp_query->posts by unsetting it |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
284b3e2 to
ff0c3a3
Compare
|
@westonruter was this PR supposed to be auto merged? |
|
@b1ink0 yes, I enabled auto-merge. |
|
Oh okay, I just wanted to make sure it was internal. |
Summary
Fixes #2345
Relevant technical choices
It turns out that
WP_Query::$postsis defined as:Note: it can be
null!This ensures no error occurs in that case.