Opened 7 years ago
Closed 7 years ago
#41555 closed defect (bug) (fixed)
REST API: Call `rest_get_server()` instead of accessing the `$wp_rest_server` global
Reported by: | jnylen0 | Owned by: | jnylen0 |
---|---|---|---|
Milestone: | 4.9 | Priority: | normal |
Severity: | normal | Version: | 4.4 |
Component: | REST API | Keywords: | has-patch has-unit-tests commit |
Focuses: | rest-api | Cc: |
Description
It is possible, though unlikely, that REST API functions can be called from within a context that has not actually loaded a WP_REST_Server
instance into the $wp_rest_server
variable. This has caused a few crashes on WP.com; details are well within the nightmare zone of customized WordPress load order.
There is already a rest_get_server()
function to ensure that the server object is initialized before attempting to do anything with it; we should be consistent in using this function rather than the global variable.
This was mostly done in [36529] (cc @rmccue); the patch attached here cleans up all remaining uses of $wp_rest_server
except for those within the rest_get_server()
function, along with a few errant @global
annotations.
Attachments (3)
Change History (6)
#1
@
7 years ago
- Keywords has-unit-tests added
Added a unit test in 41555.2.diff. Before these changes, it fails with the same message we saw on WP.com:
Fatal error: Call to a member function register_route() on null in src/wp-includes/rest-api.php on line 77
Add a previously failing test case