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.
@@ -16,8 +16,8 @@ class ActionScheduler_wpCommentLogger extends ActionScheduler_Logger {
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 );
@@ -35,18 +35,19 @@ public function log( $action_id, $message, DateTime $date = NULL ) {
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
/**
@@ -58,7 +59,8 @@ protected function create_wp_comment( $action_id, $message, DateTime $date ) {
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
@@ -76,23 +78,30 @@ public function get_entry( $entry_id ) {
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
@@ -105,20 +114,18 @@ 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.
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
@@ -131,7 +138,7 @@ public function filter_comment_queries( $query ) {
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 ;
@@ -192,17 +199,21 @@ protected function get_comment_count() {
192
199
$ stats = get_transient ( 'as_comment_count ' );
193
200
194
201
if ( ! $ stats ) {
195
- $ stats = array ();
196
-
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
+ $ 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
+ );
202
213
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 ' ] ] ) ) {
@@ -258,14 +269,14 @@ public function init() {
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.
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
}
0 commit comments