Skip to content
This repository has been archived by the owner. It is now read-only.

Cannot Comment Without Being Logged In #2960

Closed
noamichael opened this issue Dec 10, 2016 · 11 comments
Closed

Cannot Comment Without Being Logged In #2960

noamichael opened this issue Dec 10, 2016 · 11 comments
Labels

Comments

@noamichael
Copy link

@noamichael noamichael commented Dec 10, 2016

Hey guys,

So, I'm using the latest version of the WP-API, and it appears that I am unable to submit a comment without being logged in. My wordpress settings allow for anyone to comment.

My request looks like this:

POST
http://www.example.com/wp-blog/wp-json/wp/v2/comment?post=124&content=Hello_world&author_name=Me&email=Me%40example.com
Response => {
            "code":"rest_comment_login_required",
            "message":"Sorry, you must be logged in to comment.",
            "data":{"status":401}
}

Is there anyway to do this with the current API?

@websupporter
Copy link
Member

@websupporter websupporter commented Dec 10, 2016

Hi noamichael,
anonymous comment by default is disabled with the 4.7 API. However, there is a filter, you can use:
add_filter( 'rest_allow_anonymous_comments', '__return_true' );

should do the trick.

@noamichael
Copy link
Author

@noamichael noamichael commented Dec 10, 2016

@websupporter

Thanks for the quick reply! Where would you add that definition? I'm not too familiar with PHP and I don't know where the standard place to add such a definition would be.

@websupporter
Copy link
Member

@websupporter websupporter commented Dec 10, 2016

One place could be your (child) themes functions.php

@BE-Webdesign
Copy link
Member

@BE-Webdesign BE-Webdesign commented Dec 10, 2016

@noamichael,

The best option is to create a simple plugin file, alternatively you can place it in a themes functions.php. If you place the code into a theme file, when you change your active theme the functionality will be lost.

@BE-Webdesign
Copy link
Member

@BE-Webdesign BE-Webdesign commented Dec 10, 2016

Closing this out as this is not a bug/enhancement for the API. Feel free to continue discussion here.

@noamichael
Copy link
Author

@noamichael noamichael commented Dec 10, 2016

@websupporter @BE-Webdesign

Thank you for the speedy support, guys. I can now comment as expected.

@websupporter
Copy link
Member

@websupporter websupporter commented Dec 10, 2016

Great :) Glad we were able to help.

@ChrisSargent
Copy link

@ChrisSargent ChrisSargent commented Dec 14, 2016

3 hours later of wondering why it wasn't working.... thanks! Might have been nice for someone to mention this: https://codex.wordpress.org/Version_4.7

@wilburt
Copy link

@wilburt wilburt commented Feb 3, 2017

So how do we post the comment with the user authenticated?

@WP-API WP-API locked as spam and limited conversation to collaborators Apr 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
7 participants
@websupporter @noamichael @ChrisSargent @BE-Webdesign @wilburt and others