duncanjbrown/plain-route
Composer 安装命令:
composer require duncanjbrown/plain-route
包简介
Define arbitrary endpoints in WordPress
README 文档
README
This library provides a simple interface for WordPress's fiddly rewrite rules API.
It's useful for creating arbitrary endpoints with callbacks. For example, a webhook receiver for a payment gateway.
Usage
Creating an endpoint is accomplished by newing one up. You should do this on init.
add_action( 'init', function() {
new Plain_Route( 'stripe(/)?', [
'rewrite' => 'p=123',
'pre_get_posts' => function( $query ) {
if( $query->is_main_query() ) {
$query->set('stripe', true);
}
}]);
});
In the above example, pre_get_posts could be replaced with wp_title or wp. Or you could add them alongside.
You can also render any template with the special template callback.
Creating an endpoint that renders a specific template:
add_action( 'init', function() {
new Plain_Route( 'my-special-template(/)?', [
'template' => 'my-special-template.php'
]);
});
Credit
This class is a much-simplified variation of HM_Rewrite by humanmade.
统计信息
- 总下载量: 1.18k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-01-18