{"id":18743243,"url":"https://github.com/anthonybudd/wp_route","last_synced_at":"2025-09-04T20:45:56.508Z","repository":{"id":62486084,"uuid":"125053697","full_name":"anthonybudd/WP_Route","owner":"anthonybudd","description":"A simple class for binding complex routes to functions methods or WP_AJAX actions.","archived":false,"fork":false,"pushed_at":"2022-07-28T18:02:43.000Z","size":32,"stargazers_count":103,"open_issues_count":9,"forks_count":35,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-13T04:29:34.239Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/anthonybudd.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-13T13:12:00.000Z","updated_at":"2025-01-03T15:26:57.000Z","dependencies_parsed_at":"2022-11-02T10:01:14.483Z","dependency_job_id":null,"html_url":"https://github.com/anthonybudd/WP_Route","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/anthonybudd/WP_Route","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anthonybudd%2FWP_Route","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anthonybudd%2FWP_Route/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anthonybudd%2FWP_Route/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anthonybudd%2FWP_Route/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anthonybudd","download_url":"https://codeload.github.com/anthonybudd/WP_Route/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anthonybudd%2FWP_Route/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273672111,"owners_count":25147490,"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","status":"online","status_checked_at":"2025-09-04T02:00:08.968Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-11-07T16:10:45.531Z","updated_at":"2025-09-04T20:45:56.455Z","avatar_url":"https://github.com/anthonybudd.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# WP_Route\n\n### A simple way to make custom routes in WordPress.\nWP_Route is a simple way to create custom routes in WordPress for listening for webhooks, oAuth callbacks and basic routing. WP_Route is a single class solution that does not require any set-up and supports route parameters and redirects.\n\n## Introduction: **[Medium Post](https://medium.com/@AnthonyBudd/wp-route-a-simple-way-to-make-custom-routes-in-wordpress-5ab1b3063115)**\n\n```php\n\nWP_Route::get('flights',                        'listFlights');\nWP_Route::post('flights/{flight}',              'singleFlight');\nWP_Route::put('flights/{flight}/book/{date}',   'bookFlight');\nWP_Route::delete('flights/{flight}/delete',     'deleteFlight');\n\nWP_Route::any('flights/{flight}',   array('Class', 'staticMethod'));\nWP_Route::patch('flights/{flight}', array($object, 'method'));\nWP_Route::match(['get', 'post'],    'flights/{flight}/confirm', 'confirmFlight');\nWP_Route::redirect('from/here',     '/to/here', 301);\n\n\n```\n\n# Installation\n\nRequire WP_Route with composer\n\n```\n$ composer require anthonybudd/WP_Route\n```\n\n**Or**\n\nDownload the WP_Route class and require it at the top of your functions.php file. This is not recommended. \n\n```php\nrequire 'WP_Route/src/WP_Route.php';\n```\n\n\n# GET Started\nSimply define a route by calling any of the static methods get(), post(), put(), patch(), delete() or any(). This will bind the specified URL to a callable. When a HTTP request bound for that URL is detected, WP_Route will call the callable. \n\n```php\nWP_Route::get('flights', 'listFlights');\n\n// http://example.com/flights\nfunction listFlights(){\n  \n   // Your Code Here!  \n  \n}\n```\n\n# Parameters\nIf you need to extract route parameters from the request URI you can do this by wrapping the value to be extracted in curly brackets. The extracted values will be provided to the callable as function arguments as shown below.\n```php\nWP_Route::get('flights/{flight}', 'singleFlight');\n\nfunction singleFlight($flight){\n    echo $flight; // 1\n}\n```\n\n# Methods\n### get($route, $callable)\n### any(), post(), put(), patch(), delete()\nAll of these methods are used for binding a specific route and HTTP request method to a callable. The method any() will bind a route to a callable but will be HTTP method agnostic.\n```php\n\nWP_Route::get('flights',           'listFlights');\nWP_Route::post('flights/{flight}', array('FlightController', 'singleFlight'));\n\nfunction listFlights(){\n\t// Your Code Here\n}\n  \nClass FlightController{\n\tpublic static function singleFlight($flight){\n\t\t// Your Code Here\n\t}\n}\n```\n\n### match($methods, $route, $callable)\nIf you want to bind a callable to multiple HTTP methods but you do not want to use any(), you can use match(). The first parameter must be an array of HTTP request methods. The arguments $route and $callable work the same as get().\n```php\nWP_Route::match(['get', 'post'], 'flights/{flight}/confirm', 'confirmFlight');\n\nfunction confirmFlight($flight){\n\t// Your Code Here\n}\n```\n\n### redirect($route, $redirect, $code = 301)\nThe redirect() method will redirect the user to the argument $redirect when they navigate to the route. To set a custom HTTP response code use the 3rd argument $code.\n```php\nWP_Route::redirect('open-google', 'https://google.com', 301);\n```\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanthonybudd%2Fwp_route","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanthonybudd%2Fwp_route","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanthonybudd%2Fwp_route/lists"}