PluginProbe
Image Optimizer – Compress Images and Convert to WebP or AVIF / trunk
Image Optimizer – Compress Images and Convert to WebP or AVIF vtrunk
1.7.7 1.7.6 1.7.5 1.7.4 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.3.0 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 All 33 releases
← All changes | vendor/woocommerce/action-scheduler/classes/data-stores/ActionScheduler_wpCommentLogger.php +52 -41 1.5.4 → trunk View file →
@@ -4,21 +4,21 @@
4 4 * Class ActionScheduler_wpCommentLogger
5 5 */
6 6 class ActionScheduler_wpCommentLogger extends ActionScheduler_Logger {
7 7 const AGENT = 'ActionScheduler';
8 - const TYPE = 'action_log';
8 + const TYPE = 'action_log';
9 9
10 10 /**
11 11 * Create log entry.
12 12 *
13 - * @param string $action_id Action ID.
14 - * @param string $message Action log's message.
15 - * @param DateTime $date Action log's timestamp.
13 + * @param string $action_id Action ID.
14 + * @param string $message Action log's message.
15 + * @param DateTime|null $date Action log's timestamp.
16 16 *
17 17 * @return string The log entry ID
18 18 */
19 - public function log( $action_id, $message, DateTime $date = NULL ) {
20 - if ( empty($date) ) {
19 + public function log( $action_id, $message, ?DateTime $date = null ) {
20 + if ( empty( $date ) ) {
21 21 $date = as_get_datetime_object();
22 22 } else {
23 23 $date = as_get_datetime_object( clone $date );
24 24 }
@@ -34,20 +34,21 @@
34 34 * @param DateTime $date Action log entry's timestamp.
35 35 */
36 36 protected function create_wp_comment( $action_id, $message, DateTime $date ) {
37 37
38 - $comment_date_gmt = $date->format('Y-m-d H:i:s');
38 + $comment_date_gmt = $date->format( 'Y-m-d H:i:s' );
39 39 ActionScheduler_TimezoneHelper::set_local_timezone( $date );
40 40 $comment_data = array(
41 - 'comment_post_ID' => $action_id,
42 - 'comment_date' => $date->format('Y-m-d H:i:s'),
41 + 'comment_post_ID' => $action_id,
42 + 'comment_date' => $date->format( 'Y-m-d H:i:s' ),
43 43 'comment_date_gmt' => $comment_date_gmt,
44 - 'comment_author' => self::AGENT,
45 - 'comment_content' => $message,
46 - 'comment_agent' => self::AGENT,
47 - 'comment_type' => self::TYPE,
44 + 'comment_author' => self::AGENT,
45 + 'comment_content' => $message,
46 + 'comment_agent' => self::AGENT,
47 + 'comment_type' => self::TYPE,
48 48 );
49 - return wp_insert_comment($comment_data);
49 +
50 + return wp_insert_comment( $comment_data );
50 51 }
51 52
52 53 /**
53 54 * Get single log entry for action.
@@ -57,9 +58,10 @@
57 58 * @return ActionScheduler_LogEntry
58 59 */
59 60 public function get_entry( $entry_id ) {
60 61 $comment = $this->get_comment( $entry_id );
61 - if ( empty($comment) || $comment->comment_type != self::TYPE ) {
62 +
63 + if ( empty( $comment ) || self::TYPE !== $comment->comment_type ) {
62 64 return new ActionScheduler_NullLogEntry();
63 65 }
64 66
65 67 $date = as_get_datetime_object( $comment->comment_date_gmt );
@@ -75,25 +77,32 @@
75 77 * @return ActionScheduler_LogEntry[]
76 78 */
77 79 public function get_logs( $action_id ) {
78 80 $status = 'all';
79 - if ( get_post_status($action_id) == 'trash' ) {
81 + $logs = array();
82 +
83 + if ( get_post_status( $action_id ) === 'trash' ) {
80 84 $status = 'post-trashed';
81 85 }
82 - $comments = get_comments(array(
83 - 'post_id' => $action_id,
84 - 'orderby' => 'comment_date_gmt',
85 - 'order' => 'ASC',
86 - 'type' => self::TYPE,
87 - 'status' => $status,
88 - ));
89 - $logs = array();
86 +
87 + $comments = get_comments(
88 + array(
89 + 'post_id' => $action_id,
90 + 'orderby' => 'comment_date_gmt',
91 + 'order' => 'ASC',
92 + 'type' => self::TYPE,
93 + 'status' => $status,
94 + )
95 + );
96 +
90 97 foreach ( $comments as $c ) {
91 98 $entry = $this->get_entry( $c );
92 - if ( !empty($entry) ) {
99 +
100 + if ( ! empty( $entry ) ) {
93 101 $logs[] = $entry;
94 102 }
95 103 }
104 +
96 105 return $logs;
97 106 }
98 107
99 108 /**
@@ -104,10 +113,8 @@
104 113 protected function get_comment( $comment_id ) {
105 114 return get_comment( $comment_id );
106 115 }
107 116
108 -
109 -
110 117 /**
111 118 * Filter comment queries.
112 119 *
113 120 * @param WP_Comment_Query $query Comment query object.
@@ -112,14 +119,14 @@
112 119 *
113 120 * @param WP_Comment_Query $query Comment query object.
114 121 */
115 122 public function filter_comment_queries( $query ) {
116 - foreach ( array('ID', 'parent', 'post_author', 'post_name', 'post_parent', 'type', 'post_type', 'post_id', 'post_ID') as $key ) {
117 - if ( !empty($query->query_vars[$key]) ) {
123 + foreach ( array( 'ID', 'parent', 'post_author', 'post_name', 'post_parent', 'type', 'post_type', 'post_id', 'post_ID' ) as $key ) {
124 + if ( ! empty( $query->query_vars[ $key ] ) ) {
118 125 return; // don't slow down queries that wouldn't include action_log comments anyway.
119 126 }
120 127 }
121 - $query->query_vars['action_log_filter'] = TRUE;
128 + $query->query_vars['action_log_filter'] = true;
122 129 add_filter( 'comments_clauses', array( $this, 'filter_comment_query_clauses' ), 10, 2 );
123 130 }
124 131
125 132 /**
@@ -130,9 +137,9 @@
130 137 *
131 138 * @return array
132 139 */
133 140 public function filter_comment_query_clauses( $clauses, $query ) {
134 - if ( !empty($query->query_vars['action_log_filter']) ) {
141 + if ( ! empty( $query->query_vars['action_log_filter'] ) ) {
135 142 $clauses['where'] .= $this->get_where_clause();
136 143 }
137 144 return $clauses;
138 145 }
@@ -191,19 +198,23 @@
191 198
192 199 $stats = get_transient( 'as_comment_count' );
193 200
194 201 if ( ! $stats ) {
195 - $stats = array();
202 + $stats = array();
203 + $count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} WHERE comment_type NOT IN('order_note','action_log') GROUP BY comment_approved", ARRAY_A );
204 + $total = 0;
205 + $stats = array();
206 + $approved = array(
207 + '0' => 'moderated',
208 + '1' => 'approved',
209 + 'spam' => 'spam',
210 + 'trash' => 'trash',
211 + 'post-trashed' => 'post-trashed',
212 + );
196 213
197 - $count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} WHERE comment_type NOT IN('order_note','action_log') GROUP BY comment_approved", ARRAY_A );
198 -
199 - $total = 0;
200 - $stats = array();
201 - $approved = array( '0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'trash' => 'trash', 'post-trashed' => 'post-trashed' );
202 -
203 214 foreach ( (array) $count as $row ) {
204 215 // Don't count post-trashed toward totals.
205 - if ( 'post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved'] ) {
216 + if ( 'post-trashed' !== $row['comment_approved'] && 'trash' !== $row['comment_approved'] ) {
206 217 $total += $row['num_comments'];
207 218 }
208 219 if ( isset( $approved[ $row['comment_approved'] ] ) ) {
209 220 $stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments'];
@@ -257,9 +268,9 @@
257 268 /**
258 269 * Defer comment counting.
259 270 */
260 271 public function disable_comment_counting() {
261 - wp_defer_comment_counting(true);
272 + wp_defer_comment_counting( true );
262 273 }
263 274
264 275 /**
265 276 * Enable comment counting.
@@ -264,8 +275,8 @@
264 275 /**
265 276 * Enable comment counting.
266 277 */
267 278 public function enable_comment_counting() {
268 - wp_defer_comment_counting(false);
279 + wp_defer_comment_counting( false );
269 280 }
270 281
271 282 }