• REST API: add new route

    Read more

    Create new routes likes https://wp_url/wp-json/dev/v1/some-endpoint

    add_action( 'rest_api_init', 'dev__rest_api_init');
    
    function dev__rest_api_init (){
    
    	register_rest_route(
    		'dev/v1',
    		'/some-endpoint/',
    		array(
    			'methods' => 'GET',
    			'callback' => 'dev__infos__get',
    		)
    	);
    
    }
    
    function dev__infos__get() {
    
    	$data = array(...);
    
    	$response = new WP_REST_Response( $data );
    	$response->set_status( 200 );
    
    	return $response;
    
    }

    Sources:

    • https://developer.wordpress.org/rest-api/extending-the-rest-api/adding-custom-endpoints/
    • https://developer.wordpress.org/reference/functions/register_rest_route/