Edit like/unlike function

This topic contains 1 reply, has 2 voices, and was last updated by  Stiofan O’Connor 5 years, 10 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket

Tagged: 

  • Author
    Posts
  • #436389

    Peter Georgiou
    Expired Member
    Post count: 4

    Hi there,

    I have currently copied and altered the function geodir_reviewrating_comments_like_unlike in my functions file. I managed to get it to display what I needed it to show and in the correct place. It works perfectly on load and reload of the page but the thing is, once I click on the like button it makes an ajax call and then returns the original plugin text (i.e. ‘You like this’) instead of my custom text which I changed to ‘you found this review helpful’.

    How can I make sure that the ajax call that is made returns my custom function?

    Here is my custom function:

    function custom_geodir_reviewrating_comments_like_unlike($comment_id, $echo = true, $login_alert = false) {
    $has_liked = geodir_reviewrating_has_comment_liked($comment_id);
    $get_total_likes = geodir_reviewrating_get_total_liked($comment_id);

    $script = false;
    if ($login_alert && !get_current_user_id()) {
    $script = ‘<script type=”text/javascript”>alert(“‘ . esc_attr(__(‘You must be logged-in to like a review comment.’, ‘geodir_reviewratings’)) . ‘”)</script>’;
    }

    $like_action = ‘like’;
    $like_class = ”;
    $like_text = wp_sprintf(__(‘%d people found this review helpful.’, ‘geodir_reviewratings’), $get_total_likes);
    $like_button = ‘<i class=”fa fa-thumbs-o-up gdrr-btn-like”></i>’;
    if ($has_liked) {
    $like_action = ‘unlike’;
    $like_class = ‘ gdrr-liked’;
    $like_button = ‘<i class=”fa fa-thumbs-up gdrr-btn-like”></i>’;
    if ($get_total_likes > 1) {
    $like_text = $get_total_likes == 2 ? __(‘You and 1 other person found this review helpful.’, ‘geodir_reviewratings’) : wp_sprintf(__(‘You and %d other people found this review helpful.’, ‘geodir_reviewratings’), ($get_total_likes – 1));
    } else {
    $like_text = __(‘You found this review helpful.’, ‘geodir_reviewratings’);
    }
    }

    /**
    * Filter the like/useful button html.
    *
    * @since 1.2.8
    * @package GeoDirectory_Review_Rating_Manager
    *
    * @param string $like_button Like/useful button content.
    * @param string $like_action Action to handle on button click (like or unlike).
    * @param bool $has_liked True if current user has liked this, otherwise false.
    */
    $like_button = apply_filters(‘geodir_reviewrating_like_unlike_button’, $like_button, $like_action, $has_liked);

    $html = ‘<div class=”comments_review_likeunlike’ . $like_class . ‘” data-comment-id=”‘ . $comment_id . ‘” data-like-action=”‘ . $like_action . ‘” data-wpnonce=”‘ . esc_attr(wp_create_nonce(‘gd-like-‘ . (int)$comment_id)) . ‘”><span class=”like_count”>’ . $like_button . $like_text . ‘</span>’ . $script . ‘</div>’;

    if ($echo)
    echo $html;
    else
    return $html;
    }

    #436430

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    A valid license is required to view this reply.

    You may need to login

    OR

    Buy either a Membership or valid license for this product.

    Thanks, Team GeoDirectory!

Viewing 2 posts - 1 through 2 (of 2 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket