update_comment_cache

The timeline below displays how wordpress function update_comment_cache has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.1

/**
 * Updates the comment cache of given comments.
 *
 * Will add the comments in $comments to the cache. If comment ID already exists
 * in the comment cache then it will not be updated. The comment is added to the
 * cache using the comment group with the key using the ID of the comments.
 *
 * @since 2.3.0
 * @since 4.4.0 Introduced the `$update_meta_cache` parameter.
 *
 * @param WP_Comment[] $comments          Array of comment objects
 * @param bool         $update_meta_cache Whether to update commentmeta cache. Default true.
 */
function update_comment_cache($comments, $update_meta_cache = true)
{
    $data = array();
    foreach ((array) $comments as $comment) {
        $data[$comment->comment_ID] = $comment;
    }
    wp_cache_add_multiple($data, 'comment');
    if ($update_meta_cache) {
        // Avoid `wp_list_pluck()` in case `$comments` is passed by reference.
        $comment_ids = array();
        foreach ($comments as $comment) {
            $comment_ids[] = $comment->comment_ID;
        }
        update_meta_cache('comment', $comment_ids);
    }
}

WordPress Version: 5.1

/**
 * Updates the comment cache of given comments.
 *
 * Will add the comments in $comments to the cache. If comment ID already exists
 * in the comment cache then it will not be updated. The comment is added to the
 * cache using the comment group with the key using the ID of the comments.
 *
 * @since 2.3.0
 * @since 4.4.0 Introduced the `$update_meta_cache` parameter.
 *
 * @param WP_Comment[] $comments          Array of comment objects
 * @param bool         $update_meta_cache Whether to update commentmeta cache. Default true.
 */
function update_comment_cache($comments, $update_meta_cache = true)
{
    foreach ((array) $comments as $comment) {
        wp_cache_add($comment->comment_ID, $comment, 'comment');
    }
    if ($update_meta_cache) {
        // Avoid `wp_list_pluck()` in case `$comments` is passed by reference.
        $comment_ids = array();
        foreach ($comments as $comment) {
            $comment_ids[] = $comment->comment_ID;
        }
        update_meta_cache('comment', $comment_ids);
    }
}

WordPress Version: 4.4

/**
 * Updates the comment cache of given comments.
 *
 * Will add the comments in $comments to the cache. If comment ID already exists
 * in the comment cache then it will not be updated. The comment is added to the
 * cache using the comment group with the key using the ID of the comments.
 *
 * @since 2.3.0
 * @since 4.4.0 Introduced the `$update_meta_cache` parameter.
 *
 * @param array $comments          Array of comment row objects
 * @param bool  $update_meta_cache Whether to update commentmeta cache. Default true.
 */
function update_comment_cache($comments, $update_meta_cache = true)
{
    foreach ((array) $comments as $comment) {
        wp_cache_add($comment->comment_ID, $comment, 'comment');
    }
    if ($update_meta_cache) {
        // Avoid `wp_list_pluck()` in case `$comments` is passed by reference.
        $comment_ids = array();
        foreach ($comments as $comment) {
            $comment_ids[] = $comment->comment_ID;
        }
        update_meta_cache('comment', $comment_ids);
    }
}

WordPress Version: 3.9

/**
 * Updates the comment cache of given comments.
 *
 * Will add the comments in $comments to the cache. If comment ID already exists
 * in the comment cache then it will not be updated. The comment is added to the
 * cache using the comment group with the key using the ID of the comments.
 *
 * @since 2.3.0
 *
 * @param array $comments Array of comment row objects
 */
function update_comment_cache($comments)
{
    foreach ((array) $comments as $comment) {
        wp_cache_add($comment->comment_ID, $comment, 'comment');
    }
}

WordPress Version: 3.7

/**
 * Updates the comment cache of given comments.
 *
 * Will add the comments in $comments to the cache. If comment ID already exists
 * in the comment cache then it will not be updated. The comment is added to the
 * cache using the comment group with the key using the ID of the comments.
 *
 * @since 2.3.0
 * @package WordPress
 * @subpackage Cache
 *
 * @param array $comments Array of comment row objects
 */
function update_comment_cache($comments)
{
    foreach ((array) $comments as $comment) {
        wp_cache_add($comment->comment_ID, $comment, 'comment');
    }
}