WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 6 years ago

#5463 closed enhancement (fixed)

New XML-RPC method: wp.getCommentCount

Reported by: josephscott Owned by: westi
Milestone: 2.5 Priority: normal
Severity: normal Version:
Component: XML-RPC Keywords: has-patch
Focuses: Cc:

Description

This ticket supersedes #5341

The new wp.getCommentCount method provides the number of comments that have been approved, are awaiting moderation and have been marked as spam.

An optional post_id can be provided that will limit the comment numbers to just that post.

Example call to get comment count for entire blog:

wp.getCommentCount(blog_id, username, password)

Example call to get comment count for one post:

wp.getCommentCount(blog_id, username, password, post_id)

Example struct that is returned:

{
  "approved" = 1;
  "awaiting_moderation" = 7; 
  "spam" = 369; 
}

I've contacted the author of the WordPress Comment Moderation Notifier and he's fine with adjusting his app to match our API.

Attachments (2)

xmlrpc.php.diff (1.2 KB) - added by josephscott 6 years ago.
comment.php.diff (1.7 KB) - added by josephscott 6 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 redsweater6 years ago

I'm still a little troubled by the fact that this API is being driven by a single plugin with a very specific goal. It seems hasty to implement this very specific API for getting "counts", when probably what should be done is a longer-term thoughtful development of a general "comments" API which would allow fetching and editing them, as well.

I have to admit this API is a lot better than the other one which is being superseded, but it will still look a little embarrassing in the API, I think, to have this strangely orphaned API for getting comment counts, with no other supporting API for comments.

For instance, what if the API for getting posts had been driven from the start by some plugin that just happened to show you your "post count" ? Then we'd have this weird "getPostCount" method to support forever, and it might look kind of weird in the API. I feel like some restraint might be in order to keep the API from bloating in response to nifty plugins.

[Rant Off] :)

comment:2 westi6 years ago

  • Owner changed from anonymous to westi
  • Status changed from new to assigned

Good patch.

Some comments.

Can we avoid embedding database queries in xmlrpc.php - it would be better to introduce a new wordpress api function to expose the data and have the query there - that way we can use it internally or other plugins can use.

comment:3 josephscott6 years ago

The general desire to expose this information certainly did come to the forefront because of this one tool. But is that really a good reason to disregard it? It isn't like no one else will be able to use this if they want to.

I agree that an expanded comments API is a good idea, and this new method is a step that direction. Before submitting this I considered skipping it entirely, but I didn't for two reasons. One, there is obviously an interest in exposing this specific information (comment numbers) and the difference in the size of the data. In order to come up with these numbers via a general comment editing API you'd have to send a significantly larger amount of data across the wire.

I have every intention of adding more comment methods, it seems desirable to have the ability to fetch and modify and perhaps even create comments via XML-RPC. But I'd rather not wait for that to be complete in order to start adding additional useful methods now.

On the embedded query, I totally agree. I was rather surprised not to see a function for doing this already. Would a similar wp_get_comment_count() function in wp-includes/comment.php be reasonable? I can put together a new patch to do that.

comment:4 redsweater6 years ago

Hi Joseph - my faith is in you to do whatever is best. I just wanted to express my gut reaction here, for the record and in case it sparks any rethinking on anybody's part.

By no means do I want to denigrate the work you're doing, though. God, no! ;)

josephscott6 years ago

josephscott6 years ago

comment:5 josephscott6 years ago

I've moved all of the heavy lifting to get_comment_count() in wp-includes/comment.php and updated the xmlrpc.php diff to use that function instead.

While I was at it I added the total_comments field.

comment:6 ryan6 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

(In [6534]) wp.getCommentCount from josephscott. fixes #5463

Note: See TracTickets for help on using tickets.