#29583 closed defect (bug) (fixed)
The getter in WP_Error may cause an "Undefined property" notice
Reported by: | bjornjohansen | Owned by: | SergeyBiryukov |
---|---|---|---|
Milestone: | 4.1 | Priority: | normal |
Severity: | normal | Version: | 4.0 |
Component: | General | Keywords: | has-patch |
Focuses: | Cc: |
Description
Since the getter doesn't check whether the requested property actually exists before trying to return it, it may cause an "Undefined property" notice.
This happens on the update page in wp-admin if the compatibility of a plugin is unknown.
Attached patch sets default return value to null and only return the value of the requested property if it actually is set.
Attachments (3)
Change History (15)
#3
@
10 years ago
+1 for 29583.patch. An alternative would be to ensure a filtered response of plugins_api()
always includes compatibility
and tested
.
#4
@
10 years ago
This (both existing and proposed code) seems like a lot of work to avoid an is_wp_error() check.
#5
@
10 years ago
I'm getting these notices too. It seems there are two issues here - one the overall handling of get calls on properties that don't exist and second the code that calls these things..
I'd propose that these are handled as two separate tickets. Clearing the notice does not need to be bogged down in the debate about how to handle the version check. I think serge's and Jeremy's code should be split off to another ticket.
NOTE: My original code returned a false. I've modified to make it match the null in bjorn's code. Null is probably correct, but TBH I'd have to test the exact code to be fully satisfied of which the notice producing code originally returned.
#6
follow-up:
↓ 7
@
10 years ago
The same notice will show up in other places as well, due to missing is_wp_error() checks. Today I got it while using get_terms with 'hide_empty' => false and all the terms in the taxonomy were empty (will create separate ticket for that).
I suggest we do as Brian is proposing: Fix the getter and move the missing is_wp_error() checks to separate tickets (even though the cases might never be discovered as soon as the getter is fixed).
#7
in reply to:
↑ 6
@
10 years ago
Replying to bjornjohansen:
The same notice will show up in other places as well, due to missing is_wp_error() checks.
That's the point. A missing is_wp_error()
check indicates a developer error, we should not hide these notices.
#8
@
10 years ago
- Owner set to SergeyBiryukov
- Resolution set to fixed
- Status changed from new to closed
In 29825:
Reproduced the notice if
plugins_api()
returns aWP_Error
:We should probably check if
$info->compatibility
is set inupdate-core.php
, like we do for$info->tested
. See 29583.patch.