geminilabs

[site-reviews] get the email value from an URL parameter

Aug 22nd, 2021 (edited)
1,989
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.69 KB | None | 0 0
  1. /**
  2.  * @param array $fields
  3.  * @param \GeminiLabs\SiteReviews\Arguments $args
  4.  * @return array
  5.  */
  6. add_filter('site-reviews/review-form/fields', function ($fields, $args) {
  7.     $email = filter_input(INPUT_GET, 'email', FILTER_VALIDATE_EMAIL);
  8.     if (!empty($email)) {
  9.         // Set the input type of the email field to "hidden"
  10.         if (false !== array_search('email', $args->hide)) {
  11.             $args->set('hide', array_diff($args->hide, ['email']));
  12.             $fields['email']['placeholder'] = '';
  13.             $fields['email']['type'] = 'hidden';
  14.         }
  15.         // Set the value of the email field
  16.         $fields['email']['value'] = $email;
  17.     }
  18.     return $fields;
  19. }, 10, 2);
Add Comment
Please, Sign In to add comment