Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.

CommentHandler

Marco Siccardi edited this page Jan 31, 2020 · 2 revisions

To get a new instance, either create an inline variable or use your favorite Locator:

//inline var
var handler = new CommentHandler();

//MVVMLight (or any other Locator):
SimpleIoc.Default.Register<ICommentHandler>(()=> new CommentHandler());

If you want to add the "If-Modified-Since"-Header and "User-Agent"-Header, just fill in the parameters:

//inline var
var handler = new CommentHandler(DateTime.Now, "MyAwesomeApp", "1.0.0");

//MVVMLight (or any other Locator):
SimpleIoc.Default.Register<ICommentHandler>(()=> new CommentHandler(DateTime.Now, "MyAwesomeApp", "1.0.0"));

getting a list of comments with default parameters:

var comments = handler.GetCommentsAsync("commentsUrlFromPostEntity");

Note that you have optional parameters for pages and page counts.

post anonymous comment:

var newComment = handler.CreateAnonymousCommentAsync("yourBaseUrl", "AuthorName", "[email protected]", postId: 12345, parentId:78901);

If a parentId is provided, the comment is posted as response to the corresponding comment. The request will give you the newly created comment back. You can then insert it locally into your existing comments list that may already have been downloaded before.

ADDITIONAL WORK NEEDED

  1. You need to allow anonyomous comments generally on your page (Settings/Discussion => check "Comment author must fill out name and email")
  2. You need to explicitly allow anonymous comments in the CommentController (see also the API docs => set $allow_anonymous to true)

Please note that ALL anonymous comments will go into your moderation queue. It is recommended to also have a spam filter active.

In future versions, this library will also be able to handle comments from users that are logged in.

All above calls will result in a WordPressEntitySet<TWordPressEntity> or a WordPressEntity<TWordPressEntity>. If there was an error on the API side, the Error property will be filled, otherwise it will be null and the Value will hold the result.

Clone this wiki locally