Create a gist now

Instantly share code, notes, and snippets.

What routing looks like in an Illuminated WordPress Plugin
<?php
// in your plugin's src/routes.php file
$router->rewrite('/some/arbitrary/url/{slug}', function($slug) {
// you can do anything here
update_option('option_name', $slug);
// if you return false, the request is over
//return false;
// if you return a string, WordPress will try to load a template by that name
return 'my-custom-template';
});
// you can also use Router::rewrite for more traditional rewrites to index.php
$router->rewrite('/some/other/url/{slug}', 'index.php?slug=$matches[1]');
// and if you want to add to the REST API, that's easy too:
$router->get('/my/custom/endpoint', function() {
// you can do anything here
// and whatever you return will be transformed into JSON
return [ 'foo' => 'bar' ];
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment