geminilabs

[site-reviews] Only require email field if rating is 1-star or less

Sep 30th, 2021 (edited)
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.51 KB | None | 0 0
  1. /**
  2.  * Require the email field if the submitted rating is 1-star or less
  3.  *
  4.  * Make sure to set the email field as not required in the Settings
  5.  * otherwise this will do nothing.
  6.  *
  7.  * Requires: Site Reviews v5.16
  8.  *
  9.  * @param array $rules
  10.  * @param \GeminiLabs\SiteReviews\Request $request
  11.  * @return array
  12.  */
  13. add_filter('site-reviews/validation/rules/normalized', function ($rules, $request) {
  14.     if ($request->rating < 2) {
  15.         $rules['email'] = 'required|email';
  16.     }
  17.     return $rules;
  18. }, 10, 2);
Add Comment
Please, Sign In to add comment