REST API Comment

REST API Comment adds in the 'Comment creation' function to the WordPress REST API.

Author:Joaquim Domingos António (profile at wordpress.org)
WordPress version required:5.5
WordPress version tested:5.8.1
Plugin version:1.0.2
Added to WordPress repository:22-10-2021
Last updated:07-11-2021
Warning! This plugin has not been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues when used with more recent versions of WordPress.
Rating, %:0
Rated by:0
Plugin URI:
Total downloads:489
Active installs:20+
plugin download
Click to start download

If you wish to ‘Create comments’ using REST API, without exposing Administrator credentials to the Front-End application, you are at the right place. Since WordPress 4.7, REST API was natively included in WordPress.

In order to ‘Create a comment’ , the authentication for a user with ‘Administrator’ role is required. While this is a deliberately done for security reasons, such implementation makes it very hard for Front-End applications to implement a simple ‘Post Comment’ or ‘Reply Comment’ function.

This plugin fulfils such requirement by extending the existing WordPress REST API endpoints.

Requirements:

Minimum PHP version: 7.0
Minimum WordPress version: 5.5

Installation:

Download the plugin form wordpress marketplace install it like any other WordPress plugin.
After the installation activate the plugin through the ‘Plugins’ menu in WordPress

Endpoint:

When this plugin is installed one new endpoint is added to the wp/v2 namespace.

Endpoint
HTTP Verb
Permalinks

*/wp-json/wp/v2/comments/create
POST
enabled

*/?rest_route=/wp/v2/comments/create
POST
disabled

Usage:

  1. Create a Comment

To create a comment using REST API, send a POST request to:

/wp-json/wp/v2/comments/create – if permalinks is enabled on your wordpress website.

Or

/?rest_route=/wp/v2/comments/create if permalinks is not enabled on your wordpress website.

With a JSON body, as shown bellow:

`Json

{
“post”: “Post ID”,
“author_name”: “Comment Author’s name”,
“author_email”: “Comment Author’s email”,
“content”: “Comment content”
}
`

The content may also be send as an object:

`Json

{
“post”: “Post ID”,
“author_name”: “Comment Author’s name”,
“author_email”: “Comment Author’s email”,
“content”: {
“raw”:”Comment content”
}
}
`

Set header to:

`

content-type: application/json
`
If successful, you should receive a response with the data of the created comment:

`Json

{
“id”: “[comment id]”,
“status”: “[comment status]”,
“message”:”[server response message]”
}
`

In response header the status code should be:

`Http

HTTP 201 Created
`

  1. Reply a comment

To reply a comment you just need to add the field parent for the parent comment to the JSON body

`Json

{
“post”: “Post ID”,
“author_name”: “Comment Author’s name”,
“author_email”: “Comment Author’s email”,
“content”: “Comment content”,
“parent”:”Comment parent ID”
}
`

Note: Ensure the parent is a comment id that belongs to the post informed in the field post. The comment parent post id must match the post id otherwise the following error will be shown:

`Json

{
“code”: “rest_post_mismatch_parent_post_id”,
“message”: “Post ID and Parent post ID does not match”,
“data”: {
“status”: 400
}
}
`

Contact

If there is any thing to say about the plugin fill free to contact us.


Screenshots
FAQ
ChangeLog