Comment Object and Query Features in 4.4

Without comments, a website is as effective at creating a community as the Chicago Cubs are at winning World Series titles. WordPress 4.4 is a rebuilding release and the comments system is much improved under the hood.

This release lays the groundwork for future features and improvements.

A New Classy and Strong Comment Object

The new WP_Comment class provides a single organized comment object that models its row in $wpdb->comments. You may be familiar with this approach from WP_Post, which inspired the caching implementation used in WP_Comment.

This was a prerequisite to many of the other comment-related bugbug A bug is an error or unexpected result. Performance improvements, code optimization, and are considered enhancements, not defects. After feature freeze, only bugs are dealt with, with regressions (adverse changes from the previous version) being the highest priority. fixes and features added in 4.4. The WP_Comment class is marked final to retain flexibility while it is young.

See #32619.

Comment Queries for the Whole Family

WP_Comment_Query has new query parameters for traversing your comments family tree.

  • parent__in takes an array of comment parent IDs to return all matching children.
  • parent__not_in takes an array of comment parent IDs and does not return any matching children.
  • hierarchical can be set to either threaded, flat, or false.
    • threaded returns a tree for matched comments, with the children for each comment included in its children property.
    • flat returns a flat array of matched comments plus their children.
    • false does not include descendants for matched comments. This is the default behavior.
  • orderby has a new option comment__in, useful when querying by comment__in the matched results will return in the same order.

See #8071 and #33882.

#4-4, #comments, #dev-notes