• Resolved ant42

    (@ant42)


    Hello,

    I’m using the apply_filters(‘glsr_create_review’, false, []); function in PHP to create reviews. I need to implement checks for duplicates and limit the number of reviews to one per person, just like the standard review form displayed via shortcodes.

    Additionally, I want to display messages similar to the standard form, such as:

    <div class="glsr-form-message glsr-form-failed">Duplicate review detected. It looks like you already said that!</div>

    <div class="glsr-form-message glsr-form-success">Your review has been submitted!</div>

    Is there a way to get the result or error from the function so I can handle these messages accordingly? Or do I need to implement custom logic for this?

    Thank you.

Viewing 1 replies (of 1 total)
  • Plugin Author Gemini Labs

    (@geminilabs)

    You will be able to filter the Validators used in the glsr_create_review function in Site Reviews v7.1.0 like this:

    add_filter('site-reviews/validators', function (array $validators) {
    if (true !== glsr()->retrieve('glsr_create_review')) {
    return $validators;
    }
    return [
    '\GeminiLabs\SiteReviews\Modules\Validator\DefaultValidator',
    '\GeminiLabs\SiteReviews\Modules\Validator\CustomValidator',
    '\GeminiLabs\SiteReviews\Modules\Validator\PermissionValidator',
    '\GeminiLabs\SiteReviews\Modules\Validator\DuplicateValidator',
    '\GeminiLabs\SiteReviews\Modules\Validator\ReviewLimitsValidator',
    '\GeminiLabs\SiteReviews\Modules\Validator\BlacklistValidator',
    '\GeminiLabs\SiteReviews\Modules\Validator\AkismetValidator',
    ];
    });

    And then you would get the errors and error message like this:

    $review = apply_filters('glsr_create_review', false, [...]);

    if (function_exists('glsr') && false === $review) {
    $errors = glsr()->session()->cast('form_errors', 'array');
    $message = glsr()->session()->cast('form_message', 'string');
    }
    • This reply was modified 2 months, 1 week ago by Gemini Labs.
    • This reply was modified 2 months, 1 week ago by Gemini Labs.
Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.