Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 简单Wordpress REST端点路由不';行不通_Php_Wordpress_Rest - Fatal编程技术网

Php 简单Wordpress REST端点路由不';行不通

Php 简单Wordpress REST端点路由不';行不通,php,wordpress,rest,Php,Wordpress,Rest,我需要通过以下方式处理WordPress的外部请求: http://localhost/vku.dev/wp-json/notifications. 无需向整个URL添加其他部分。 所以,我的代码是: function testREST(WP_REST_Request $request) { error_log('Route "notifications" works'); return 'Route "notifications" wor

我需要通过以下方式处理WordPress的外部请求: http://localhost/vku.dev/wp-json/notifications. 无需向整个URL添加其他部分。 所以,我的代码是:

function testREST(WP_REST_Request $request) {
    error_log('Route "notifications" works');
    return 'Route "notifications" works';
    //return new WP_REST_Response(true, 200);
}
add_action('rest_api_init', function () {
    /*
    // Inline function also not working
    register_rest_route('notifications', '', [
        'methods' => 'GET',
        'callback' => function (WP_REST_Request $request) {
            error_log('Route "notifications" works');
            return 'Route "notifications" works';
            //return new WP_REST_Response(true, 200);
        },
    ]);
    */
    register_rest_route('notifications', '', [
        'methods' => 'GET',
        'callback' => 'testREST',
    ]);
});
代码看起来很简单,但不起作用-http://localhost/vku.dev/wp-json/notifications 向我提供某个对象的转储,无法访问事件处理程序的主体。 怎么了