Title: WP Router
Author: Jonathan Brinley
Published: <strong>Èbìbí  23, 2011</strong>
Last modified: Ògún  6, 2012

---

Ṣàwárí àwọn plugin

Plugin yìí **kò tíì ṣe àyẹ̀wò pẹ̀lú àwọn ìtújáde mẹ́ta pàtàkì tó kẹ́yìn ti WordPress**.
Ó lè jẹ́ pé a kò tọ́jú tàbí ṣe àtìlẹ́yìn fún un mọ́, ó sì lè ní àwọn ọ̀ràn ìbámu
nígbà tí a bá lò ó pẹ̀lú àwọn ẹ̀yà WordPress tuntun.

![](https://s.w.org/plugins/geopattern-icon/wp-router.svg)

# WP Router

 Láti ọwọ́ [Jonathan Brinley](https://profiles.wordpress.org/jbrinley/)

[Ṣe ìgbàsílẹ̀](https://downloads.wordpress.org/plugin/wp-router.zip)

 * [Àwọn àlàyé](https://yor.wordpress.org/plugins/wp-router/#description)
 * [Àwọn àgbéyẹ̀wò](https://yor.wordpress.org/plugins/wp-router/#reviews)
 *  [Ìgbéwọlẹ̀](https://yor.wordpress.org/plugins/wp-router/#installation)
 * [Ìdàgbàsókè](https://yor.wordpress.org/plugins/wp-router/#developers)

 [Ìrànlọ́wọ́](https://wordpress.org/support/plugin/wp-router/)

## Àpèjúwe

WordPressÌtumọ̀ Yorùbá: ’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Ìtumọ̀ Yorùbá: ’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Ìtumọ̀ Yorùbá: ’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](http://flightless.us)

### Usage

#### Creating Routes

 * Your plugin should hook into the `wp_router_generate_routes` action.
    The callback
   should take one argument, a `WP_Router` object.
 * Register a route and its callback using `WP_Router::add_route( $id, $args )`
    - `$id` is a unique string your plugin should use to identify the route
    - `$args` is an associative array, that sets the following properties for your
      route.
       Any omitted argument will use the default value.
       * `path` (required) Ìtumọ̀ Yorùbá: – A regular expression to match against
         the request path.
          This corresponds to the array key you would use when
         creating rewrite rules for WordPress.
       * `query_vars` Ìtumọ̀ Yorùbá: – An associative array, with the keys being
         query vars, and the
          values being explicit strings or integers corresponding
         to matches in the path regexp. Any query variables included here will be
         automatically registered.
       * `title` Ìtumọ̀ Yorùbá: – The title of the page.
       * `title_callback` Ìtumọ̀ Yorùbá: – A callback to use for dynamically generating
         the title.
          Defaults to `__()`. If `NULL`, the `title` argument will be
         used as-is. if page_callback or `access_callback` returns `FALSE`, `title_callback`
         will not be called.
       *     ```
             title_callback can be either a single callback function or an array specifying
             ```
         
       * callback functions for specific HTTP methods (e.g., `GET`, `POST`, `PUT`,`
         DELETE`, etc.).
          If the latter, the `default` key will be used if no other
         keys match the current request method.
       * `title_arguments` Ìtumọ̀ Yorùbá: – An array of query variables whose values
         will be passed
          as arguments to `title_callback`. Defaults to the value
         of `title`. If an argument is not a registered query variable, it will 
         be passed as-is.
       * `page_callback` (required) Ìtumọ̀ Yorùbá: – A callback to use for dynamically
         generating the
          contents of the page. The callback should either echo or
         return the contents of the page (if both, the returned value will be appended
         to the echoed value). If FALSE is returned, nothing will be output, and
         control of the page contents will be handed back to WordPress. The callback
         will be called during the `parse_request` phase of WordPressÌtumọ̀ Yorùbá:’
         s page load. If `access_callback` returns `FALSE`, `page_callback` will
         not be called.
       *     ```
             page_callback can be either a single callback function or an array specifying
             ```
         
       * callback functions for specific HTTP methods (e.g., `GET`, `POST`, `PUT`,`
         DELETE`, etc.).
          If the latter, the `default` key will be used if no other
         keys match the current request method.
       * `page_arguments` Ìtumọ̀ Yorùbá: – An array of query variables whose values
         will be passed as
          arguments to `page_callback`. If an argument is not 
         a registered query variable, it will be passed as-is.
       * `access_callback` Ìtumọ̀ Yorùbá: – A callback to determine if the user 
         has permission to access
          this page. If `access_arguments` is provided,
         default is `current_user_can`, otherwise default is `TRUE`. If the callback
         returns `FALSE`, anonymous users are redirected to the login page, authenticated
         users get a 403 error.
       *     ```
             access_callback can be either a single callback function or an array specifying
             ```
         
       * callback functions for specific HTTP methods (e.g., `GET`, `POST`, `PUT`,`
         DELETE`, etc.).
          If the latter, the `default` key will be used if no other
         keys match the current request method.
       * `access_arguments` Ìtumọ̀ Yorùbá: – An array of query variables whose values
         will be passed
          as arguments to `access_callback`. If an argument is not
         a registered query variable, it will be passed as-is.
       * `template` Ìtumọ̀ Yorùbá: – An array of templates that can be used to display
         the page. If a path
          is absolute, it will be used as-is; relative paths
         allow for overrides by the theme. The string `$id` will be replaced with
         the ID of the route. If no template is found, fallback templates are (in
         this order): `route-$id.php`, `route.php`, `page-$id.php`, page.php, `index.
         php`. If FALSE is given instead of an array, the page contents will be 
         printed before calling `exit()` (you can also accomplish this by printing
         your output and exiting directly from your callback function).

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.Ìtumọ̀ Yorùbá: ’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Ìtumọ̀ Yorùbá: ’s not found either, fall back
to `route-wp-router-sample.php`, etc.).

#### Editing Routes

 * You can hook into the `wp_router_alter_routes` action to modify routes created
   by other plugins. The callback should take one argument, a `WP_Router` object.

#### 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.

 * `WP_Router::edit_route( string $id, array $changes )` Ìtumọ̀ Yorùbá: – update
   each
    property given in `$changes` for the route with the given ID. Any properties
   not given in `$changes` will be left unaltered.
 * `WP_Router::remove_route( string $id )` Ìtumọ̀ Yorùbá: – delete the route with
   the given ID
 * `WP_Router::get_route( string $id )` Ìtumọ̀ Yorùbá: – get the `WP_Route` object
   for the given ID
 * `WP_Router::get_url( string $id, array $arguments )` Ìtumọ̀ Yorùbá: – get the
   URL to reach the route with the given ID, with the given query variables and 
   their values
 * `WP_Route::get( string $property )` Ìtumọ̀ Yorùbá: – get the value of the specified
   property for
    the `WP_Route` instance

## Ìgbéwọlẹ̀

 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Ìtumọ̀ Yorùbá: ’s API is called by another active plugin.

## Àwọn àgbéyẹ̀wò

![](https://secure.gravatar.com/avatar/d6499e15c7ebe0b88d18d441a03689724c5962bd5ebf75f5f81fd32b6ba67e53?
s=60&d=retro&r=g)

### 󠀁[Интересный плагин](https://wordpress.org/support/topic/%d0%b8%d0%bd%d1%82%d0%b5%d1%80%d0%b5%d1%81%d0%bd%d1%8b%d0%b9-%d0%bf%d0%bb%d0%b0%d0%b3%d0%b8%d0%bd-3/)󠁿

 [petrozavodsky](https://profiles.wordpress.org/vovasik/) Ọ̀wàrà 27, 2017

Интересный плагин

 [ Ka gbogbo àwọn àgbéyẹ̀wò 3 ](https://wordpress.org/support/plugin/wp-router/reviews/)

## Àwọn Olùkópa & Olùgbéejáde

“WP Router” jẹ́ ètò ìṣàmúlò orísun ṣíṣí sílẹ̀. Àwọn ènìyàn wọ̀nyí ti ṣe ìkópa sí
plugin yìí.

Àwọn Olùkópa

 *   [ Jonathan Brinley ](https://profiles.wordpress.org/jbrinley/)

[Túmọ̀ “WP Router” sí èdè rẹ.](https://translate.wordpress.org/projects/wp-plugins/wp-router)

### Ṣe o nífẹ̀ẹ́ sí ìdàgbàsókè?

[Ṣàwárí koodu](https://plugins.trac.wordpress.org/browser/wp-router/), ṣàyẹ̀wò [ibi ìpamọ́ SVN](https://plugins.svn.wordpress.org/wp-router/),
tàbí ṣe àgbékalẹ̀ sí [àkọsílẹ̀ ìdàgbàsókè](https://plugins.trac.wordpress.org/log/wp-router/)
nípasẹ̀ [RSS](https://plugins.trac.wordpress.org/log/wp-router/?limit=100&mode=stop_on_copy&format=rss).

## Àkọsílẹ̀ àwọn àyípadà

#### 0.5

 * Filter get_permalink on router pages to point to the requested URI
 * Filter post meta for the placeholder page when on a router page to provide a 
   title to WP SEO
 * Added `wp_router_placeholder_postmeta` filter for adding additional meta to the
   placeholder page

#### 0.4

 * Prevent redirect from route pages with the “page” or “paged” query arg

#### 0.3.3

 * Prevent redirect from all route pages when %category% is in the permastruct
 * Redirect placeholder page to the blog front page
 * Fix usage of translation functions

#### 0.3.2

 * Make $arguments param optional for WP_Router::get_url() and WP_Router::url()

#### 0.3.1

 * Added WP_Router::get_url()
 * Added WP_Route::url()

#### 0.3

 * Added `FALSE` option to template parameter to indicate immediate `exit()`
 * Added option to specify different callback functions depending on the HTTP request
   method
 * Verified compatibility with WordPress 3.0
 * Added WP_Router::get_url() function

#### 0.2

 * Added the `template` argument

#### 0.1

 * Initial version

## Àkójọpọ̀ Meta

 *  Ẹ̀yà **0.5**
 *  Ìgbàgbọ́hùn tó kẹ́yìn **ọdún 14 sẹ́yìn**
 *  Àwọn ìgbéwọlẹ̀ tó ṣiṣẹ́ **800+**
 *  Ẹ̀yà WordPress ** 3.0 tàbí ju bẹ́ẹ̀ lọ **
 *  Dánwò dé **3.4.2**
 *  Èdè
 * [English (US)](https://wordpress.org/plugins/wp-router/)
 * Àmì
 * [URL mapping](https://yor.wordpress.org/plugins/tags/url-mapping/)
 *  [Ìwòye Tó Péye](https://yor.wordpress.org/plugins/wp-router/advanced/)

## Àwọn ìbò

 3.7 lára àwọn ìràwọ̀ 5.

 *  [  2 5-star reviews     ](https://wordpress.org/support/plugin/wp-router/reviews/?filter=5)
 *  [  0 4-star reviews     ](https://wordpress.org/support/plugin/wp-router/reviews/?filter=4)
 *  [  0 3-star reviews     ](https://wordpress.org/support/plugin/wp-router/reviews/?filter=3)
 *  [  0 2-star reviews     ](https://wordpress.org/support/plugin/wp-router/reviews/?filter=2)
 *  [  1 1-star review     ](https://wordpress.org/support/plugin/wp-router/reviews/?filter=1)

[Your review](https://wordpress.org/support/plugin/wp-router/reviews/#new-post)

[See all reviews](https://wordpress.org/support/plugin/wp-router/reviews/)

## Àwọn Olùkópa

 *   [ Jonathan Brinley ](https://profiles.wordpress.org/jbrinley/)

## Ìrànlọ́wọ́

Nǹkan wà tí o fẹ́ sọ? Ṣé o nílò ìrànlọ́wọ́?

 [Wo àpéjọ ìrànlọ́wọ́](https://wordpress.org/support/plugin/wp-router/)

## Ṣe ìtọrẹ

Ṣé o fẹ́ ṣe àtìlẹ́yìn fún ìlọsíwájú plugin yìí?

 [ Ṣe ìtọrẹ sí plugin yìí ](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=A69NZPKWGB6H2)