ap_user_votes_pre_fetch( array $ids )

Description #

Pre fetch and cache all votes by given post ID.

Parameters #

  • $ids
    array (Required) Post IDs.

Source #

File: includes/votes.php

function ap_user_votes_pre_fetch( $ids ) {
	if ( $ids && is_user_logged_in() ) {
		$votes = ap_get_votes(
			array(
				'vote_post_id' => (array) $ids,
				'vote_user_id' => get_current_user_id(),
				'vote_type'    => array( 'flag', 'vote' ),
			)
		);

		$cache_keys = array();
		foreach ( (array) $ids as $post_id ) {
			$cache_keys[ $post_id . '_' . get_current_user_id() . '_flag' ] = true;
			$cache_keys[ $post_id . '_' . get_current_user_id() . '_vote' ] = true;
		}

		foreach ( (array) $votes as $vote ) {
			unset( $cache_keys[ $vote->vote_post_id . '_' . $vote->vote_user_id . '_' . $vote->vote_type ] );
		}
	}
}

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