2017 © Pedro Peláez
 

library plain-route

Define arbitrary endpoints in WordPress

image

duncanjbrown/plain-route

Define arbitrary endpoints in WordPress

  • Monday, January 18, 2016
  • by duncanjbrown
  • Repository
  • 1 Watchers
  • 0 Stars
  • 359 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 13 % Grown

The README.md

Purpose

This library provides a simple interface for WordPress's fiddly rewrite rules API., (*1)

It's useful for creating arbitrary endpoints with callbacks. For example, a webhook receiver for a payment gateway., (*2)

Usage

Creating an endpoint is accomplished by newing one up. You should do this on init., (*3)

add_action( 'init', function() {
  new Plain_Route( 'stripe(/)?', [
    'rewrite' => 'p=123',
    'pre_get_posts' => function( $query ) {
    if( $query->is_main_query() ) {
      $query->set('stripe', true);
    }
  }]);
});

In the above example, pre_get_posts could be replaced with wp_title or wp. Or you could add them alongside., (*4)

You can also render any template with the special template callback., (*5)

Creating an endpoint that renders a specific template:, (*6)

add_action( 'init', function() {
    new Plain_Route( 'my-special-template(/)?', [
        'template' => 'my-special-template.php'
    ]);
});

Credit

This class is a much-simplified variation of HM_Rewrite by humanmade., (*7)

The Versions

18/01 2016

dev-master

9999999-dev

Define arbitrary endpoints in WordPress

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Duncan Brown

18/01 2016

0.1

0.1.0.0

Define arbitrary endpoints in WordPress

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Duncan Brown