Search code examples
phpwordpresswordpress-rest-api

WP Rest API: new route return rest_invalid_handler


This is a simple test script for create a new route:

add_action( 'rest_api_init', function () {
  register_rest_route( 'ass', '/ativar', array(
    'methods' => 'GET',
    'callback' => 'testing_route',
  ) );
} );

function testing_route($data){
    return array( 'message' => 'testing route' );
}

But it returning an error message:

rest_invalid_handler


Solution

  • Solved!

    'callback' => __NAMESPACE__ . '\\testing_route',