Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rest_api_init event not fired

I am trying to run custom plugin on wp 4.7.4 . Below is my simple plugin

add_action( 'rest_api_init', 'register_routes');


function register_routes() {
   register_rest_route( 'taxonomy-manager/v1', '/taxonomies/(P<taxonomy_type>[a-zA-Z]+)', array(
   'methods' => 'GET',
   'callback' => 'get_or_insert'
  ) );
} 

function get_or_insert( WP_REST_Request $request ) {

   $parameters = $request->get_params();

   return $parameters;

}

When I request wp-json endpoint I see no plugin route there. Plugin was successfully activated. Have I missed something ? Does above plugin (or similar one based on rest_api_init event) works for anybody else ? Thanks.

like image 919
Anton Putau Avatar asked May 26 '17 14:05

Anton Putau


1 Answers

I got solution, You need to use wp-json with your URL... like https://yourdomain.com/wp-json/namespace/and-so-on/

Then it will work. I was missing wp-json in URL.

like image 65
Shakeel Ahmed Avatar answered Sep 17 '22 03:09

Shakeel Ahmed