Skip to content

Commit

Permalink
Merge pull request #51 from hozerapha/master
Browse files Browse the repository at this point in the history
Added a requested function to check if user has liked a post
  • Loading branch information
Alimir authored Jul 2, 2019
2 parents af33562 + 6e68265 commit 9b6bc58
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions inc/general-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1568,6 +1568,34 @@ function wp_ulike_generate_user_id( $user_ip ) {
}
}

/**
* Function to check if user has liked post
*
* @author Jose Colina [hozerapha]
* @param String $user_ID, $post_ID
* @since > 3.5.1
* @return Boolean
*/
if(!function_exists('wp_ulike_user_liked_post')) {
function wp_ulike_user_liked_post($user_ID, $post_ID) {
// Global wordpress database object
global $wpdb;
// Get ULike settings
$wpu_settings = wp_ulike_get_post_settings_by_type('likeThis', $post_ID);
$table_name = $wpu_settings['table_name'];
$column_name = $wpu_settings['column_name'];
// Get number of likes in the post by the user
$results = $wpdb->get_results( "SELECT COUNT(id) AS total
FROM ".$wpdb->prefix."$table_name
WHERE $column_name = '$post_ID'
AND status = 'like'
AND user_id = $user_ID"
);
// Return bool true if there is a like
return ($results[0]->total > 0);
}
}

/*******************************************************
Templates
*******************************************************/
Expand Down

0 comments on commit 9b6bc58

Please sign in to comment.