=== 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: 3.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 [Adelie Design](http://www.AdelieDesign.com)
== Installation ==
1. Download and unzip the plugin
1. Upload the `WP-Router` folder to the `/wp-content/plugins/` directory
1. Activate the plugin through the 'Plugins' menu in WordPress
1. 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 =
* 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) - 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` - 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` - The title of the page.
* `title_callback` - 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` - 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) - 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'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` - 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` - 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` - 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` - 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.'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 =
* 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 )` - 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 )` - delete the route with the given ID
* `WP_Router::get_route( string $id )` - get the `WP_Route` object for the given ID
* `WP_Router::get_url( string $id, array $arguments )` - get the URL to reach the route with the given ID, with the given query variables and their values
* `WP_Route::get( string $property )` - get the value of the specified property for
the `WP_Route` instance
== Changelog ==
= 0.1 =
* Initial version
= 0.2 =
* Added the `template` argument
= 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.3.1 =
* Added WP_Router::get_url()
* Added WP_Route::url()
= 0.3.2 =
* Make
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
blogga_v1.0_weidea.net_BootstrapWordpress前端源码模板_网站UI界面主题.zip (813个子文件)
PSDs.7z 616KB
global.css 45KB
jquery-ui.css 34KB
prettyPhoto.css 17KB
shortcodes.css 16KB
screen.css 12KB
screen.css 12KB
uniform.default.css 10KB
grid.css 10KB
grid.css 10KB
reset.css 9KB
960_24_col.css 8KB
screen.css 4KB
screen.css 4KB
colorpicker.css 4KB
admin.css 4KB
typography.css 3KB
typography.css 3KB
ie.css 3KB
ie.css 3KB
screen.css 2KB
screen.css 2KB
screen.css 2KB
screen.css 2KB
ie.css 2KB
ie.css 2KB
print.css 2KB
print.css 2KB
forms.css 2KB
forms.css 2KB
supersized.css 2KB
nivo-slider.css 1KB
screen.css 1KB
screen.css 1KB
print.css 1KB
print.css 1KB
reset.css 1KB
reset.css 1KB
style.css 659B
content.css 637B
custom.css 0B
.DS_Store 12KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
ajax-loader.gif 3KB
loading.gif 3KB
loader.gif 2KB
loader.gif 2KB
loader.gif 2KB
loader.gif 2KB
loader.gif 2KB
help.gif 295B
toolbars.gif 260B
default_thumbnail.gif 227B
default_thumbnail.gif 227B
default_thumbnail.gif 227B
default_thumbnail.gif 227B
default_thumbnail.gif 227B
page_bug.gif 180B
media.gif 149B
more_bug.gif 146B
audio.gif 146B
more.gif 108B
page.gif 108B
image.gif 101B
video.gif 99B
colorpicker_indic.gif 86B
custom_indic.gif 86B
colorpicker_indic.gif 86B
custom_indic.gif 86B
colorpicker_select.gif 78B
colorpicker_select.gif 78B
blank.gif 49B
blank.gif 49B
trans.gif 43B
dialog.htm 869B
index.html 25KB
index.html 25KB
index.html 5KB
background.jpg 112KB
comment_depth_background.jpg 3KB
jquery-1.7.2.min.js 93KB
jquery.min.js 90KB
jquery.ui.datepicker.min.js 35KB
merged.js 31KB
pixastic.js 27KB
colorpicker.js 24KB
jquery.ui.sortable.min.js 23KB
共 813 条
- 1
- 2
- 3
- 4
- 5
- 6
- 9
资源评论
dunming_6725413
- 粉丝: 18
- 资源: 6949
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功