vendi-advertising/vendi-template-router

1.3.7 2020-09-14 20:20 UTC

This package is auto-updated.

Last update: 2024-04-15 04:03:29 UTC


README

The goal of this plugin was to better override WordPress's routing engine in a more explicit and controlled manner. There are times when you want the full power of WordPress's CMS backend but you want to take complete control of the rendering. Usually this scenario pops up most when you are developing an application instead of just a website.

At the time that this plugin was created the REST API was just entering beta and the work on the rewrite engine wasn't spoken of yet. (Hopefully that's coming soon, though!)

The general use-case for this plugin is for URL "folders" that you want to redirect to your own template folder based on name. For instance, if you want everything at https://www.example.com/app/ to go to your own application folder (which doesn't even need to live in the web root).

This plugin can be installed as a normal plugin however it is recommended that you actually install this as an MU plugin.

To use this plugin you just need to register your route:

\Vendi\Shared\template_router::register_context(
                                                <context_name>,
                                                <url_folder>,
                                                <template_location_root>,
                                                <magic_page = 'page'>,
                                                <template_subfolder = 'templates'>
                                            );
  • <context_name>
    • Arbitrary string name that represents URLs relative to <url_folder>.
    • If you want to ask the template_router to generate URLs later you'll need this.
  • <url_folder>
    • Arbitrary valid URL string that represents the "folder" that your application is served from.
  • <template_location_root>
    • The absolute path that requests to <url_folder> will be passed to.
  • <magic_page>
    • When passing the requested route to your template this query string variable will be used.
    • Make sure that your app does not depend on this value.
    • This value is optional and defaults to "page".
    • This parameter is poorly named and really should be "internal_query_string_key" or something.
  • <template_subfolder>
    • The subfolder relative to <template_location_root> that holds the templates for this route.
    • This value is optional and defaults to "templates"

Example

For a general application called Test that you want to have all routes start with test and with the WordPress install at /var/www/wordpress-root-folder/ and with templates living in /var/www/wordpress-root-folder/templates/ you would register your context using:

\Vendi\Shared\template_router::register_context(
                                                'Test',
                                                'test',
                                                '/var/www/wordpress-root-folder/'
                                            );