#46300 closed enhancement (fixed)
Return type/value of get_site is not being checked in wp_insert_site
Reported by: | david.binda | Owned by: | SergeyBiryukov |
---|---|---|---|
Milestone: | 5.1.1 | Priority: | normal |
Severity: | normal | Version: | 5.1 |
Component: | Networks and Sites | Keywords: | has-patch commit |
Focuses: | multisite | Cc: |
Description
The get_site
function may return null
in case the site is not found ( see https://core.trac.wordpress.org/browser/trunk/src/wp-includes/ms-site.php?rev=44727#L293 ), otherwise returns a WP_Site
object.
The function is being called from inside the wp_insert_site
(see https://core.trac.wordpress.org/browser/trunk/src/wp-includes/ms-site.php?rev=44727#L70 ) and the WP_Site
object is implicitly expected, as the follow-up code treats the $new_site
variable as an object (eg.: https://core.trac.wordpress.org/browser/trunk/src/wp-includes/ms-site.php?rev=44727#L114).
I haven't run into any issues, but it might be worth checking the return type and return WP_Error
out of the wp_insert_site
instead of 0
in case the call to get_site
fails. (the 0
would be an result of null->id
, producing null
casted to int
).
Attachments (2)
Change History (12)
This ticket was mentioned in Slack in #core-multisite by lukecarbis. View the logs.
6 years ago
This ticket was mentioned in Slack in #core by lukecarbis. View the logs.
6 years ago
#6
@
6 years ago
The patch looks good to me, except for the typo in the error message (/retrieves/retrieve/
).
Good find, thanks @davidbinda! Putting this in 5.1.1, as it's mostly about better error case handling. If
get_site()
has failed immediately after the$wpdb->insert()
succeeds, there are probably bigger problems. 🙂