* * Do not edit or add to this file if you wish to upgrade WooCommerce Product Reviews Pro to newer * versions in the future. If you wish to customize WooCommerce Product Reviews Pro for your * needs please refer to http://docs.woothemes.com/document/woocommerce-product-reviews-pro/ for more information. * * @package WC-Product-Reviews-Pro/Templates * @author SkyVerge * @copyright Copyright (c) 2015, SkyVerge, Inc. * @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0 */ if (!defined('ABSPATH')) { exit; } // Exit if accessed directly global $product; $contribution = wc_product_reviews_pro_get_contribution($comment); $rating = $contribution->get_rating(); $title = $contribution->get_title(); $rating_enabled = $rating && get_option('woocommerce_enable_review_rating') == 'yes'; ?> <li itemprop="review" itemscope itemtype="http://schema.org/Review" <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?> "> <div id="comment-<?php comment_ID(); ?>
/** * Order comments (contributions) on frontend * * @since 1.0.0 * @param array $comments * @return array $comments */ public function order_comments($comments) { global $post; if ('product' == $post->post_type) { $orderby = get_option('wc_product_reviews_pro_contributions_orderby'); switch ($orderby) { // Order contributions by most helpful ratio // TODO: implement a better algorithm for determining usefulness case 'most_helpful': foreach ($comments as $key => $comment) { $contribution = wc_product_reviews_pro_get_contribution($comment); $comment->helpfulness_ratio = $contribution->get_helpfulness_ratio(); $comments[$key] = $comment; } usort($comments, array($this, 'compare_helpfulness_ratio')); break; // The comments template defaults to oldest first // The comments template defaults to oldest first case 'newest': $comments = array_reverse($comments); break; } } return $comments; }
/** * Output the attachment meta box HTML * * @since 1.0.0 */ public function contribution_attachment_meta_box() { global $comment; $contribution = wc_product_reviews_pro_get_contribution($comment); $attachment_url = $contribution->get_attachment_url(); $attachment_id = $contribution->get_attachment_id(); $image = wp_get_attachment_image($attachment_id, 'large'); $attachment_exists = $attachment_id && $image || $attachment_url; // Attachment controls if ($attachment_exists) { echo '<p>'; if ($attachment_url) { echo __('Source:', WC_Product_Reviews_Pro::TEXT_DOMAIN) . ' <a href="' . $attachment_url . '">' . $attachment_url . '</a>'; } else { if ($attachment_id) { echo '<a href="' . get_edit_post_link($attachment_id) . '">' . __('Edit attachment', WC_Product_Reviews_Pro::TEXT_DOMAIN) . '</a>'; } } echo ' | <a href="#" class="remove-attachment" data-comment-id="' . esc_attr($comment->comment_ID) . '">' . __('Remove attachment', WC_Product_Reviews_Pro::TEXT_DOMAIN) . '</a>'; echo '</p>'; // Display photo if ('photo' == $contribution->get_attachment_type()) { if ($attachment_url) { echo '<img alt="" src="' . esc_url($attachment_url) . '" />'; } else { if ($image) { echo $image; } } } // Embed video, or simply display a link if ('video' == $contribution->get_attachment_type() && $attachment_url) { $embed_code = wp_oembed_get($attachment_url); echo $embed_code ? $embed_code : '<p>' . sprintf('<a href="%s">%s</a>', $attachment_url, $attachment_url) . '</p>'; } } else { echo '<p>' . __('Attachment has been removed', WC_Product_Reviews_Pro::TEXT_DOMAIN) . '</p>'; } }
/** * Remove the contribution attachment * * @since 1.0.0 */ public function remove_contribution_attachment() { $this->verify_request($_POST['security'], 'wc-product-reviews-pro-admin'); // Bail out if contribution/comment ID is not provided if (!isset($_POST['comment_id']) || !$_POST['comment_id']) { wp_send_json_error(array('message' => __('Invalid request.', WC_Product_Reviews_Pro::TEXT_DOMAIN))); } // Get contribution $contribution = wc_product_reviews_pro_get_contribution($_POST['comment_id']); if (!$contribution) { wp_send_json_error(array('message' => __('Invalid request. Contribution not found.', WC_Product_Reviews_Pro::TEXT_DOMAIN))); } if ($contribution->has_attachment()) { $attachment_id = $contribution->get_attachment_id(); $attachment_url = $contribution->get_attachment_url(); if ($attachment_url) { delete_comment_meta($contribution->id, 'attachment_url'); } if ($attachment_id) { delete_comment_meta($contribution->id, 'attachment_id'); wp_delete_attachment($attachment_id); } wp_send_json_success(array('message' => __('Attachment successfully removed.', WC_Product_Reviews_Pro::TEXT_DOMAIN))); } }