Custom endpoint without loading entire WordPress

With only WooCommerce installed the WordPress rest api loading time is above 1.5s, this is unpractical, so i’m trying to create a custom endpoint and define SHORTINIT to true to load the minimum possible, but the custom endpoint is not available. Code is in a folder inside my theme outside of wordpress scope.

define(‘SHORTINIT’, true);

require_once $_SERVER[‘DOCUMENT_ROOT’] . ‘/wp-load.php’;

function custom_endpoint() {
register_rest_route( ‘test’, ‘route’, array(
‘methods’ => ‘GET’,
‘callback’ => ‘custom_return’,
)
);
}
add_action( ‘rest_api_init’, ‘custom_endpoint’ );

function custom_return() {
return rest_ensure_response( ‘Hello World! This is my first REST API’ );
}

Read more here:: Custom endpoint without loading entire WordPress

Leave a Reply

Your email address will not be published. Required fields are marked *