Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $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' ];
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement