{"id":13368,"date":"2011-05-23T16:02:17","date_gmt":"2011-05-23T16:02:17","guid":{"rendered":"https:\/\/wordpress.org\/plugins-wp\/wp-router\/"},"modified":"2012-08-06T15:06:17","modified_gmt":"2012-08-06T15:06:17","slug":"wp-router","status":"publish","type":"plugin","link":"https:\/\/os.wordpress.org\/plugins\/wp-router\/","author":383275,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_crdt_document":"","version":"0.5","stable_tag":"trunk","tested":"3.4.2","requires":"3.0","requires_php":"","requires_plugins":"","header_name":"WP Router","header_author":"Flightless","header_description":"","assets_banners_color":"","last_updated":"2012-08-06 15:06:17","external_support_url":"","external_repository_url":"","donate_link":"https:\/\/www.paypal.com\/cgi-bin\/webscr?cmd=_s-xclick&hosted_button_id=A69NZPKWGB6H2","header_plugin_uri":"https:\/\/github.com\/jbrinley\/WP-Router","header_author_uri":"http:\/\/flightless.us\/","rating":3.7,"author_block_rating":0,"active_installs":900,"downloads":17138,"num_ratings":3,"support_threads":0,"support_threads_resolved":0,"author_block_count":0,"sections":["description","installation","changelog"],"tags":[],"upgrade_notice":[],"ratings":{"1":"1","2":0,"3":0,"4":0,"5":"2"},"assets_icons":[],"assets_banners":[],"assets_blueprints":{},"all_blocks":[],"tagged_versions":[],"block_files":[],"assets_screenshots":[],"screenshots":[],"jetpack_post_was_ever_published":false},"plugin_section":[],"plugin_tags":[70653,70652],"plugin_category":[],"plugin_contributors":[77692],"plugin_business_model":[],"class_list":["post-13368","plugin","type-plugin","status-publish","hentry","plugin_tags-callback-functions","plugin_tags-url-mapping","plugin_contributors-jbrinley","plugin_committers-jbrinley"],"banners":[],"icons":{"svg":false,"icon":"https:\/\/s.w.org\/plugins\/geopattern-icon\/wp-router.svg","icon_2x":false,"generated":true},"screenshots":[],"raw_content":"<!--section=description-->\n<p>WordPress's rewrite rules and query variables provide a powerful system\nfor mapping URL strings to collections of posts. Every request is parsed\ninto query variables and turned into a SQL query via <code>$wp_query-&gt;query()<\/code>.<\/p>\n\n<p>Sometimes, though, you don't want to display a list of posts. You just want\na URL to map to a callback function, with the output displayed in place of\nposts in whatever theme you happen to be using.<\/p>\n\n<p>That's where WP Router comes in. It handles all the messy bits of registering\npost types, query variables, rewrite rules, etc., and lets you write code to\ndo what you want it to do. One function call is all it takes to map a\nURL to your designated callback function and display the return value in the page.<\/p>\n\n<p>Created by <a href=\"http:\/\/flightless.us\">Flightless<\/a><\/p>\n\n<h3>Usage<\/h3>\n\n<h4>Creating Routes<\/h4>\n\n<ul>\n<li>Your plugin should hook into the <code>wp_router_generate_routes<\/code> action.\nThe callback should take one argument, a <code>WP_Router<\/code> object.<\/li>\n<li><p>Register a route and its callback using <code>WP_Router::add_route( $id, $args )<\/code><\/p>\n\n<ul>\n<li><code>$id<\/code> is a unique string your plugin should use to identify the route<\/li>\n<li><p><code>$args<\/code> is an associative array, that sets the following properties for your route.\nAny omitted argument will use the default value.<\/p>\n\n<ul>\n<li><p><code>path<\/code> (required) - A regular expression to match against the request path.\nThis corresponds to the array key you would use when creating rewrite rules for WordPress.<\/p><\/li>\n<li><p><code>query_vars<\/code> - An associative array, with the keys being query vars, and the\nvalues being explicit strings or integers corresponding to matches in the path regexp.\n Any query variables included here will be automatically registered.<\/p><\/li>\n<li><p><code>title<\/code> - The title of the page.<\/p><\/li>\n<li><p><code>title_callback<\/code> - A callback to use for dynamically generating the title.\nDefaults to <code>__()<\/code>. If <code>NULL<\/code>, the <code>title<\/code> argument will be used as-is. if\n    page_callback or <code>access_callback<\/code> returns <code>FALSE<\/code>, <code>title_callback<\/code> will not be called.<\/p>\n\n<pre><code>title_callback can be either a single callback function or an array specifying\n<\/code><\/pre>\n\n<p>callback functions for specific HTTP methods (e.g., <code>GET<\/code>, <code>POST<\/code>, <code>PUT<\/code>, <code>DELETE<\/code>, etc.).\nIf the latter, the <code>default<\/code> key will be used if no other keys match the current\nrequest method.<\/p><\/li>\n<li><p><code>title_arguments<\/code> - An array of query variables whose values will be passed\nas arguments to <code>title_callback<\/code>. Defaults to the value of <code>title<\/code>. If an argument\nis not a registered query variable, it will be passed as-is.<\/p><\/li>\n<li><p><code>page_callback<\/code> (required) - A callback to use for dynamically generating the\ncontents of the page. The callback should either echo or return the contents of\nthe page (if both, the returned value will be appended to the echoed value). If\n    FALSE is returned, nothing will be output, and control of the page contents will\nbe handed back to WordPress. The callback will be called during the <code>parse_request<\/code>\nphase of WordPress's page load. If <code>access_callback<\/code> returns <code>FALSE<\/code>, <code>page_callback<\/code>\nwill not be called.<\/p>\n\n<pre><code>page_callback can be either a single callback function or an array specifying\n<\/code><\/pre>\n\n<p>callback functions for specific HTTP methods (e.g., <code>GET<\/code>, <code>POST<\/code>, <code>PUT<\/code>, <code>DELETE<\/code>, etc.).\nIf the latter, the <code>default<\/code> key will be used if no other keys match the current\nrequest method.<\/p><\/li>\n<li><p><code>page_arguments<\/code> - An array of query variables whose values will be passed as\narguments to <code>page_callback<\/code>. If an argument is not a registered query variable,\nit will be passed as-is.<\/p><\/li>\n<li><p><code>access_callback<\/code> - A callback to determine if the user has permission to access\nthis page. If <code>access_arguments<\/code> is provided, default is <code>current_user_can<\/code>, otherwise\ndefault is <code>TRUE<\/code>. If the callback returns <code>FALSE<\/code>, anonymous users are redirected to\nthe login page, authenticated users get a 403 error.<\/p>\n\n<pre><code>access_callback can be either a single callback function or an array specifying\n<\/code><\/pre>\n\n<p>callback functions for specific HTTP methods (e.g., <code>GET<\/code>, <code>POST<\/code>, <code>PUT<\/code>, <code>DELETE<\/code>, etc.).\nIf the latter, the <code>default<\/code> key will be used if no other keys match the current\nrequest method.<\/p><\/li>\n<li><p><code>access_arguments<\/code> - An array of query variables whose values will be passed\nas arguments to <code>access_callback<\/code>. If an argument is not a registered query variable,\nit will be passed as-is.<\/p><\/li>\n<li><p><code>template<\/code> - An array of templates that can be used to display the page. If a path\nis absolute, it will be used as-is; relative paths allow for overrides by the theme.\nThe string <code>$id<\/code> will be replaced with the ID of the route. If no template is found,\nfallback templates are (in this order): <code>route-$id.php<\/code>, <code>route.php<\/code>, <code>page-$id.php<\/code>,\n    page.php, <code>index.php<\/code>. If FALSE is given instead of an array, the page contents will\nbe printed before calling <code>exit()<\/code> (you can also accomplish this by printing your output\nand exiting directly from your callback function).<\/p><\/li>\n<\/ul><\/li>\n<\/ul><\/li>\n<\/ul>\n\n<p>Example:\n    $router-&gt;add_route('wp-router-sample', array(\n        'path' =&gt; '^wp_router\/(.*?)$',\n        'query_vars' =&gt; array(\n            'sample_argument' =&gt; 1,\n        ),\n        'page_callback' =&gt; array(get_class(), 'sample_callback'),\n        'page_arguments' =&gt; array('sample_argument'),\n        'access_callback' =&gt; TRUE,\n        'title' =&gt; 'WP Router Sample Page',\n        'template' =&gt; array('sample-page.php', dirname(<strong>FILE<\/strong>).DIRECTORY_SEPARATOR.'sample-page.php')\n    ));<\/p>\n\n<p>In this example, the path <code>http:\/\/example.com\/wp_router\/my_sample_path\/<\/code> will call\nthe function <code>sample_callback<\/code> in the calling class. The value of the <code>sample_argument<\/code>\nquery variable, in this case \"my_sample_path\", will be provided as the first and only\nargument to the callback function. If the file <code>sample-page.php<\/code> is found in the theme,\nit will be used as the template, otherwise <code>sample-page.php<\/code> in your plugin directory will\nbe used (if that's not found either, fall back to <code>route-wp-router-sample.php<\/code>, etc.).<\/p>\n\n<h4>Editing Routes<\/h4>\n\n<ul>\n<li>You can hook into the <code>wp_router_alter_routes<\/code> action to modify routes created by other plugins. The callback should take one argument, a <code>WP_Router<\/code> object.<\/li>\n<\/ul>\n\n<h4>Public API Functions<\/h4>\n\n<p>Creating or changing routes should always occur in the context of the <code>wp_router_generate_routes<\/code> or <code>wp_router_alter_routes<\/code> actions, using the <code>WP_Router<\/code> object supplied to your callback function.<\/p>\n\n<ul>\n<li><code>WP_Router::edit_route( string $id, array $changes )<\/code> - update each\nproperty given in <code>$changes<\/code> for the route with the given ID. Any properties\nnot given in <code>$changes<\/code> will be left unaltered.<\/li>\n<li><code>WP_Router::remove_route( string $id )<\/code> - delete the route with the given ID<\/li>\n<li><code>WP_Router::get_route( string $id )<\/code> - get the <code>WP_Route<\/code> object for the given ID<\/li>\n<li><code>WP_Router::get_url( string $id, array $arguments )<\/code> - get the URL to reach the route with the given ID, with the given query variables and their values<\/li>\n<li><code>WP_Route::get( string $property )<\/code> - get the value of the specified property for\nthe <code>WP_Route<\/code> instance<\/li>\n<\/ul>\n\n<!--section=installation-->\n<ol>\n<li>Download and unzip the plugin<\/li>\n<li>Upload the <code>WP-Router<\/code> folder to the <code>\/wp-content\/plugins\/<\/code> directory<\/li>\n<li>Activate the plugin through the 'Plugins' menu in WordPress<\/li>\n<li>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.<\/li>\n<\/ol>\n\n<!--section=changelog-->\n<h4>0.5<\/h4>\n\n<ul>\n<li>Filter get_permalink on router pages to point to the requested URI<\/li>\n<li>Filter post meta for the placeholder page when on a router page to provide a title to WP SEO<\/li>\n<li>Added <code>wp_router_placeholder_postmeta<\/code> filter for adding additional meta to the placeholder page<\/li>\n<\/ul>\n\n<h4>0.4<\/h4>\n\n<ul>\n<li>Prevent redirect from route pages with the \"page\" or \"paged\" query arg<\/li>\n<\/ul>\n\n<h4>0.3.3<\/h4>\n\n<ul>\n<li>Prevent redirect from all route pages when %category% is in the permastruct<\/li>\n<li>Redirect placeholder page to the blog front page<\/li>\n<li>Fix usage of translation functions<\/li>\n<\/ul>\n\n<h4>0.3.2<\/h4>\n\n<ul>\n<li>Make $arguments param optional for WP_Router::get_url() and WP_Router::url()<\/li>\n<\/ul>\n\n<h4>0.3.1<\/h4>\n\n<ul>\n<li>Added WP_Router::get_url()<\/li>\n<li>Added WP_Route::url()<\/li>\n<\/ul>\n\n<h4>0.3<\/h4>\n\n<ul>\n<li>Added <code>FALSE<\/code> option to template parameter to indicate immediate <code>exit()<\/code><\/li>\n<li>Added option to specify different callback functions depending on the HTTP request method<\/li>\n<li>Verified compatibility with WordPress 3.0<\/li>\n<li>Added WP_Router::get_url() function<\/li>\n<\/ul>\n\n<h4>0.2<\/h4>\n\n<ul>\n<li>Added the <code>template<\/code> argument<\/li>\n<\/ul>\n\n<h4>0.1<\/h4>\n\n<ul>\n<li>Initial version<\/li>\n<\/ul>","raw_excerpt":"Provides a simple API for mapping requests to callback functions.","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/os.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin\/13368","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/os.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin"}],"about":[{"href":"https:\/\/os.wordpress.org\/plugins\/wp-json\/wp\/v2\/types\/plugin"}],"replies":[{"embeddable":true,"href":"https:\/\/os.wordpress.org\/plugins\/wp-json\/wp\/v2\/comments?post=13368"}],"author":[{"embeddable":true,"href":"https:\/\/os.wordpress.org\/plugins\/wp-json\/wporg\/v1\/users\/jbrinley"}],"wp:attachment":[{"href":"https:\/\/os.wordpress.org\/plugins\/wp-json\/wp\/v2\/media?parent=13368"}],"wp:term":[{"taxonomy":"plugin_section","embeddable":true,"href":"https:\/\/os.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_section?post=13368"},{"taxonomy":"plugin_tags","embeddable":true,"href":"https:\/\/os.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_tags?post=13368"},{"taxonomy":"plugin_category","embeddable":true,"href":"https:\/\/os.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_category?post=13368"},{"taxonomy":"plugin_contributors","embeddable":true,"href":"https:\/\/os.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_contributors?post=13368"},{"taxonomy":"plugin_business_model","embeddable":true,"href":"https:\/\/os.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_business_model?post=13368"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}