Advertisement
geminilabs

[site_reviews] Set the email and name from the logged-in user

Feb 25th, 2023
833
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.50 KB | None | 0 0
  1. /**
  2.  * Set the email and name from the logged-in user
  3.  * @param array $fields
  4.  * @return array
  5.  */
  6. add_filter('site-reviews/review-form/fields/normalized', function ($fields) {
  7.     if (!is_user_logged_in()) {
  8.         return $fields;
  9.     }
  10.     $user = wp_get_current_user();
  11.     array_walk($fields, function ($field) use ($user) {
  12.         if ('email' === $field->path) {
  13.             $field->value = $user->user_email;
  14.         }
  15.         if ('name' === $field->path) {
  16.             $field->value = $user->display_name;
  17.         }
  18.     });
  19.     return $fields;
  20. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement