• Resolved entumas

    (@entumas)


    Hi! (I love your plugin)

    How can I validate if a user has reviewed a post?

    I want that if user have not done the review, the form will appear.
    And if he has already done it, he will get his own review.

    Function type
    if ( review_exits ) { [site_reviews] } else { [site_reviews_form] }

    Thanks!

    • This topic was modified 3 years, 8 months ago by entumas.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Gemini Labs

    (@geminilabs)

    1. Use the review limits option in the settings

    2. See the “How do I hide the form after a review is submitted?” section on the FAQ page.

    3. If you are requiring that users are logged in before submitting a review, you can also use the assigned_users="user_id" in the shortcodes to assign reviews to the person who submitted them, and to restrict displayed reviews to those submitted by the user.

    Thread Starter entumas

    (@entumas)

    Hello. thank you very much for the reply. ??

    This function I am already using, but it does not solve my “problems”.
    In addition, wanting to validate whether or not there is a review of a post by the current user, will serve me for more than one use.

    I understand that there is a way and you validate it.
    Can you tell me what it is?

    Thanks

    Plugin Author Gemini Labs

    (@geminilabs)

    If you want the review limits to apply per page and not sitewide, then you need to also be assigning your reviews.

    For example:

    [site_reviews_form assigned_posts=post] will assign reviews to the current page, and the review limits will apply only to that page.

    Thread Starter entumas

    (@entumas)

    Hi again!

    Yes I already know that…
    You only give me solutions, based on examples of use of shortcodes.
    I don’t know if my English is too bad or what.

    The function example I put
    if ( review_exits ) { [site_reviews] } else { [site_reviews_form] }
    it was just a example.

    I want to modify elements of my page that have nothing to do with your plugin, based on whether the user has made a review or not in one post or another.

    I understand that there is a way, and you validate it.
    Can you tell me what it is?

    Thanks

    Plugin Author Gemini Labs

    (@geminilabs)

    As explained earlier, please see the “How do I hide the form after a review is submitted?” section on the FAQ page. The second example in that section explains how to hide the form if someone has already submitted a review.

    And instead of this:

    sprintf('<p>%s</p>', __('Thank you for your review!'));
    

    You could do this:

    do_shortcode('[site_reviews assigned_posts=post_id]');
    

    to display the reviews.

    Otherwise, you could use the glsr_get_reviews function to see if there are any reviews to display based on the options you provide it. For example, if you required that only logged in user can submit a review, then something like this might work:

    $reviews = apply_filters('glsr_get_reviews', [], [
        'assigned_posts' => 'post_id',
        'user__in' => [$currentUserId],
    ]);
    if (count($reviews) > 0) {
        // reviews exists
    } else {
        // reviews do not exist
    }

    Thread Starter entumas

    (@entumas)

    This is what I was looking for.
    Thanks!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Validate if a user has reviewed a post’ is closed to new replies.