underpin / rest-endpoint-loader
Underpin的REST端点加载器
1.1.0
2021-11-24 21:34 UTC
Requires
- underpin/underpin: ^2.0
This package is auto-updated.
Last update: 2024-08-25 03:32:06 UTC
README
一个辅助注册REST端点到WordPress网站的加载器。
安装
使用Composer
composer require underpin/rest-endpoint-loader
手动安装
此插件使用内置的自动加载器,因此只要在Underpin之前调用它,就应该按预期工作。
require_once(__DIR__ . '/underpin-rest-endpoints/rest-endpoints.php');
设置
- 安装Underpin。请参阅Underpin文档
- 根据需要注册新的REST端点。
示例
一个非常基本的示例可能看起来像这样。
// Register rest endpoint underpin()->rest_endpoints()->add( 'example-endpoint', [ 'endpoint_callback' => function ( \WP_REST_Request $request ) { return [ 'result' => 'Wow this worked nicely!' ]; }, 'has_permission_callback' => '__return_true', 'rest_namespace' => 'example/v1', 'route' => 'example-endpoint', 'args' => [ 'methods' => 'GET' ], ] );
或者,您可以通过扩展Rest_Endpoint
并直接引用扩展类来实现
underpin()->rest_endpoints()->add('endpoint-key','Namespace\To\Class');
一个常见的用例是使用自己的rest_namespace
扩展Rest_Endpoint
以保持代码DRY。