[wp-trac] [WordPress Trac] #50318: REST API: Preloading silences deprecation errors

WordPress Trac noreply at wordpress.org
Thu Jun 4 17:01:02 UTC 2020


#50318: REST API: Preloading silences deprecation errors
--------------------------+-----------------------------
 Reporter:  dlh           |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  REST API      |    Version:  4.4
 Severity:  normal        |   Keywords:  has-patch
  Focuses:                |
--------------------------+-----------------------------
 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.

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


More information about the wp-trac mailing list