[wp-trac] [WordPress Trac] #62163: WP_REST_Request::get_params() includes unregistered args including rest_route when not using pretty permalinks

WordPress Trac noreply at wordpress.org
Wed Jan 22 18:50:47 UTC 2025


#62163: WP_REST_Request::get_params() includes unregistered args including
rest_route when not using pretty permalinks
--------------------------------------+---------------------
 Reporter:  westonruter               |       Owner:  (none)
     Type:  defect (bug)              |      Status:  new
 Priority:  low                       |   Milestone:  6.8
Component:  REST API                  |     Version:  4.4
 Severity:  normal                    |  Resolution:
 Keywords:  good-first-bug has-patch  |     Focuses:
--------------------------------------+---------------------

Comment (by dilip2615):

 Hello @westonruter according to my thoughts, the
 WP_REST_Request::get_params() function includes all query parameters,
 including rest_route when pretty permalinks are disabled. To prevent this,
 you can manually unset the rest_route parameter before processing the
 request.
 {{{#!php
 <?php
 add_filter('rest_request_before_callbacks', function($response, $handler,
 $request) {
     if ($request->has_param('rest_route')) {
         $request->set_param('rest_route', null);
     }
     return $response;
 }, 10, 3);
 This filter ensures the rest_route parameter is removed, preventing
 unintended behavior while maintaining backward compatibility.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/62163#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list