wpseek.com
Bazujące na WordPress narzędzie wyszukiwania dla deweloperów i twórców motywów.



update_comment_cache › WordPress Function

Od2.3.0
Przestarzałyn/a
update_comment_cache ( $comments, $update_meta_cache = true )
Parametry: (2)
  • (WP_Comment[]) $comments Array of comment objects
    Wymagane: Tak
  • (bool) $update_meta_cache Whether to update commentmeta cache. Default true.
    Wymagane: Nie
    Domyślny: true
Zdefiniowane na:
Codex:
Dziennik zmian:
  • 4.4.0

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.


Źródło

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 );
	}
}