From 0a859633f0f021c464d162664e66137db43f2f04 Mon Sep 17 00:00:00 2001 From: hozerapha Date: Tue, 4 Jun 2019 10:59:36 -0500 Subject: [PATCH 1/2] Update general-functions.php Added 'wp_ulike_user_liked_post' function to determine if the currently logged in user has liked the post or not. Can be used inside the loop sending the user ID and post ID loop functions as parameters. --- inc/general-functions.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/inc/general-functions.php b/inc/general-functions.php index 54af3d34..05628182 100644 --- a/inc/general-functions.php +++ b/inc/general-functions.php @@ -1537,6 +1537,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.4 + * @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 *******************************************************/ From 6e68265882b343f72e9971fcc9b5252381402b67 Mon Sep 17 00:00:00 2001 From: hozerapha Date: Tue, 4 Jun 2019 11:04:01 -0500 Subject: [PATCH 2/2] Update general-functions.php Fixed version number --- inc/general-functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/general-functions.php b/inc/general-functions.php index 05628182..5ff4ab8f 100644 --- a/inc/general-functions.php +++ b/inc/general-functions.php @@ -1542,7 +1542,7 @@ function wp_ulike_generate_user_id( $user_ip ) { * * @author Jose Colina [hozerapha] * @param String $user_ID, $post_ID - * @since 3.4 + * @since > 3.5.1 * @return Boolean */ if(!function_exists('wp_ulike_user_liked_post')) {