3

When researching and reading about the WP REST API utilization I've seen many topics mentioned about how another version should be rolled out but nothing in the documentation regarding a return for a deprecated version. Planning the life span of an API and how I should develop for each version I was unsure how I should fire a return indicating a newer version is pushed.

For example:

add_action( 'rest_api_init', function () {
  register_rest_route( 'cpt/v1', '/all_posts/', array(
    'methods' => 'GET',
    'callback' => 'some_cpt',
  ) );
} );

if I were to change the route to:

add_action( 'rest_api_init', function () {
  register_rest_route( 'cpt/v2', '/all_posts/', array(
    'methods' => 'GET',
    'callback' => 'some_cpt',
  ) );
} );

what should I properly pass through v1 to indicate there is a new version? Was thinking of using WP_Error as it is shown but I'm unsure the code return and where to implement the WP_Error:

return new WP_Error( 'new_version_needed', 'Deprecated version', array( 'status' => 303 ) );

or:

return new WP_Error( 'new_version_needed', 'Deprecated version', array( 'status' => 410 ) );
  • I would just simply return a string stating it is deprecated. – ProEvilz Oct 25 '17 at 15:23
  • I understand that but where exactly and are you supposed to return it in the callback because what I've been led to believe the proper return should be done through WP_Error however, as linked, the documentation is limited. – DᴀʀᴛʜVᴀᴅᴇʀ Oct 25 '17 at 15:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.