geminilabs

Fix WPML translated reviews (not supported!)

Sep 25th, 2021
658
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * THIS IS UNSUPPORTED!
  3.  *
  4.  * Translating reviews with WPML will create reviews in the wp_posts table
  5.  * that are NOT linked to review details in the custom Site Reviews tables.
  6.  * This may break functionality of Site Reviews and it is NOT supported!
  7.  */
  8. add_action('site-reviews/review/build/before', function ($review) {
  9.     // get the current language
  10.     $lang = apply_filters('wpml_current_language', null);
  11.     // get the Post ID of the translated review
  12.     $postId = apply_filters('wpml_object_id', $review->ID, glsr()->post_type, true, $lang);
  13.     // only proceed if the review has been translated
  14.     if ($postId === $review->ID) {
  15.         return;
  16.     }
  17.     $post = get_post($postId);
  18.     if (!empty($post->post_title)) {
  19.         $review->set('title', $post->post_title);
  20.     }
  21.     if (!empty($post->post_content)) {
  22.         $review->set('content', $post->post_content);
  23.     }
  24. });
  25.  
RAW Paste Data