Introduce WP_Comment class to model/strongly-type rows from the comments database table. Inclusion of this class is a pre-req for some more general comment cleanup and sanity.

* Takes inspiration from `WP_Post` and adds sanity to comment caching. 
* Clarifies when the current global value for `$comment` is returned. The current implementation in `get_comment()` introduces side effects and an occasion stale global value for `$comment` when comment caches are cleaned.
* Strongly-types `@param` docs
* This class is marked `final` for now

Props wonderboymusic, nacin.

See #32619.


git-svn-id: https://develop.svn.wordpress.org/trunk@33891 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor
2015-09-03 18:16:35 +00:00
parent 52f31a77e9
commit 60ba8b05e4
16 changed files with 247 additions and 123 deletions
+4 -1
View File
@@ -665,7 +665,10 @@ class WP_Comment_Query {
* @param array $results An array of comments.
* @param WP_Comment_Query &$this Current instance of WP_Comment_Query, passed by reference.
*/
$comments = apply_filters_ref_array( 'the_comments', array( $results, &$this ) );
$_comments = apply_filters_ref_array( 'the_comments', array( $results, &$this ) );
// Convert to WP_Comment instances
$comments = array_map( 'get_comment', $_comments );
wp_cache_add( $cache_key, $comments, 'comment' );
if ( '*' === $fields ) {