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_idinteger | false (Required) Reference ID.
- $user_idinteger (Required) User ID.
- $typestring (Optional) View type. Default value: 'question'
- $ipstring | 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; }
Expand full source code Collapse full source code View on GitHub: includes/views.php:128
Add your comment