Right now, if people want to show their WP comments they have to fetch the data themselves and build the logic, or use external services like Disqus. We could build a package to do this so users can use WordPress default comment system.
User Stories
As a Frontity user
I want to be able to access my WordPress comments in the state
so that I can consume them however I want
As a Frontity user
I want to be able to call an action to post a new comment
so that I can integrate it in my Comments forms
As a Frontity user I want to have a component to show my comments so that I just have to adapt some styles and not build my own logic
As a Frontity user I want to have a component with a form to submit new comments so that I just have to adapt some styles and not build my own logic
As a Frontity user I want to be able to break comments into pages, selecting the number of top level comments so that I don’t have to load all comments from the beginning
As a Frontity user I want to be able to order my comments from older to newer or newer to older so that I can select depending on each specific case
Possible solution
As @luisherranz suggested, the comments fetch could be handled by wp-source via actions.source.fetch("@comments/1232"), while we could work on a package to expose:
Comments : a component that shows both the comments and the form to create a new one.
CommentForm a component to create a new comment.
actions.comments.create(...) : an action for those themes that want to create the form themselves, but don’t want to implement the logic.
Apart from that, we need to investigate a way to pass down styles to an external component:
Please, bear in mind that this section wasn’t part of the opening post. It has been added afterwards and its purpose is to keep a quick summary with the most relevant information about this FD at the top of the thread.
@luisherranz I like the approach you suggested. I guess both components, the comments and the form, would be minimal and theme developers just have to style them right? Could they even use a processor if they want to modify the logic of the components?
Hi, have you implemented this package? I tested this method of showing comments but it’s probably only for displaying and no option for posting a new comment. So it’s useless if we can’t add new comments posting method. For this I know we may need to config our WP for accepting post requests too.
I don’t want to use Disqus. So any guide for a noob?
We haven’t implemented this yet. It’s one of our top priorities so I guess we’ll work on it during the coming weeks. Anyway, you may want to take a look at WP REST API Handbook, as you said, you can add new comments using POST - > https://developer.wordpress.org/rest-api/reference/comments/#create-a-comment.
You can also take a look at this guide, the implementation should be pretty similar. Let us know if you finally try it
Actually it’s a bit different scenario in my case as I’m using wordpress.com not .org so authentication etc is a bit different. Also I don’t posses any good skills in things like oauth etc. wordpress.com docs are not making sense to me – maybe they’re for experts. However with localhost I used JWT authentication plugin. I test it sort of working but after dumping off I tried with .com and solution not found.
Can you tell me that is frontity has any method of API authorization? Like can I switch frontity to use authenticated API and provide it with username and p/w of admin. I found when we enable a authentication plugin frontity stops grabbing data from public endpoints too
In an old version of the framework we were using a call to /wp-comments-post.php in the WP site, actually the same call that a page served from WP would do to post a comment. That way you don’t have to deal with neither REST API calls nor authentication at all.
If I remember correctly, you have to send a POST request to yourwpsite.com/wp-comments-post.php along with the comment info as a form data object (you can create a <form> for that):
Thanks for the answer. For testing I created a form on codepen link here. Actually wordpress is refusing to accept commented posted from outside even I have disabled all of the required things like author login requirements etc for sort of anonymous behavior
I guess that means we can’t support WP.com comments with the same, non-authenticated approach. Maybe we need two separate packages, wp-org-comments and, in the future, wp-com-comments.
What I feel is maybe no, we don’t need separate package. We’d follow a better approach. Because all wp user use some sort of security plugins they may interfere and there will be a lot of issues as number of people increase.
Why not make package which follow this method https://developer.wordpress.com/docs/api/1.1/post/sites/%24site/posts/%24post_ID/replies/new/ and find a wp.org plugin or make a new one which simply enable oauth authentication similar to wp.com?
highlander_comment_nonce and akismet_comment_nonce are available in the HTML, we could do a fetch and extract those.
But ak_js is not. My guess is that that number is generated using JavaScript and if you don’t send it, the request will fail.
We would have to study if it’s possible to create comments from an external service when Akismet is activated. @David and @inamkbmail, could you please take a look at that and report what you find?
Actually I tried changing values of each to 123456 and comment got submitted but when I altered value of highlander_comment_nonce it brought up the same error like 'comment couldn’t be posted`. If
and we can get that nonce then we’re close to the solution.
Sorry I sent a few comments on your web please remove them from moderation awaiting list.
I think we need to understand better how Akismet works because it is activated by default on WP.com but it is also widely used in self-hosted WP. Same for Jetpack.
If our comments package doesn’t work with Akismet or Jetpack, Frontity itself will be much less appealing.
I think we need to understand better how Akismet and JetPack work before we start coding.
Here it is the development API of Akismet. In libraries, there a couple of Node/JS libraries you can take a look: