{"id":19107779,"url":"https://github.com/alleyinteractive/wp-path-dispatch","last_synced_at":"2025-06-15T18:36:32.982Z","repository":{"id":65747216,"uuid":"598724615","full_name":"alleyinteractive/wp-path-dispatch","owner":"alleyinteractive","description":" Simply and easily add a URL which fires an action, triggers a callback, and/or loads a template.","archived":false,"fork":false,"pushed_at":"2024-05-01T17:04:43.000Z","size":34,"stargazers_count":7,"open_issues_count":1,"forks_count":1,"subscribers_count":21,"default_branch":"develop","last_synced_at":"2025-06-01T22:00:31.572Z","etag":null,"topics":["wordpress","wordpress-package"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alleyinteractive.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-02-07T17:28:37.000Z","updated_at":"2024-07-01T09:26:38.000Z","dependencies_parsed_at":"2024-05-01T18:26:29.221Z","dependency_job_id":"3bf861e6-0fe7-46f9-bf40-4ed5453a5a7f","html_url":"https://github.com/alleyinteractive/wp-path-dispatch","commit_stats":{"total_commits":8,"total_committers":1,"mean_commits":8.0,"dds":0.0,"last_synced_commit":"e7c7f8b7dbb2437c4ebde0a3cb8bf3a67aeb5217"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":"alleyinteractive/create-php-package","purl":"pkg:github/alleyinteractive/wp-path-dispatch","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alleyinteractive%2Fwp-path-dispatch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alleyinteractive%2Fwp-path-dispatch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alleyinteractive%2Fwp-path-dispatch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alleyinteractive%2Fwp-path-dispatch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alleyinteractive","download_url":"https://codeload.github.com/alleyinteractive/wp-path-dispatch/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alleyinteractive%2Fwp-path-dispatch/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260028949,"owners_count":22948066,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["wordpress","wordpress-package"],"created_at":"2024-11-09T04:13:55.909Z","updated_at":"2025-06-15T18:36:32.930Z","avatar_url":"https://github.com/alleyinteractive.png","language":"PHP","readme":"# WP Path Dispatch\n\n[![Coding Standards](https://github.com/alleyinteractive/wp-path-dispatch/actions/workflows/coding-standards.yml/badge.svg)](https://github.com/alleyinteractive/wp-path-dispatch/actions/workflows/coding-standards.yml)\n[![Testing Suite](https://github.com/alleyinteractive/wp-path-dispatch/actions/workflows/unit-test.yml/badge.svg)](https://github.com/alleyinteractive/wp-path-dispatch/actions/workflows/unit-test.yml)\n\nSimply and easily add a URL which fires an action, triggers a callback, and/or\nloads a template.\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require alleyinteractive/wp-path-dispatch\n```\n\n## Usage\n\nAt any point before init,\n\n```php\n\\WP_Path_Dispatch\\Path_Dispatch()-\u003eadd_path(\n\t[\n\t\t'path'     =\u003e 'some-path',\n\t\t'callback' =\u003e 'some_function'\n\t]\n);\n```\n\nThis will cause http://domain.com/some-path/ to call `some_function()`.\n\nIMPORTANT! You must flush your rewrites after adding a path.\n\nYou can add multiple paths at once with `add_paths()`:\n\n```php\n\\WP_Path_Dispatch\\Path_Dispatch()-\u003eadd_paths(\n\t[\n\t\t[\n\t\t\t'path'     =\u003e 'some-path',\n\t\t\t'callback' =\u003e 'some_function',\n\t\t],\n\t\t[\n\t\t\t'path'     =\u003e 'custom-feed.json',\n\t\t\t'callback' =\u003e 'custom_feed',\n\t\t],\n\t\t[\n\t\t\t'path'     =\u003e 'custom-feed.xml',\n\t\t\t'callback' =\u003e 'custom_feed',\n\t\t],\n\t]\n);\n```\n\nThe dispatch happens on `parse_query`, so you can then modify the query via\n`pre_get_posts` or do whatever\nyou have to do. You can even just load a static file and exit if you simply need to render static content.\n\nWhen the path is loaded, the action `dispatch_path_{$path}` is fired. You can\nhook onto this instead of or\nin addition to passing a callback to add_path(s). The callback is optional.\n\nLastly, you can set custom rewrites if your paths are more complex. In these\ncases, the 'path' argument essentially becomes a slug. See\n[add_rewrite_rule()](http://codex.wordpress.org/Rewrite_API/add_rewrite_rule)\nfor details about 'rule', 'redirect' (rewrite), and 'position'.\n\n## Full breakdown of all the path options\n\n```php\n\\WP_Path_Dispatch\\Path_Dispatch()-\u003eadd_path(\n\t[\n\t\t'path'     =\u003e 'some-path',     // required\n\t\t'callback' =\u003e 'some_function', // optional\n\t\t'action'   =\u003e '',              // fire this action instead of dispatch_path_{$path}\n\t\t'template' =\u003e '',              // optional\n\t\t'rewrite'  =\u003e [                // optional\n\t\t\t'query_vars' =\u003e [],                               // optional\n\t\t\t'rule'       =\u003e '',                               // required (assuming 'rewrite' is set)\n\t\t\t'redirect'   =\u003e 'index.php?dispatch=$matches[1]', // optional\n\t\t\t'position'   =\u003e 'top'                             // optional\n\t\t],\n\t]\n);\n```\n\n## Examples\n\nSimplest possible usages: fires the action 'dispatch_path_my-path' at http://domain.com/my-path/\n\n```php\n\\WP_Path_Dispatch\\Path_Dispatch()-\u003eadd_path(\n\t[\n\t\t'path' =\u003e 'my-path',\n\t]\n);\n```\n\nThis can even be simplified further as:\n\n```php\n\\WP_Path_Dispatch\\Path_Dispatch()-\u003eadd_path( 'my-path' );\n```\n\nCall the function 'my_function' at http://domain.com/my-path/\n\n```php\n\\WP_Path_Dispatch\\Path_Dispatch()-\u003eadd_path(\n\t[\n\t\t'path'     =\u003e 'my-path',\n\t\t'callback' =\u003e 'my_function',\n\t]\n);\n```\n\nLoad the template file 'dispatch-custom-page.php' at http://domain.com/my-path/\n\n```php\n\\WP_Path_Dispatch\\Path_Dispatch()-\u003eadd_path(\n\t[\n\t\t'path'     =\u003e 'my-path',\n\t\t'template' =\u003e 'custom-page'\n\t]\n);\n```\n\nAdd a custom rewrite rule. Fires the action 'dispatch_path_my-path' at e.g.\nhttp://domain.com/my-path/foo/ and sets the query var 'my_path' to 'foo'. This\nassumes you already registered that query var.\n\n```php\n\\WP_Path_Dispatch\\Path_Dispatch()-\u003eadd_path(\n\t[\n\t\t'path'    =\u003e 'my-rewrite',\n\t\t'rewrite' =\u003e [\n\t\t\t'rule'     =\u003e 'my-path/(.*)/?',\n\t\t\t'redirect' =\u003e 'index.php?dispatch=my-rewrite\u0026my_path=$matches[1]'\n\t\t],\n\t]\n);\n```\n\nSame as above, but registers the query var automatically, and loads the template 'dispatch-my-page.php'.\n\n```php\n\\WP_Path_Dispatch\\Path_Dispatch()-\u003eadd_path(\n\t[\n\t\t'path'     =\u003e 'my-rewrite',\n\t\t'rewrite'  =\u003e [\n\t\t\t'rule'       =\u003e 'my-path/(.+)/?',\n\t\t\t'redirect'   =\u003e 'index.php?dispatch=my-rewrite\u0026my_path=$matches[1]',\n\t\t\t'query_vars' =\u003e 'my_path',\n\t\t],\n\t\t'template' =\u003e 'my-page',\n\t]\n);\n```\n\nSame as above, but with multiple query vars, and with a callback instead of a template.\n\n```php\n\\WP_Path_Dispatch\\Path_Dispatch()-\u003eadd_path(\n\t[\n\t\t'path'     =\u003e 'my-rewrite',\n\t\t'rewrite'  =\u003e [\n\t\t\t'rule'       =\u003e 'my-path/([^/]+)/(.+)/?',\n\t\t\t'redirect'   =\u003e 'index.php?dispatch=my-rewrite\u0026my_path=$matches[1]\u0026my_section=$matches[2]',\n\t\t\t'query_vars' =\u003e [ 'my_path', 'my_section' ],\n\t\t],\n\t\t'callback' =\u003e [ My_Singleton(), 'my_method' ],\n\t]\n);\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Credits\n\nThis project is actively maintained by [Alley\nInteractive](https://github.com/alleyinteractive). Like what you see? [Come work\nwith us](https://alley.co/careers/).\n\n- [Matt Boynes](https://github.com/mboynes)\n- [All Contributors](../../contributors)\n\n## License\n\nThe GNU General Public License (GPL) license. Please see [License File](LICENSE) for more information.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falleyinteractive%2Fwp-path-dispatch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falleyinteractive%2Fwp-path-dispatch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falleyinteractive%2Fwp-path-dispatch/lists"}