Create custom WordPress routes and redirects, restrict access by roles and/or capabilities. Routes made simple

Overview

Plubo Routes

GitHub stars Code Climate maintainability

WordPress routes made simple.

✔️ No need to write rewrite rules and tags manually
✔️ Automatically flush rewrite rules when the routes change
✔️ Custom redirects and action routes
✔️ Easily extendable with hooks
✔️ Easy to use with Sage 10


Getting started

composer require joanrodas/plubo-routes

You can also install Plubo Routes as a standalone WordPress plugin, simply downloading the zip and placing it in the plugins folder.


Read the Docs


Adding new routes

There are different types of routes:


How to add a new route

You can add new routes using the following filter:

PluboRoutes\RoutesProcessor::init();

add_filter( 'plubo/routes', array($this, 'add_routes') );
public function add_routes( $routes ) {
    //Your routes
    return $routes;
}

Basic routes

Basic routes take 3 parameters:

Parameter Type
Route Path String
Template file name String | Callable
Config Array (optional)

Examples:

use PluboRoutes\Route\Route;

add_filter( 'plubo/routes', array($this, 'add_routes') );
public function add_routes( $routes ) {
    $routes[] = new Route('clients/list', 'template_name');

    //SAGE 10 example
    $routes[] = new Route(
        'dashboard/{subpage:slug}',
        function($matches) {
            $subpage = 'dashboard/' . $matches['subpage'];
            return locate_template( app('sage.finder')->locate($subpage) );
        },
        [
            'name' => 'my-route'
        ]
    );
    return $routes;
}

Available syntax

You can use the format {variable_name:type} with any of the available types:

  • number (numbers only)
  • word (a-Z only)
  • slug (a valid WordPress slug)
  • date (yyyy-mm-dd date)
  • year (4 digits)
  • month (01-12)
  • day (01-31)
  • digit (single digit 0-9)
  • jwt (JWT token)
  • ip (IPv4)

You can also use custom regex patterns using the format {variable_name:regex_pattern} like {author:([a-z0-9-]+)}


Changing general template path

By default, Plubo Routes will search the template inside your theme, but you can use a hook to chenge the default path.

If you use Sage 10, you could add something like this:

add_filter( 'plubo/template', function($template) {
    return app('sage.finder')->locate($template);
});

Custom Actions

Named routes provide a hook to execute your custom actions:

add_action('plubo/route_{route_name}', function($matches) {
    //Do something
});

Contributions

contributions welcome GitHub issues GitHub license

Feel free to contribute to the project, suggesting improvements, reporting bugs and coding.

You might also like...
WordPress & TypeScript. Simple starter template for WordPress projects

WordPress & TypeScript. Simple starter template for WordPress projects that want to use TypeScript in combination with @wordpress/scripts

Create WordPress themes with beautiful OOP code and the Twig Template Engine
Create WordPress themes with beautiful OOP code and the Twig Template Engine

By Jared Novack (@jarednova), Lukas Gächter (@lgaechter), Pascal Knecht (@pascalknecht), Maciej Palmowski (@palmiak_fp), Coby Tamayo (@cobytamayo), Up

A better way to create WordPress themes.

Runway Framework for WordPress Visit the Runway website: RunwayWP.com A better way to create WordPress themes. Runway was built for creating WordPress

WordPress plugin to make it easier to create block patterns.

=== Templets === Contributors: mkaz Tags: block patterns, patterns Requires at least: 5.8 Tested up to: 5.8 Requires PHP: 7.3 Stable tag: 0.2.0 Licens

A WordPress plugin to create Blockbase child themes

Create Blockbase Theme A WordPress plugin to create Blockbase child themes Find out more about Blockbase at blockbasetheme.com Step 1 – Setup Install

This is code to create a new user as admin use for Wordpress FrontEnd Developer to prevent any scaming from clients

theme-setup This is code to create a new user as admin use for Wordpress FrontEnd Developer to prevent any scaming from clients How to use Just copy c

Disable direct access to your sites /wp-login.php script, plus user notifications based on actions.
Disable direct access to your sites /wp-login.php script, plus user notifications based on actions.

