gpt4 book ai didi

wordpress - rest_api_init 事件未触发

转载 作者:行者123 更新时间:2023-12-02 22:02:11 24 4
gpt4 key购买 nike

我正在尝试在 wp 4.7.4 上运行自定义插件。下面是我的简单插件

add_action( 'rest_api_init', 'register_routes');


function register_routes() {
register_rest_route( 'taxonomy-manager/v1', '/taxonomies/(P<taxonomy_type>[a-zA-Z]+)', array(
'methods' => 'GET',
'callback' => 'get_or_insert'
) );
}

function get_or_insert( WP_REST_Request $request ) {

$parameters = $request->get_params();

return $parameters;

}

当我请求 wp-json 端点时,我看到那里没有插件路由。插件已成功激活。我错过了什么吗?上述插件(或基于 rest_api_init 事件的类似插件)对其他人有效吗?谢谢。

最佳答案

我找到了解决方案,您需要将 wp-json 与您的 URL 一起使用...例如 https://yourdomain.com/wp-json/namespace/and-so-on/

然后就可以了。我在 URL 中缺少 wp-json。

关于wordpress - rest_api_init 事件未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44204307/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com