-
Notifications
You must be signed in to change notification settings - Fork 1
CommentHandler
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"));
var comments = handler.GetCommentsAsync("commentsUrlFromPostEntity");
Note that you have optional parameters for pages and page counts.
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
- You need to allow anonyomous comments generally on your page (Settings/Discussion => check "Comment author must fill out name and email")
- You need to explicitly allow anonymous comments in the CommentController (see also the API docs => set
$allow_anonymous
totrue
)
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.