我不建议这样做。如果您对用户进行身份验证会更好,但您可以创建一个api端点来发布如下注释:
add_action(\'rest_api_init\',
function () {
register_rest_route(
\'api\',
\'api_post_comment\',
array(
\'methods\' => \'GET\',
\'callback\' => \'api_post_comment\',
)
);
});
function api_post_comment() {
wp_insert_comment([
\'comment_approved\' => 0,
\'comment_author\' => \'test\',
\'comment_author_email\' => \'[email protected]\',
\'comment_author_IP\' => $_SERVER[\'REMOTE_ADDR\'],
\'comment_content\' => \'test\',
\'comment_parent\' => 0,
\'comment_post_ID\' => 25084,
]);
}
您可以在此处了解更多信息:
https://developer.wordpress.org/reference/functions/wp_insert_comment/这里:https://developer.wordpress.org/rest-api/extending-the-rest-api/adding-custom-endpoints/