ap_is_viewed( integer|false $ref_id, integer $user_id, string $type = 'question', string|boolean $ip = false )

Description #

Check if user already viewd post or user profile.

Parameters #

  • $ref_id
    integer | false (Required) Reference ID.
  • $user_id
    integer (Required) User ID.
  • $type
    string (Optional) View type. Default value: 'question'
  • $ip
    string | boolean (Optional) IP address. Default value: false

Source #

File: includes/views.php

function ap_is_viewed( $ref_id, $user_id, $type = 'question', $ip = false ) {
	if ( empty( $ref_id ) ) {
		return false;
	}

	global $wpdb;
	$ip_clue = '';

	if ( false !== $ip ) {
		$ip_clue = $wpdb->prepare( ' AND view_ip = %s', $ip );
	}

	$query = $wpdb->prepare( "SELECT count(*) FROM {$wpdb->ap_views} WHERE view_user_id = %d AND view_ref_id = %d AND view_type = %s {$ip_clue}", $user_id, $ref_id, $type ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared

	$count = $wpdb->get_var( $query ); // phpcs:ignore WordPress.DB

	return $count > 0 ? true : false;
}

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