在自定义插件中公开WORDPRESS REST API

时间:2018-12-18 10:33:43

标签: php wordpress api

如何在自定义插件中公开其余API? 我想公开此路由,当我将其用于functions.php时,它可以工作,但是当我在自定义插件中使用它时,找不到该路由。

add_action( 'rest_api_init', 'my_register_route');

 function my_register_route() {      
    register_rest_route( 'my-route', 'my-posts', array(
            'methods' => 'GET',
            'callback' => 'my_posts',
            'permission_callback' => function() {
                return current_user_can( 'edit_others_posts' );
                }, 
    );
 }

0 个答案:

没有答案