Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/278.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 从哪里开始扩展WP-API_Php_Wordpress_Api_Plugins_Extend - Fatal编程技术网

Php 从哪里开始扩展WP-API

Php 从哪里开始扩展WP-API,php,wordpress,api,plugins,extend,Php,Wordpress,Api,Plugins,Extend,我正在尝试为Wordpress使用和 现在我可能只是愚蠢,但我真的不知道从哪里开始,即使我已经读了上面的链接一遍又一遍。我说的不是代码,而是最基本的,我应该把代码放在哪里?在插件中?如果是这样,我需要包括什么才能让它工作?或者这足以扩展课程 对不起,我只是觉得页面上的信息太少了。。。还是我完全错过了一个自上而下的完美结构的例子 在这里。 谢谢你的帮助 我不知道文档是否过时了,但是扩展WP-API非常简单。你得先去 在插件中,注册scripts和styles functions.php、boots

我正在尝试为Wordpress使用和

现在我可能只是愚蠢,但我真的不知道从哪里开始,即使我已经读了上面的链接一遍又一遍。我说的不是代码,而是最基本的,我应该把代码放在哪里?在插件中?如果是这样,我需要包括什么才能让它工作?或者这足以扩展课程

对不起,我只是觉得页面上的信息太少了。。。还是我完全错过了一个自上而下的完美结构的例子

在这里。
谢谢你的帮助

我不知道文档是否过时了,但是扩展WP-API非常简单。你得先去

在插件中,注册scripts和styles functions.php、bootstrap.php等钩子,然后添加一个新钩子来注册路由

add_filter( 'json_endpoints', array( $this, 'registerRoutes' ) );

public function registerRoutes($routes){
        $editorService = $this->container["editorService"];

        $routes['/newsletters'] = array(
            array( array( $editorService, 'create'), \WP_JSON_Server::CREATABLE | \WP_JSON_Server::ACCEPT_JSON ),
        );
        $routes['/newsletters/(?P<id>\d+)'] = array(
            array( array( $editorService, 'get'), \WP_JSON_Server::READABLE )
        );
        return $routes;
    }

我不知道文档是否过时了,但是扩展WP-API非常简单。你得先去

在插件中,注册scripts和styles functions.php、bootstrap.php等钩子,然后添加一个新钩子来注册路由

add_filter( 'json_endpoints', array( $this, 'registerRoutes' ) );

public function registerRoutes($routes){
        $editorService = $this->container["editorService"];

        $routes['/newsletters'] = array(
            array( array( $editorService, 'create'), \WP_JSON_Server::CREATABLE | \WP_JSON_Server::ACCEPT_JSON ),
        );
        $routes['/newsletters/(?P<id>\d+)'] = array(
            array( array( $editorService, 'get'), \WP_JSON_Server::READABLE )
        );
        return $routes;
    }