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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
<?php // phpcs:ignoreFile
namespace AutomateWoo;
/** * @class Review * @since 3.0.0 */ class Review {
/** @var int */ private $comment_id = 0;
/** @var int */ private $user_id = 0;
/** @var string */ private $email;
/** @var int */ private $product_id = 0;
/** @var \WP_Comment */ private $comment;
/** @var string */ private $comment_status;
/** @var bool */ public $exists = false;
/** * @param \WP_Comment|int $comment */ public function __construct( $comment ) { if ( is_numeric( $comment ) ) { $comment = get_comment( $comment ); }
if ( ! $comment || 'review' !== $comment->comment_type || 'product' !== get_post_type( $comment->comment_post_ID ) ) { return; }
$this->exists = true; $this->comment = $comment; $this->comment_id = (int) $comment->comment_ID; $this->user_id = (int) $comment->user_id; $this->product_id = (int) $comment->comment_post_ID; $this->email = Clean::email( $comment->comment_author_email ); $this->comment_status = wp_get_comment_status( $comment ); }
/** * @return int */ public function get_id() { return $this->comment_id; }
/** * @return int */ public function get_product_id() { return $this->product_id; }
/** * @return int */ public function get_user_id() { return $this->user_id; }
/** * @return int */ public function get_email() { return $this->email; }
/** * @return string */ public function get_content() { return Clean::textarea( $this->comment->comment_content ); }
/** * @return int */ function get_rating() { return (int) get_comment_meta( $this->get_id(), 'rating', true ); }
/** * Get the customer who made the review. * * @since 4.5 * * @return Customer|bool */ public function get_customer() { return Customer_Factory::get_by_review( $this ); }
/** * @return string */ public function get_comment_status() { return $this->comment_status; }
/** * @return boolean */ public function is_approved() { return $this->comment_status === 'approved'; }
}
|