REST endpoint generator
register_rest_route with permissions, ready to use.
Genuinely free. No sign-up, no email, no limits, no cookies. We don't store the URL you analyse.
Code
<?php
add_action( 'rest_api_init', function () {
register_rest_route( 'myplugin/v1', '/items', array(
'methods' => 'GET',
'callback' => function ( WP_REST_Request $request ) {
return new WP_REST_Response( array( 'ok' => true ), 200 );
},
'permission_callback' => '__return_true',
) );
} );
// Endpoint: /wp-json/myplugin/v1/itemsWhat it's for
Adding an endpoint to the WordPress REST API needs register_rest_route with a namespace, a route and the permission_callback (too often forgotten). Here you get the correct structure, with permissions already in place.
Frequently asked questions
›Why does permission_callback matter?
Because without it the endpoint is public and WordPress shows a warning. Defining it (even just __return_true if it's intentionally public) is required for a correct registration.