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