Advertisement
geminilabs

[site-reviews] set the name/email values from an URL parameter

Oct 18th, 2023 (edited)
1,619
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.72 KB | None | 0 0
  1. /**
  2.  * Set the name and email values from URL parameters (?review_name=&review_email=)
  3.  * Example: https://domain.com?review_name=Jane&review_email=jane@xxx.com
  4.  * @param array $fields
  5.  * @return array
  6.  */
  7. add_filter('site-reviews/review-form/fields/normalized', function ($fields) {
  8.     $parameters = array_filter([
  9.         'email' => filter_input(INPUT_GET, 'review_email', FILTER_VALIDATE_EMAIL),
  10.         'name' => filter_input(INPUT_GET, 'review_name'),
  11.     ]);
  12.     $haystack = wp_list_pluck(wp_list_pluck($fields, 'field'), 'path');
  13.     foreach ($parameters as $needle => $value) {
  14.         if (in_array($needle, $haystack)) {
  15.             $index = array_search($needle, $haystack);
  16.             $fields[$index]->field['value'] = $value;
  17.         }
  18.     }
  19.     return $fields;
  20. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement