Opened 4 years ago
Closed 4 years ago
#50318 closed defect (bug) (fixed)
REST API: Preloading silences deprecation errors
Reported by: | dlh | Owned by: | whyisjake |
---|---|---|---|
Milestone: | 5.5 | Priority: | normal |
Severity: | normal | Version: | 4.4 |
Component: | REST API | Keywords: | has-patch commit |
Focuses: | Cc: |
Description
Loading a post in the block editor involves preloading data from the REST API via rest_preload_api_request()
. This initializes the REST server, including rest_api_default_filters()
on rest_api_init
, which, in turn, invokes the REST deprecation handlers that covert the errors to headers rather than calling trigger_error()
.
To replicate, enable WP_DEBUG
and add this hook:
<?php add_action( 'admin_footer', function () { _deprecated_function( 'oops', '1.2.3' ); } );
This code will trigger an error when /wp-admin/edit.php
is loaded, but not /wp-admin/post-new.php
.
The attached patch would address this inconsistency in a somewhat naive way by just checking for REST_REQUEST
before adding the deprecation handlers (which would also address the problem for all internal uses of the API, not just preloading). I'm open to ideas that are a little leaner.
I think this is one of the times that checking for
REST_REQUEST
is the right way to go about it.