Advertisement
geminilabs

[site-reviews] Set form rating value from an URL parameter

Mar 19th, 2021
1,026
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.49 KB | None | 0 0
  1. /**
  2.  * Set the form rating value from an URL parameter (?overall_rating=)
  3.  * Example: https://domain.com?overall_rating=4
  4.  * @param array $fields
  5.  * @return array
  6.  */
  7. add_filter('site-reviews/config/forms/review-form', function ($fields) {
  8.     if (isset($fields['rating'])) {
  9.         $rating = intval(filter_input(INPUT_GET, 'overall_rating'));
  10.         $rating = max(0, $rating);
  11.         if ($rating > 5) {
  12.             $rating = 5;
  13.         }
  14.         $fields['rating']['value'] = $rating;
  15.     }
  16.     return $fields;
  17. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement