function host_review_submit($atts) { global $post; //$ip_ban = rah_check_rate_limit(); $ip_ban = false; if (has_user_reviewed_host($post->ID) && !isset($_POST['existing_post_id'])) { ?> We understand you are excited to give your host feedback, but you've already submitted a review for this host.<br /> If you need to make changes, please wait a few minutes and <a href="<?php the_permalink(); ?> edit">edit your review here</a>. <?php } elseif (is_user_logged_in() && !$ip_ban) { global $current_user; get_currentuserinfo(); // Do some minor form validation to make sure there is content if (isset($_POST['title'])) { $title = $_POST['title']; } else { wp_die('Please enter a title'); } $star_ratings = $_POST['star_ratings']; $post_content = isset($_POST['comments']) ? sanitize_text_field($_POST['comments']) : ''; $xpost = isset($_POST['xpost']) ? 'yes' : 'no'; $reinvoices = isset($_POST['reinvoices']) ? $_POST['reinvoices'] : 'na'; $no_issues = isset($_POST['issues_na']) ? $_POST['issues_na'] : false; // Add the content of the form to $post as an array $review = array('post_title' => sanitize_text_field($title), 'post_status' => 'pending', 'post_type' => 'reviews', 'post_content' => $post_content, 'comment_status' => 'open', 'ping_status' => 'closed', 'post_parent' => $post->ID); if (isset($_POST['existing_post_id'])) { $id = $_POST['existing_post_id']; $review['ID'] = $id; wp_update_post($review); } else { $id = wp_insert_post($review); } if (!empty($no_issues)) { $star_ratings['issue_resolution_rating'] = 0; } // Set the Host to be associated with the group update_post_meta($id, '_review_star_ratings', $star_ratings); update_post_meta($id, '_review_xpost', $xpost); update_post_meta($id, '_review_reinvoices', $reinvoices); update_post_meta($id, '_review_issues_na', $no_issues); if (!empty($current_user->user_email)) { $message = 'Hi ' . $current_user->user_firstname . ',' . "\n"; $message .= 'We\'ve recieved your review for ' . get_the_title($post->ID) . '.' . "\n"; $message .= 'It will be reviewed soon, and if approved you will be notified via email.'; $message .= "\n\n"; $message .= 'Thanks,' . "\n"; $message .= 'The Host Reviews Board Team'; wp_mail($current_user->user_email, 'Host Review Recieved', $message); } // Tell the Admins $edit_url = admin_url('post.php?post=' . $id . '&action=edit&post_type=review'); $admin_message = 'A new review has been submitted for approval on Host Reviews Board' . "\n\n"; $admin_message .= 'Please login and <a href="' . $edit_url . '"" target="_blank">moderate this review</a>'; wp_mail('*****@*****.**', 'New Review to Moderate', $admin_message); ?> <script>ga('send', 'event', { eventCategory: 'review', eventAction: 'submitted'});</script> <h4>Thanks for your review! We will look it over and, if approved, it will be published. If we see any issues, we'll let you know.</h4> <?php } else { ?> <h4>Slow down there!</h4><?php } }
function widget($args, $instance) { global $post; if (!is_object($post) || $post->post_type !== 'hosts' || !is_single()) { return; } $parent = get_post_ancestors($post); if ($parent) { $group_url = get_permalink($parent[0]); $group_name = get_the_title($parent[0]); $group_image = get_post_meta($parent[0], '_rah_group_fb_icon', true); } $group_types = get_the_terms($post->ID, 'type'); $types = implode(', ', wp_list_pluck($group_types, 'name')); $review_count = get_post_meta($post->ID, '_host_review_count', true); $host_location = get_post_meta($post->ID, '_user_postal_code', true); $location_string = ''; if (!empty($host_location)) { $city = rah_get_postal_city($host_location); $state = rah_get_postal_state($host_location); if (!empty($city)) { $location_string .= $city . ', '; } $location_string .= $state; } ?> <div class="host-widet-wraper"> <a href="<?php echo get_permalink($post->ID); ?> "> <div class="review-avatar"> <?php echo get_avatar(get_user_id_from_host_id($post->ID)); ?> </div> </a> <header class="entry-header"> <?php if (get_the_time(get_option('date_format'))) { ?> <h1 class="entry-title"><a href="<?php echo get_permalink($post->ID); ?> "> <?php the_title(); ?> </a></h1> <!-- .entry-title --> <div class="widget-host-type"><span class="dashicons dashicons-cart"></span><?php echo $types; ?> </div> <?php if (!empty($location_string)) { ?> <div class="widget-host-location"><span class="dashicons dashicons-location-alt"></span><?php echo $location_string; ?> </div> <?php } ?> <div class="entry-meta clearfix"> <div class="">Joined On: <?php the_time(get_option('date_format')); ?> </div> <?php if (isset($group_name)) { ?> <div class="group"><?php if ($group_image) { ?> <img src="<?php echo $group_image; ?> " /> <?php } ?> <a href="<?php echo $group_url; ?> " title-"<?php echo esc_attr($group_name); ?> "> <?php echo $group_name; ?> </a></div> <?php } ?> </div> <div class="widget-ratings-wrapper"> <?php echo rah_generate_stars(get_post_meta($post->ID, '_host_rating', true)); ?> <br /> <?php printf(_n('%d Review', '%d Reviews', $review_count, 'interface'), $review_count); ?> </div> <?php if (!user_is_host($post->ID)) { ?> <div class="widget-review-button"> <?php if (is_user_logged_in() && has_user_reviewed_host($post->ID)) { ?> <a href="<?php echo get_permalink($post->ID); ?> edit"><input type="button" value="Update Your Review" /></a> <?php } else { ?> <a href="<?php echo get_permalink($post->ID); ?> new"><input type="button" value="Review This Host" /></a> <?php } ?> </div> <?php } ?> <!-- .entry-meta --> </header> <!-- .entry-header --> <?php } ?> </header> </div> <?php }