WordPress Login Locker Disable direct access to your sites /wp-login.php script plus user notifications based on actions. Package Installation (via Co

A curated list of Awesome WordPress Theme, Plugins and Framework development Resources and WordPress Communities.

Awesome WordPress A curated list of Awesome WordPress Theme, Plugins and Framework development Resources and WordPress Communities. Inspired by bayand

The Pronamic WordPress Basecone plugin allows you to connect your WordPress installation to Basecone.

Pronamic WordPress Basecone The Pronamic WordPress Basecone plugin allows you to connect your WordPress installation to Basecone. Table of contents Au

Comments
  • Configure Renovate

    Configure Renovate

    WhiteSource Renovate

    Welcome to Renovate! This is an onboarding PR to help you understand and configure settings before regular Pull Requests begin.

    🚦 To activate Renovate, merge this Pull Request. To disable Renovate, simply close this Pull Request unmerged.


    Detected Package Files

    • composer.json (composer)

    Configuration Summary

    Based on the default config's presets, Renovate will:

    • Start dependency updates only once this onboarding PR is merged
    • Enable Renovate Dependency Dashboard creation
    • If semantic commits detected, use semantic commit type fix for dependencies and chore for all others
    • Ignore node_modules, bower_components, vendor and various test/tests directories
    • Autodetect whether to pin dependencies or maintain ranges
    • Rate limit PR creation to a maximum of two per hour
    • Limit to maximum 10 open PRs at any time
    • Group known monorepo packages together
    • Use curated list of recommended non-monorepo package groupings
    • Fix some problems with very old Maven commons versions
    • Ignore spring cloud 1.x releases
    • Ignore web3j 5.0.0 release
    • Ignore http4s digest-based 1.x milestones
    • Use node versioning for @types/node
    • Limit concurrent requests to reduce load on Repology servers until we can fix this properly, see issue 10133
    • Do not upgrade from Alpine stable to edge

    🔡 Would you like to change the way Renovate is upgrading your dependencies? Simply edit the renovate.json in this branch with your custom config and the list of Pull Requests in the "What to Expect" section below will be updated the next time Renovate runs.


    What to Expect

    It looks like your repository dependencies are already up-to-date and no Pull Requests will be necessary right away.


    ❓ Got questions? Check out Renovate's Docs, particularly the Getting Started section. If you need any further assistance then you can also request help here.


    This PR has been generated by WhiteSource Renovate. View repository job log here.

    opened by renovate[bot] 0
  • Private routes

    Private routes

    • Please check if the PR fulfills these requirements
    • [x] I have read the guidelines
    • [x] Docs have been added / updated (for bug fixes / features)

    • What kind of change does this PR introduce?
    • [ ] Bux fix
    • [x] New feature
    • [ ] Docs update
    • [ ] Others (please specify)

    • What is the current behavior? (You can also link to an open issue here) No private routes

    • What is the new behavior (if this is a feature change)? Allow user to configure allowed roles, capabilities and custom redirects and status codes

    • Does this PR introduce a breaking change? (If so, what changes might users need to make in their application?) No

    • Other info:
    opened by joanrodas 0
  • Dev

    Dev

    • Please check if the PR fulfills these requirements
    • [x] I have read the guidelines
    • [x] Docs have been added / updated (for bug fixes / features)

    • What kind of change does this PR introduce?
    • [ ] Bux fix
    • [x] New feature
    • [ ] Docs update
    • [ ] Others (please specify)

    • What is the current behavior? (You can also link to an open issue here) No endpoints available

    • What is the new behavior (if this is a feature change)? Ability to create endpoints added

    • Does this PR introduce a breaking change? (If so, what changes might users need to make in their application?) No

    opened by joanrodas 0
  • Dependency Dashboard

    Dependency Dashboard

    This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

    This repository currently has no open or pending branches.

    Detected dependencies

    composer
    composer.json
    • php >=7.4

    • [ ] Check this box to trigger a request for Renovate to run again on this repository
    opened by renovate[bot] 0
Releases(v0.5.4)
A WordPress package for updating custom plugins and themes based on an API response from a custom update server.

WordPress Update Handler A WordPress package for updating custom plugins and themes based on an JSON REST API response from a custom update server. Ch

WP Forge 7 Oct 5, 2022
Wordpress advance plugin with multi purposes features like live chat, custom post type, custom forms, word count etc

What is this? This is wordpress plugin which is created for the multi purpose uses. How to use? Simply install the plugin. Go to the plugin settigs pa

Amir Liaqat 2 Jun 23, 2022
A super simple abstraction to make creating a custom Taxonomies in WordPress a breeze

A super simple abstraction to make creating a custom Taxonomies in WordPress a breeze

Joe Grant 2 Apr 5, 2022
Wordless is a junction between a WordPress plugin and a theme boilerplate that dramatically speeds up and enhances your custom theme creation

Wordless is a junction between a WordPress plugin and a theme boilerplate that dramatically speeds up and enhances your custom theme creation. Some of

weLaika 1.4k Dec 9, 2022
A custom update API for WordPress plugins and themes

A custom update API for WordPress plugins and themes. Intended to be used in conjunction with my plugin-update-checker library.

Yahnis Elsts 717 Dec 31, 2022
A PHP Class for creating Wordpress Custom Post Types easily

N.B I've released an updated version of the project to a new repository, PostTypes. WP Custom Post Type Class v1.4 A single class to help you build mo

Joe Grainger 412 Nov 25, 2022
Custom WordPress theme for DotOrg

wd_s Debt Collective Theme Table of Contents Introduction Getting Started Prerequisites Quick Start Advanced Setup Development Contributing and Suppor

The Debt Collective 1 Oct 31, 2022
Word Count (Custom WordPress Plugin)

word-count (Custom WordPress Plugin) Followed a tutorial to create a plugin that adds word count infos to the frontend (Posts only). I then modified t

null 1 Feb 4, 2022
A WordPress plugin to suspend WordPress sites automagically. Simple and lightweight, no annoying ads and fancy settings.

Suspend WP A WordPress plugin to suspend WordPress sites automagically. Simple and lightweight, no annoying ads and fancy settings. ?? Demo (coming so

Waren Gonzaga 3 Nov 15, 2021
Simple WordPress plugin to learn how to understand WordPress Crons and the Action Scheduler library.

Simple WordPress plugin to learn how to understand WordPress Crons and the Action Scheduler library. Import Jamendo playlists with tracks in WordPress posts.

Pierre Saikali 3 Dec 7, 2022