Download the PHP package alleyinteractive/wp-path-dispatch without Composer
On this page you can find all versions of the php package alleyinteractive/wp-path-dispatch. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download alleyinteractive/wp-path-dispatch
More information about alleyinteractive/wp-path-dispatch
Files in alleyinteractive/wp-path-dispatch
Package wp-path-dispatch
Short Description Simply and easily add a URL which fires an action, triggers a callback, and/or loads a template.
License GPL-2.0-or-later
Homepage https://github.com/alleyinteractive/wp-path-dispatch
Informations about the package wp-path-dispatch
WP Path Dispatch
Simply and easily add a URL which fires an action, triggers a callback, and/or loads a template.
Installation
You can install the package via composer:
Usage
At any point before init,
This will cause http://domain.com/some-path/ to call some_function()
.
IMPORTANT! You must flush your rewrites after adding a path.
You can add multiple paths at once with add_paths()
:
The dispatch happens on parse_query
, so you can then modify the query via
pre_get_posts
or do whatever
you have to do. You can even just load a static file and exit if you simply need to render static content.
When the path is loaded, the action dispatch_path_{$path}
is fired. You can
hook onto this instead of or
in addition to passing a callback to add_path(s). The callback is optional.
Lastly, you can set custom rewrites if your paths are more complex. In these cases, the 'path' argument essentially becomes a slug. See add_rewrite_rule() for details about 'rule', 'redirect' (rewrite), and 'position'.
Full breakdown of all the path options
Examples
Simplest possible usages: fires the action 'dispatch_path_my-path' at http://domain.com/my-path/
This can even be simplified further as:
Call the function 'my_function' at http://domain.com/my-path/
Load the template file 'dispatch-custom-page.php' at http://domain.com/my-path/
Add a custom rewrite rule. Fires the action 'dispatch_path_my-path' at e.g. http://domain.com/my-path/foo/ and sets the query var 'my_path' to 'foo'. This assumes you already registered that query var.
Same as above, but registers the query var automatically, and loads the template 'dispatch-my-page.php'.
Same as above, but with multiple query vars, and with a callback instead of a template.
Changelog
Please see CHANGELOG for more information on what has changed recently.
Credits
This project is actively maintained by Alley Interactive. Like what you see? Come work with us.
- Matt Boynes
- All Contributors
License
The GNU General Public License (GPL) license. Please see License File for more information.