PHPackages                             anthonybudd/wp\_route - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. anthonybudd/wp\_route

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

anthonybudd/wp\_route
=====================

1041.9k33[5 issues](https://github.com/anthonybudd/WP_Route/issues)[3 PRs](https://github.com/anthonybudd/WP_Route/pulls)PHP

Since Jul 28Pushed 3y ago4 watchersCompare

[ Source](https://github.com/anthonybudd/WP_Route)[ Packagist](https://packagist.org/packages/anthonybudd/wp_route)[ RSS](/packages/anthonybudd-wp-route/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependenciesVersions (1)Used By (0)

WP\_Route
=========

[](#wp_route)

### A simple way to make custom routes in WordPress.

[](#a-simple-way-to-make-custom-routes-in-wordpress)

WP\_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.

Introduction: **[Medium Post](https://medium.com/@AnthonyBudd/wp-route-a-simple-way-to-make-custom-routes-in-wordpress-5ab1b3063115)**
--------------------------------------------------------------------------------------------------------------------------------------

[](#introduction-medium-post)

```
WP_Route::get('flights',                        'listFlights');
WP_Route::post('flights/{flight}',              'singleFlight');
WP_Route::put('flights/{flight}/book/{date}',   'bookFlight');
WP_Route::delete('flights/{flight}/delete',     'deleteFlight');

WP_Route::any('flights/{flight}',   array('Class', 'staticMethod'));
WP_Route::patch('flights/{flight}', array($object, 'method'));
WP_Route::match(['get', 'post'],    'flights/{flight}/confirm', 'confirmFlight');
WP_Route::redirect('from/here',     '/to/here', 301);
```

Installation
============

[](#installation)

Require WP\_Route with composer

```
$ composer require anthonybudd/WP_Route

```

**Or**

Download the WP\_Route class and require it at the top of your functions.php file. This is not recommended.

```
require 'WP_Route/src/WP_Route.php';
```

GET Started
===========

[](#get-started)

Simply 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.

```
WP_Route::get('flights', 'listFlights');

// http://example.com/flights
function listFlights(){

   // Your Code Here!

}
```

Parameters
==========

[](#parameters)

If 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.

```
WP_Route::get('flights/{flight}', 'singleFlight');

function singleFlight($flight){
    echo $flight; // 1
}
```

Methods
=======

[](#methods)

### get($route, $callable)

[](#getroute-callable)

### any(), post(), put(), patch(), delete()

[](#any-post-put-patch-delete)

All 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.

```
WP_Route::get('flights',           'listFlights');
WP_Route::post('flights/{flight}', array('FlightController', 'singleFlight'));

function listFlights(){
	// Your Code Here
}

Class FlightController{
	public static function singleFlight($flight){
		// Your Code Here
	}
}
```

### match($methods, $route, $callable)

[](#matchmethods-route-callable)

If 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().

```
WP_Route::match(['get', 'post'], 'flights/{flight}/confirm', 'confirmFlight');

function confirmFlight($flight){
	// Your Code Here
}
```

### redirect($route, $redirect, $code = 301)

[](#redirectroute-redirect-code--301)

The 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.

```
WP_Route::redirect('open-google', 'https://google.com', 301);
```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity34

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity25

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7443012?v=4)[Anthony C. Budd](/maintainers/anthonybudd)[@anthonybudd](https://github.com/anthonybudd)

---

Top Contributors

[![anthonybudd](https://avatars.githubusercontent.com/u/7443012?v=4)](https://github.com/anthonybudd "anthonybudd (30 commits)")

### Embed Badge

![Health badge](/badges/anthonybudd-wp-route/health.svg)

```
[![Health](https://phpackages.com/badges/anthonybudd-wp-route/health.svg)](https://phpackages.com/packages/anthonybudd-wp-route)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
