/var/www/html_de/wp-content/plugins/woocommerce/src/Internal/Admin/ProductReviews/ReviewsUtil.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php

namespace Automattic\WooCommerce\Internal\Admin\ProductReviews;

/**
 * A utility class for handling comments that are product reviews.
 */
class ReviewsUtil {

    
/**
     * Modifies the moderation URLs in the email notifications for product reviews.
     *
     * @param string $message The email notification message.
     * @param int    $comment_id The comment ID.
     * @return string The modified email notification message.
     */
    
public static function modify_product_review_moderation_urls$message$comment_id ) {
        
$comment get_comment$comment_id );

        
// Only modify URLs for product reviews.
        
if ( ! $comment || get_post_type$comment->comment_post_ID ) !== 'product' ) {
            return 
$message;
        }

        
// Replace the WordPress comment moderation URLs with WooCommerce product review URLs.
        
$product_reviews_url admin_url'edit.php?post_type=product&page=product-reviews' );

        
// Replace the moderation panel URL (this is the "show all reviews pending" link).
        
$message str_replace(
            
admin_url'edit-comments.php?comment_status=moderated#wpbody-content' ),
            
$product_reviews_url '&comment_status=moderated',
            
$message
        
);

        return 
$message;
    }

    
/**
     * Removes product reviews from the edit-comments page to fix the "Mine" tab counter.
     *
     * @param array|mixed       $clauses A compacted array of comment query clauses.
     * @param \WP_Comment_Query $comment_query The WP_Comment_Query instance being filtered.
     *
     * @return array|mixed
     */
    
public static function comments_clauses_without_product_reviews$clauses$comment_query ) {
        global 
$wpdb;

        if ( ! empty( 
$comment_query->query_vars['post_type'] ) ) {
            
$post_type $comment_query->query_vars['post_type'];
            if ( ! 
is_array$post_type ) ) {
                
$post_type explode','$post_type );
            }
            if ( 
in_array'product'$post_typetrue ) ) {
                return 
$clauses;
            }
        }

        
/**
         * Any comment queries with these values are likely to be custom handling where we don't want to change default behavior.
         * This may change for the `type` query vars in the future if we break out review replies as their own type.
         */
        
foreach ( array( 'ID''parent''parent__in''post_author__in''post_author''post_name''type''type__in''type__not_in''post_type__in''comment__in''comment__not_in' ) as $arg ) {
            if ( ! empty( 
$comment_query->query_vars$arg ] ) ) {
                return 
$clauses;
            }
        }

        if ( ! empty( 
$comment_query->query_vars['post_id'] ) && absint$comment_query->query_vars['post_id'] ) > ) {
            if ( 
'product' === get_post_typeabsint$comment_query->query_vars['post_id'] ) ) ) {
                return 
$clauses;
            }
        }

        if ( ! empty( 
$comment_query->query_vars['post__in'] ) ) {
            
$post_ids wp_parse_id_list$comment_query->query_vars['post__in'] );
            
_prime_post_caches$post_idsfalsefalse );
            foreach ( 
$post_ids as $post_id ) {
                if ( 
'product' === get_post_type$post_id ) ) {
                    return 
$clauses;
                }
            }
        }

        
$clauses['join']  .= " LEFT JOIN {$wpdb->posts} AS wp_posts_to_exclude_reviews ON comment_post_ID = wp_posts_to_exclude_reviews.ID ";
        
$clauses['where'] .= ( trim$clauses['where'] ) ? ' AND ' '' ) . " wp_posts_to_exclude_reviews.post_type NOT IN ('product') ";

        return 
$clauses;
    }
}