Advertisement
geminilabs

[site-reviews] hide the review form after submission

Feb 16th, 2024
573
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.07 KB | None | 0 0
  1. /**
  2.  * Hides the review form after a review has been submitted
  3.  * Paste this in your active theme's functions.php file
  4.  *
  5.  * @param string $script
  6.  * @return string
  7.  */
  8. add_filter('site-reviews/enqueue/public/inline-script', function ($script) {
  9.     return $script."
  10.    document.addEventListener('site-reviews/after/submission', function (ev) {
  11.        if (false !== ev.detail.errors) return;
  12.        ev.detail.form.classList.add('glsr-hide-form');
  13.        ev.detail.form.insertAdjacentHTML('afterend', '<p>' + ev.detail.message + '</p>');
  14.    });";
  15. });
  16.  
  17. /**
  18.  * Hides the review form from registered users who have already submitted a review
  19.  * Paste this in your active theme's functions.php file
  20.  *
  21.  * @param string $template
  22.  * @return string
  23.  */
  24. add_filter('site-reviews/rendered/template/reviews-form', function ($template, $data) {
  25.     $request = glsr()->request($data['args']);
  26.     return glsr('Modules\Validator\ReviewLimitsValidator', compact('request'))->isValid()
  27.         ? $template
  28.         : sprintf('<p>%s</p>', __('Thank you for your review!'));
  29. }, 10, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement