Activity::prefetch_comments()

Description #

Pre fetch comments of activities and cache them.

Changelog #

VersionDescription
4.1.2Introduced.

Source #

File: includes/class/class-activity.php

	private function prefetch_comments() {
		global $wpdb;

		if ( empty( $this->ids['comment'] ) ) {
			return;
		}

		$ids      = esc_sql( sanitize_comma_delimited( $this->ids['comment'] ) );
		$comments = $wpdb->get_results( "SELECT * FROM {$wpdb->comments} WHERE comment_ID in ({$ids})" ); // phpcs:ignore WordPress.DB

		// Cache comments.
		foreach ( $comments as $_comment ) {
			wp_cache_set( $_comment->comment_ID, $_comment, 'comment' );
		}
	}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment