jbrinley / WP-Router

Routes paths to callback functions in WordPress
108 stars 27 forks source link

=== WP Router === Contributors: jbrinley Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=A69NZPKWGB6H2 Tags: URL mapping, callback functions Requires at least: 3.0 Tested up to: 5.2.4 Stable tag: trunk

Provides a simple API for mapping requests to callback functions.

== Description ==

WordPress's rewrite rules and query variables provide a powerful system for mapping URL strings to collections of posts. Every request is parsed into query variables and turned into a SQL query via $wp_query->query().

Sometimes, though, you don't want to display a list of posts. You just want a URL to map to a callback function, with the output displayed in place of posts in whatever theme you happen to be using.

That's where WP Router comes in. It handles all the messy bits of registering post types, query variables, rewrite rules, etc., and lets you write code to do what you want it to do. One function call is all it takes to map a URL to your designated callback function and display the return value in the page.

Created by Flightless

== Installation ==

  1. Download and unzip the plugin
  2. Upload the WP-Router folder to the /wp-content/plugins/ directory
  3. Activate the plugin through the 'Plugins' menu in WordPress
  4. You should see the sample page at http://example.org/wp_router/sample/. Apart from that, there is no public UI for this plugin. You will not see any changes unless the plugin's API is called by another active plugin.

== Usage ==

= Creating Routes =

Example: $router->add_route('wp-router-sample', array( 'path' => '^wp_router/(.*?)$', 'query_vars' => array( 'sample_argument' => 1, ), 'page_callback' => array(get_class(), 'sample_callback'), 'page_arguments' => array('sample_argument'), 'access_callback' => TRUE, 'title' => 'WP Router Sample Page', 'template' => array('sample-page.php', dirname(__FILE__).DIRECTORY_SEPARATOR.'sample-page.php') ));

In this example, the path http://example.com/wp_router/my_sample_path/ will call the function sample_callback in the calling class. The value of the sample_argument query variable, in this case "my_sample_path", will be provided as the first and only argument to the callback function. If the file sample-page.php is found in the theme, it will be used as the template, otherwise sample-page.php in your plugin directory will be used (if that's not found either, fall back to route-wp-router-sample.php, etc.).

= Editing Routes =

= Public API Functions =

Creating or changing routes should always occur in the context of the wp_router_generate_routes or wp_router_alter_routes actions, using the WP_Router object supplied to your callback function.

== Changelog ==

= 0.6 =

= 0.5 =

= 0.4 =

= 0.3.3 =

= 0.3.2 =

= 0.3.1 =

= 0.3 =

= 0.2 =

= 0.1 =