“Argument 1 passed to function must be an instance of WP_REST_Request, string given”


I have a plugin that I’m working on, and the POST endpoint is behaving oddly. I’m getting the error mesage seen in the title of this post; I have one other endpoint in the plugin that’s working just fine. My code:

function get_awesome_params( WP_REST_Request $request ) {
  $parameters = $request->get_params();
  return new WP_REST_Response($parameters, 200);

add_action('rest_api_init', function() {
  register_rest_route('cbd/v1', '/cbdproducts', array(
    'methods' => WP_REST_SERVER::CREATABLE,
    'callback' => 'get_awesome_params',
    'args' => array(),
    'permission_callback' => function () {
      return true;

If I remove the typing and just pass in ‘$request’, then it thinks it’s just a string and the getter called in the function doesn’t work.

, Michael C 4 years 2020-02-29T08:40:45-05:00 0 Answers 102 views 0

Leave an answer