geminilabs

Untitled

Oct 18th, 2021 (edited)
740
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Modifies the review values before they are saved
  3.  * Paste this in your active theme's functions.php file.
  4.  * @param array $values
  5.  * @param \GeminiLabs\SiteReviews\Commands\CreateReview $command
  6.  * @return array
  7.  */
  8. add_filter('site-reviews/create/review-values', function ($values, $command) {
  9.     // If the user is not logged in
  10.     // Or, if the review was NOT submitted with the specified Review Form
  11.     // Then abort!
  12.     if (!is_user_logged_in() || 21084 != $command->request->form) {
  13.         // return the unchanged values
  14.         return $values;
  15.     }
  16.     // get the logged in user
  17.     $user = wp_get_current_user();
  18.     // get a Post ID from the provided URL
  19.     $postId = url_to_postid('https://www.xyz.com/'.$user->user_nicename);
  20.     // get the post object from the Post ID
  21.     $post = get_post($postId);
  22.     // proceed if the the post object was found; also ensure that the "geodir_get_post_meta" function exists
  23.     if ($post && function_exists('geodir_get_post_meta')) {
  24.         // get the region
  25.         $region = geodir_get_post_meta($post->ID, 'region', true);
  26.         // get the city
  27.         $city = geodir_get_post_meta($post->ID, 'city', true);
  28.         // get the date
  29.         $date = do_shortcode('[geodir_event_schedules type="upcoming" number="1" template="{start_date} - {end_date}" use_current="1"]');
  30.         // finally, change the review title
  31.         $values['title'] = $city.', '.$region.', '.$date;
  32.     }
  33.     // always return the review values!
  34.     return $values;
  35. }, 10, 2);
RAW Paste Data