PHPackages                             rareloop/wp-router - 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. rareloop/wp-router

ActiveWordpress-plugin[Utility &amp; Helpers](/categories/utility)

rareloop/wp-router
==================

Router

v1.0.1(8y ago)171.8k2[1 issues](https://github.com/Rareloop/wp-router/issues)[1 PRs](https://github.com/Rareloop/wp-router/pulls)MITPHPPHP ^7.0

Since Jul 20Pushed 8y ago7 watchersCompare

[ Source](https://github.com/Rareloop/wp-router)[ Packagist](https://packagist.org/packages/rareloop/wp-router)[ Docs](https://github.com/rareloop/wp-router)[ RSS](/packages/rareloop-wp-router/feed)WikiDiscussions master Synced today

READMEChangelog (2)Dependencies (5)Versions (3)Used By (0)

**This package is no longer supported. Use at your own risk. We recommend using the underlying router: **

Rare WordPress Router
=====================

[](#rare-wordpress-router)

[![CI](https://camo.githubusercontent.com/2d6461f39b54966f8d4c1b5d32a847dd5835cf02f70cb284d90bb396238e0c75/68747470733a2f2f7472617669732d63692e6f72672f526172656c6f6f702f77702d726f757465722e7376673f6272616e63683d6d6173746572)](https://camo.githubusercontent.com/2d6461f39b54966f8d4c1b5d32a847dd5835cf02f70cb284d90bb396238e0c75/68747470733a2f2f7472617669732d63692e6f72672f526172656c6f6f702f77702d726f757465722e7376673f6272616e63683d6d6173746572)

A WordPress wrapper around the [Rareloop PHP Router](https://github.com/rareloop/router). Easily handle custom endpoints on your WordPress site with this plugin.

Installation
------------

[](#installation)

Although not a requirement, using Composer and a setup like [Bedrock](https://roots.io/bedrock/) is the recommended installation method.

```
composer require rareloop/wp-router

```

Usage
-----

[](#usage)

### Creating Routes

[](#creating-routes)

#### Map

[](#map)

Creating a route is done using the `map` function:

```
use Rareloop\WordPress\Router\Router;

// Creates a route that matches the uri `/posts/list` both GET
// and POST requests.
Router::map(['GET', 'POST'], 'posts/list', function () {
    return 'Hello World';
});
```

`map()` takes 3 parameters:

- `methods` (array): list of matching request methods, valid values:
    - `GET`
    - `POST`
    - `PUT`
    - `PATCH`
    - `DELETE`
    - `OPTIONS`
- `uri` (string): The URI to match against
- `action` (function|string): Either a closure or a Controller string

#### Route Parameters

[](#route-parameters)

Parameters can be defined on routes using the `{keyName}` syntax. When a route matches that contains parameters, an instance of the `RouteParams` object is passed to the action.

```
Router::map(['GET'], 'posts/{id}', function(RouteParams $params) {
    return $params->id;
});
```

#### Named Routes

[](#named-routes)

Routes can be named so that their URL can be generated programatically:

```
Router::map(['GET'], 'posts/all', function () {})->name('posts.index');

$url = Router::url('posts.index');
```

If the route requires parameters you can be pass an associative array as a second parameter:

```
Router::map(['GET'], 'posts/{id}', function () {})->name('posts.show');

$url = Router::url('posts.show', ['id' => 123]);
```

#### HTTP Verb Shortcuts

[](#http-verb-shortcuts)

Typically you only need to allow one HTTP verb for a route, for these cases the following shortcuts can be used:

```
Router::get('test/route', function () {});
Router::post('test/route', function () {});
Router::put('test/route', function () {});
Router::patch('test/route', function () {});
Router::delete('test/route', function () {});
Router::options('test/route', function () {});
```

#### Setting the basepath

[](#setting-the-basepath)

The router assumes you're working from the route of a domain. If this is not the case you can set the base path:

```
Router::setBasePath('base/path');
Router::map(['GET'], 'route/uri', function () {}); // `/base/path/route/uri`
```

#### Controllers

[](#controllers)

If you'd rather use a class to group related route actions together you can pass a Controller String to `map()` instead of a closure. The string takes the format `{name of class}@{name of method}`. It is important that you use the complete namespace with the class name.

Example:

```
// TestController.php
namespace \MyNamespace;

class TestController
{
    public function testMethod()
    {
        return 'Hello World';
    }
}

// routes.php
Router::map(['GET'], 'route/uri', '\MyNamespace\TestController@testMethod');
```

### Creating Groups

[](#creating-groups)

It is common to group similar routes behind a common prefix. This can be achieved using Route Groups:

```
Router::group('prefix', function ($group) {
    $group->map(['GET'], 'route1', function () {}); // `/prefix/route1`
    $group->map(['GET'], 'route2', function () {}); // `/prefix/route2§`
});
```

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 66.7% 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.

###  Release Activity

Cadence

Every ~4 days

Total

2

Last Release

3261d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1554376?v=4)[Rareloop](/maintainers/rareloop)[@Rareloop](https://github.com/Rareloop)

---

Top Contributors

[![joelambert](https://avatars.githubusercontent.com/u/644362?v=4)](https://github.com/joelambert "joelambert (4 commits)")[![adamtomat](https://avatars.githubusercontent.com/u/2631499?v=4)](https://github.com/adamtomat "adamtomat (2 commits)")

---

Tags

routerrareloop

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/rareloop-wp-router/health.svg)

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

###  Alternatives

[bramus/router

A lightweight and simple object oriented PHP Router

1.1k478.8k53](/packages/bramus-router)[izniburak/laravel-auto-routes

Auto Route Generating (Auto-Discovery) Package for Laravel

23548.1k](/packages/izniburak-laravel-auto-routes)[proai/lumen-annotations

Route and event binding annotations for Laravel Lumen

1012.6k](/packages/proai-lumen-annotations)[miranj/craft-router

Use URL segments as filtering criteria on an entry query.

231.6k](/packages/miranj-craft-router)

PHPackages © 2026

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