geminilabs

Require the review content field if rating is less than 4

Nov 5th, 2025 (edited)
605
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.43 KB | None | 0 0
  1. /**
  2.  * Require the Review content field if the submitted rating is less than 4-stars
  3.  *
  4.  * Make sure to set the review field as not required otherwise this will do nothing!
  5.  *
  6.  * @param \GeminiLabs\SiteReviews\Request $request
  7.  */
  8. add_filter('site-reviews/validation/rules', function (array $rules, $request): array {
  9.     if ($request->rating < 4) {
  10.         $rules['content'] = 'required';
  11.     }
  12.     return $rules;
  13. }, 100, 2);
Advertisement
Add Comment
Please, Sign In to add comment