Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. <?php
  2. $router->rewrite('/some/arbitrary/url/{slug}', function($slug) {
  3. // you can do anything here
  4. update_option('option_name', $slug);
  5. // if you return false, the request is over
  6. //return false;
  7. // if you return a string, WordPress will try to load a template by that name
  8. return 'my-custom-template';
  9. });
  10.  
  11. // you can also use Router::rewrite for more traditional rewrites to index.php
  12. $router->rewrite('/some/other/url/{slug}', 'index.php?slug=$matches[1]');
  13.  
  14. // and if you want to add to the REST API, that's easy too:
  15. $router->get('/my/custom/endpoint', function() {
  16. // you can do anything here
  17. // and whatever you return will be transformed into JSON
  18. return [ 'foo' => 'bar' ];
  19. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement