致命错误:调用未定义的函数REST_ROUTE()

时间:2018-04-17 作者:Sebastian Berglönn

我得到了错误Fatal error: Call to undefined function register_rest_route() 当我试着去举例的时候。com/wp json。怎么了?

我的代码是这样的:

add_action(\'rest_api_init\', function () {
  register_rest_route( \'route\', \'/path\', array(
    \'methods\' => \'GET\',
    \'callback\' => \'function\',
  ) );
} );

1 个回复
SO网友:NikHiL Gadhiya
//The Following registers an api route with multiple parameters. 

 <?php
   add_action( \'rest_api_init\', \'add_custom_users_api\');

    function add_custom_users_api()
    {
        register_rest_route( \'route\', array(
                                    \'methods\' => \'GET\',
                                    \'callback\' => \'function\',
                           ));
    }
结束

相关推荐

Php致命错误:无法将WP_REST_RESPONSE类型的对象用作wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php中

我向WordPress添加了一个自定义端点,如下所示: add_action( \'rest_api_init\', function () { register_rest_route( \'menc/v1\', \'/crosscat/(?P[\\w-]+)/(?P[\\w-]+)\', array( \'methods\' => \'GET\', \'callback\' => \'dept_cat_api\',&#x