Make WordPress Core

Opened 4 years ago

Closed 4 years ago

#50318 closed defect (bug) (fixed)

REST API: Preloading silences deprecation errors

Reported by: dlh's profile dlh Owned by: whyisjake's profile whyisjake
Milestone: 5.5 Priority: normal
Severity: normal Version: 4.4
Component: REST API Keywords: has-patch commit
Focuses: Cc:


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:


	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.

Attachments (1)

50318.diff (1.1 KB) - added by dlh 4 years ago.

Download all attachments as: .zip

Change History (3)

4 years ago

#1 @TimothyBlynJacobs
4 years ago

  • Keywords commit added
  • Milestone changed from Awaiting Review to 5.5

I think this is one of the times that checking for REST_REQUEST is the right way to go about it.

#2 @whyisjake
4 years ago

  • Owner set to whyisjake
  • Resolution set to fixed
  • Status changed from new to closed

In 48150:

REST API: Ensure depracation errors are called while preloading data with the REST API.

Fixes #50318.

Props dlh, TimothyBlynJacobs.

Note: See TracTickets for help on using tickets.