[wp-trac] [WordPress Trac] #50786: REST API: delete post from block editor triggers a warning

WordPress Trac noreply at wordpress.org
Mon Jul 27 15:08:38 UTC 2020


#50786: REST API: delete post from block editor triggers a warning
--------------------------+-----------------------------
 Reporter:  manooweb      |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  REST API      |    Version:  trunk
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 Hello,

 Tested with WordPress 5.5-beta3-48630

 When I tried to delete a post from the block editor by using the "Move to
 trash" link, I obtained a warning in the debug log file with this stack
 trace.

 {{{
 [27-Jul-2020 14:15:56 UTC] PHP Warning:  array_key_exists() expects
 parameter 2 to be array, null given in C:\wamp64\www\wpbeta\wp-includes
 \rest-api\class-wp-rest-request.php on line 436
 [27-Jul-2020 14:15:56 UTC] PHP Stack trace:
 [27-Jul-2020 14:15:56 UTC] PHP   1. {main}()
 C:\wamp64\www\wpbeta\index.php:0
 [27-Jul-2020 14:15:56 UTC] PHP   2. require()
 C:\wamp64\www\wpbeta\index.php:17
 [27-Jul-2020 14:15:56 UTC] PHP   3. wp($query_vars = *uninitialized*)
 C:\wamp64\www\wpbeta\wp-blog-header.php:16
 [27-Jul-2020 14:15:56 UTC] PHP   4. WP->main($query_args =
 *uninitialized*) C:\wamp64\www\wpbeta\wp-includes\functions.php:1285
 [27-Jul-2020 14:15:56 UTC] PHP   5. WP->parse_request($extra_query_vars =
 *uninitialized*) C:\wamp64\www\wpbeta\wp-includes\class-wp.php:745
 [27-Jul-2020 14:15:56 UTC] PHP   6. do_action_ref_array($tag =
 *uninitialized*, $args = *uninitialized*) C:\wamp64\www\wpbeta\wp-includes
 \class-wp.php:388
 [27-Jul-2020 14:15:56 UTC] PHP   7. WP_Hook->do_action($args =
 *uninitialized*) C:\wamp64\www\wpbeta\wp-includes\plugin.php:544
 [27-Jul-2020 14:15:56 UTC] PHP   8. WP_Hook->apply_filters($value =
 *uninitialized*, $args = *uninitialized*) C:\wamp64\www\wpbeta\wp-includes
 \class-wp-hook.php:311
 [27-Jul-2020 14:15:56 UTC] PHP   9. rest_api_loaded(*uninitialized*)
 C:\wamp64\www\wpbeta\wp-includes\class-wp-hook.php:287
 [27-Jul-2020 14:15:56 UTC] PHP  10. WP_REST_Server->serve_request($path =
 *uninitialized*) C:\wamp64\www\wpbeta\wp-includes\rest-api.php:338
 [27-Jul-2020 14:15:56 UTC] PHP  11. WP_REST_Server->dispatch($request =
 *uninitialized*) C:\wamp64\www\wpbeta\wp-includes\rest-api\class-wp-rest-
 server.php:376
 [27-Jul-2020 14:15:56 UTC] PHP  12.
 WP_REST_Posts_Controller->delete_item($request = *uninitialized*)
 C:\wamp64\www\wpbeta\wp-includes\rest-api\class-wp-rest-server.php:1050
 [27-Jul-2020 14:15:56 UTC] PHP  13. WP_REST_Request->set_param($key =
 *uninitialized*, $value = *uninitialized*) C:\wamp64\www\wpbeta\wp-
 includes\rest-api\endpoints\class-wp-rest-posts-controller.php:906
 }}}

 Indeed the code of the WP_REST_Request::set_param method changed in
 WordPress 5.5 from WordPress 5.4

 in 5.4

 {{{
         public function set_param( $key, $value ) {
                 $order                             =
 $this->get_parameter_order();
                 $this->params[ $order[0] ][ $key ] = $value;
         }

 }}}

 https://github.com/WordPress/WordPress/blob/5.4-branch/wp-includes/rest-
 api/class-wp-rest-request.php#L428-L431

 in 5.5


 {{{
         public function set_param( $key, $value ) {
                 $order     = $this->get_parameter_order();
                 $found_key = false;

                 foreach ( $order as $type ) {
                         if ( 'defaults' !== $type && array_key_exists(
 $key, $this->params[ $type ] ) ) {
                                 $this->params[ $type ][ $key ] = $value;
                                 $found_key                     = true;
                         }
                 }

                 if ( ! $found_key ) {
                         $this->params[ $order[0] ][ $key ] = $value;
                 }
         }

 }}}

 https://github.com/WordPress/WordPress/blob/master/wp-includes/rest-api
 /class-wp-rest-request.php#L431-L445


 At line 436 where the warning is triggered, the JSON key isn't initialized
 as an array as expected by the array_key_exists function but is null which
 causes the issue.

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


More information about the wp-trac mailing list