dsoihsnz85757 2018-12-18 10:33
浏览 142

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

How can I expose rest API in custom plugin ? I want to expose this route, When I use it into functions.php, it works, but when I use it in my custom plugin, the route is not found.

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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!