Filter lmfwc_rest_api_pre_response not working correctly
-
Hello,
I use the REST API to get license info, using the v2/licenses/{license_key} endpoint. I want to filter the response data so I found the lmfwc_rest_api_pre_response filter.
There are 2 problems:
- The arguments for the protected function response function are in the wrong order. When you call this function from inside public function getLicense , you pass the arguments in this order: success, data, code, route. But in the response() function, the arguments for route and code are inverted. So the $route parameter has the value of $code and vice versa. So when I try to use the ‘lmfwc_rest_api_pre_response’, the $route parameter has the value “200” which is totally useless, and not the api route, so I can filter only the kind of request I want.
- The other problem (not exactly problem because it works), is that the filter is written in a wrong way. If you check the doc https://developer.www.ads-software.com/reference/functions/apply_filters/ you will see that the first parameter is the $hook_name, the SECOND is the VALUE to filter, and all the rest are just other args to help us filter more precisely. So the problem is in the second parameter, which should be the $data, and after that the $route and $_SERVER[‘REQUEST_METHOD’] should follow (3rd and 4th). This is why you have to use the add_filter(‘lmfwc_rest_api_pre_response’, array($this, ‘preResponse’), 1, 3); in the api setup, and add a filter in your own hook which is totally unneeded if the apply_filters function is written correctly. But probably you already know this, but you don’t want to change your codebase that much.
I would be grateful if you could fix at least the main problem (1) which the wrong arguments order. This is a fairly simple fix, is it possible that you can make it happen any time soon?
Thank you
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- You must be logged in to reply to this topic.