Function Reference: geodir_wpml_duplicate_post_review
Summary
Duplicate post review for WPML translation post.
Global Values
- $wpdb
- (object) (required) WordPress Database object.
- Default: None
- $plugin_prefix
- (string) (required) Geodirectory plugin table prefix.
- Default: None
Parameters
- $master_comment_id
- (int) (required) Original Comment ID.
- Default: None
- $master_post_id
- (int) (required) Original Post ID.
- Default: None
- $tr_post_id
- (int) (required) Translation Post ID.
- Default: None
- $lang
- (string) (required) Language code for translating post.
- Default: None
Return Values
- (bool)
- True for success, False for fail.
Change Log
Since: 1.6.16
Source File
geodir_wpml_duplicate_post_review() is located in geodirectory-functions/custom_functions.php [Line: 2777]
Source Code
function geodir_wpml_duplicate_post_review($master_comment_id, $master_post_id, $tr_post_id, $lang) { global $wpdb, $plugin_prefix, $sitepress; $review = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . GEODIR_REVIEW_TABLE . " WHERE comment_id=%d ORDER BY id ASC", $master_comment_id), ARRAY_A); if (empty($review)) { return false; } if ($review['post_id'] != $master_post_id) { $wpdb->query($wpdb->prepare("UPDATE " . GEODIR_REVIEW_TABLE . " SET post_id=%d WHERE comment_id=%d", $master_post_id, $master_comment_id)); geodir_update_postrating($master_post_id, $post_type); } $tr_comment_id = geodir_wpml_duplicate_comment_exists($tr_post_id, $master_comment_id); if (empty($tr_comment_id)) { return false; } $post_type = get_post_type($master_post_id); $post_table = $plugin_prefix . $post_type . '_detail'; $translated_post = $wpdb->get_row($wpdb->prepare("SELECT post_title, post_latitude, post_longitude, post_city, post_region, post_country FROM " . $post_table . " WHERE post_id = %d", $tr_post_id), ARRAY_A); if (empty($translated_post)) { return false; } $review['comment_id'] = $tr_comment_id; $review['post_id'] = $tr_post_id; $review['post_title'] = $translated_post['post_title']; $review['post_city'] = $translated_post['post_city']; $review['post_region'] = $translated_post['post_region']; $review['post_country'] = $translated_post['post_country']; $review['post_latitude'] = $translated_post['post_latitude']; $review['post_longitude'] = $translated_post['post_longitude']; if (isset($review['id'])) { unset($review['id']); } $tr_review_id = $wpdb->get_var($wpdb->prepare("SELECT id FROM " . GEODIR_REVIEW_TABLE . " WHERE comment_id=%d AND post_id=%d ORDER BY id ASC", $tr_comment_id, $tr_post_id)); if ($tr_review_id) { // update review $wpdb->update(GEODIR_REVIEW_TABLE, $review, array('id' => $tr_review_id)); } else { // insert review $wpdb->insert(GEODIR_REVIEW_TABLE, $review); $tr_review_id = $wpdb->insert_id; } if ($tr_post_id) { geodir_update_postrating($tr_post_id, $post_type); if (defined('GEODIRREVIEWRATING_VERSION') && get_option('geodir_reviewrating_enable_review') && $sitepress->get_setting('sync_comments_on_duplicates')) { $wpdb->query($wpdb->prepare("DELETE FROM " . GEODIR_COMMENTS_REVIEWS_TABLE . " WHERE comment_id = %d", array($tr_comment_id))); $likes = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . GEODIR_COMMENTS_REVIEWS_TABLE . " WHERE comment_id=%d ORDER BY like_date ASC", $master_comment_id, $tr_post_id), ARRAY_A); if (!empty($likes)) { foreach ($likes as $like) { unset($like['like_id']); $like['comment_id'] = $tr_comment_id; $wpdb->insert(GEODIR_COMMENTS_REVIEWS_TABLE, $like); } } } } return $tr_review_id; }