[wp-trac] [WordPress Trac] #46300: Return type/value of get_site is not being checked in wp_insert_site

WordPress Trac noreply at wordpress.org
Thu Feb 21 21:13:28 UTC 2019


#46300: Return type/value of get_site is not being checked in wp_insert_site
--------------------------------+-----------------------------
 Reporter:  david.binda         |      Owner:  (none)
     Type:  enhancement         |     Status:  new
 Priority:  normal              |  Milestone:  Awaiting Review
Component:  Networks and Sites  |    Version:  trunk
 Severity:  normal              |   Keywords:
  Focuses:  multisite           |
--------------------------------+-----------------------------
 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`).

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/46300>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list