PluginProbe
Stream – Activity Log & Audit Trail / 3.9.0
Stream – Activity Log & Audit Trail v3.9.0
4.4.0 4.3.0 4.2.2 4.2.1 trunk 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.1 3.1.1 3.10.0 3.2.0 3.2.1 3.2.2 3.2.3 All 50 releases
← All changes | connectors/class-connector-comments.php +68 -37 3.2.13.9.0 View file →
@@ -1,7 +1,16 @@
1 1 <?php
2 +/**
3 + * Connector for Comments
4 + *
5 + * @package WP_Stream
6 + */
7 +
2 8 namespace WP_Stream;
3 9
10 +/**
11 + * Class - Connector_Comments
12 + */
4 13 class Connector_Comments extends Connector {
5 14 /**
6 15 * Connector slug
7 16 *
@@ -96,9 +105,9 @@
96 105
97 106 /**
98 107 * Return the comment type label for a given comment ID
99 108 *
100 - * @param int $comment_id ID of the comment
109 + * @param int $comment_id ID of the comment.
101 110 *
102 111 * @return string The comment type label
103 112 */
104 113 public function get_comment_type_label( $comment_id ) {
@@ -119,16 +128,17 @@
119 128 * Add action links to Stream drop row in admin list screen
120 129 *
121 130 * @filter wp_stream_action_links_{connector}
122 131 *
123 - * @param array $links Previous links registered
124 - * @param object $record Stream record
132 + * @param array $links Previous links registered.
133 + * @param object $record Stream record.
125 134 *
126 135 * @return array Action links
127 136 */
128 137 public function action_links( $links, $record ) {
129 138 if ( $record->object_id ) {
130 - if ( $comment = get_comment( $record->object_id ) ) {
139 + $comment = get_comment( $record->object_id );
140 + if ( $comment ) {
131 141 $approve_nonce = wp_create_nonce( "approve-comment_$comment->comment_ID" );
132 142
133 143 $links[ esc_html__( 'Edit', 'stream' ) ] = admin_url( "comment.php?action=editcomment&c=$comment->comment_ID" );
134 144
@@ -161,10 +171,10 @@
161 171 * This also takes into consideration whether or not the blog requires only
162 172 * name and e-mail or that users be logged in to comment. In either case it
163 173 * will try to see if the e-mail provided does belong to a registered user.
164 174 *
165 - * @param object|int $comment A comment object or comment ID
166 - * @param string $field What field you want to return
175 + * @param object|int $comment A comment object or comment ID.
176 + * @param string $field What field you want to return.
167 177 *
168 178 * @return int|string $output User ID or user display name
169 179 */
170 180 public function get_comment_author( $comment, $field = 'id' ) {
@@ -203,10 +213,10 @@
203 213 * Tracks comment flood blocks
204 214 *
205 215 * @action comment_flood_trigger
206 216 *
207 - * @param string $time_lastcomment
208 - * @param string $time_newcomment
217 + * @param string $time_lastcomment Time of last comment before block.
218 + * @param string $time_newcomment Time of first comment after block.
209 219 */
210 220 public function callback_comment_flood_trigger( $time_lastcomment, $time_newcomment ) {
211 221 $options = wp_stream_get_instance()->settings->options;
212 222 $flood_tracking = isset( $options['advanced_comment_flood_tracking'] ) ? $options['advanced_comment_flood_tracking'] : false;
@@ -225,8 +235,9 @@
225 235 $user_name = esc_html__( 'a logged out user', 'stream' );
226 236 }
227 237
228 238 $this->log(
239 + /* translators: %s: a username (e.g. "administrator") */
229 240 __( 'Comment flooding by %s detected and prevented', 'stream' ),
230 241 compact( 'user_name', 'user_id', 'time_lastcomment', 'time_newcomment' ),
231 242 null,
232 243 'comments',
@@ -238,10 +249,10 @@
238 249 * Tracks comment creation
239 250 *
240 251 * @action wp_insert_comment
241 252 *
242 - * @param int $comment_id
243 - * @param object $comment
253 + * @param int $comment_id Comment ID.
254 + * @param WP_Comment $comment Comment object.
244 255 */
245 256 public function callback_wp_insert_comment( $comment_id, $comment ) {
246 257 if ( in_array( $comment->comment_type, $this->get_ignored_comment_types(), true ) ) {
247 258 return;
@@ -250,13 +261,14 @@
250 261 $user_id = $this->get_comment_author( $comment, 'id' );
251 262 $user_name = $this->get_comment_author( $comment, 'name' );
252 263 $post_id = $comment->comment_post_ID;
253 264 $post_type = get_post_type( $post_id );
254 - $post_title = ( $post = get_post( $post_id ) ) ? "\"$post->post_title\"" : esc_html__( 'a post', 'stream' );
265 + $post = get_post( $post_id );
266 + $post_title = $post ? "\"$post->post_title\"" : esc_html__( 'a post', 'stream' );
255 267 $comment_status = ( 1 === $comment->comment_approved ) ? esc_html__( 'approved automatically', 'stream' ) : esc_html__( 'pending approval', 'stream' );
256 268 $is_spam = false;
257 269
258 - // Auto-marked spam comments
270 + // Auto-marked spam comments.
259 271 $options = wp_stream_get_instance()->settings->options;
260 272 $ak_tracking = isset( $options['advanced_akismet_tracking'] ) ? $options['advanced_akismet_tracking'] : false;
261 273
262 274 if ( class_exists( 'Akismet' ) && $ak_tracking && \Akismet::matches_last_comment( $comment ) ) {
@@ -266,21 +278,21 @@
266 278 $comment_status = esc_html__( 'automatically marked as spam by Akismet', 'stream' );
267 279 }
268 280 }
269 281
270 - $comment_type = mb_strtolower( $this->get_comment_type_label( $comment_id ) );
282 + $comment_type = mb_strtolower( $this->get_comment_type_label( $comment_id ) );
271 283
272 284 if ( $comment->comment_parent ) {
273 - $parent_user_id = get_comment_author( $comment->comment_parent, 'id' );
274 - $parent_user_name = get_comment_author( $comment->comment_parent, 'name' );
285 + $parent_user_name = get_comment_author( $comment->comment_parent );
275 286
276 287 $this->log(
288 + /* translators: %1$s: a parent comment's author, %2$s: a comment author, %3$s: a post title, %4$s: a comment status, %5$s: a comment type */
277 289 _x(
278 290 'Reply to %1$s\'s %5$s by %2$s on %3$s %4$s',
279 291 "1: Parent comment's author, 2: Comment author, 3: Post title, 4: Comment status, 5: Comment type",
280 292 'stream'
281 293 ),
282 - compact( 'parent_user_name', 'user_name', 'post_title', 'comment_status', 'comment_type', 'post_id', 'parent_user_id' ),
294 + compact( 'parent_user_name', 'user_name', 'post_title', 'comment_status', 'comment_type', 'post_id' ),
283 295 $comment_id,
284 296 $post_type,
285 297 'replied',
286 298 $user_id
@@ -286,8 +298,9 @@
286 298 $user_id
287 299 );
288 300 } else {
289 301 $this->log(
302 + /* translators: %1$s: a comment author, %2$s: a post title, %3$s: a comment status, %4$s: and a comment type */
290 303 _x(
291 304 'New %4$s by %1$s on %2$s %3$s',
292 305 '1: Comment author, 2: Post title 3: Comment status, 4: Comment type',
293 306 'stream'
@@ -305,9 +318,9 @@
305 318 * Tracks comment updates
306 319 *
307 320 * @action edit_comment
308 321 *
309 - * @param int $comment_id
322 + * @param int $comment_id Comment ID.
310 323 */
311 324 public function callback_edit_comment( $comment_id ) {
312 325 $comment = get_comment( $comment_id );
313 326
@@ -318,12 +331,14 @@
318 331 $user_id = $this->get_comment_author( $comment, 'id' );
319 332 $user_name = $this->get_comment_author( $comment, 'name' );
320 333 $post_id = $comment->comment_post_ID;
321 334 $post_type = get_post_type( $post_id );
322 - $post_title = ( $post = get_post( $post_id ) ) ? "\"$post->post_title\"" : esc_html__( 'a post', 'stream' );
335 + $post = get_post( $post_id );
336 + $post_title = $post ? "\"$post->post_title\"" : esc_html__( 'a post', 'stream' );
323 337 $comment_type = mb_strtolower( $this->get_comment_type_label( $comment_id ) );
324 338
325 339 $this->log(
340 + /* translators: %1$s: a comment author, %2$s: a post title, %3$s: a comment type */
326 341 _x(
327 342 '%1$s\'s %3$s on %2$s edited',
328 343 '1: Comment author, 2: Post title, 3: Comment type',
329 344 'stream'
@@ -339,9 +354,9 @@
339 354 * Catch the post ID during deletion
340 355 *
341 356 * @action before_delete_post
342 357 *
343 - * @param int $post_id
358 + * @param int $post_id Post ID.
344 359 */
345 360 public function callback_before_delete_post( $post_id ) {
346 361 if ( wp_is_post_revision( $post_id ) ) {
347 362 return;
@@ -354,9 +369,9 @@
354 369 * Reset the post ID after deletion
355 370 *
356 371 * @action deleted_post
357 372 *
358 - * @param int $post_id
373 + * @param int $post_id Post ID.
359 374 */
360 375 public function callback_deleted_post( $post_id ) {
361 376 if ( wp_is_post_revision( $post_id ) ) {
362 377 return;
@@ -369,9 +384,9 @@
369 384 * Tracks comment delete
370 385 *
371 386 * @action delete_comment
372 387 *
373 - * @param int $comment_id
388 + * @param int $comment_id Comment ID.
374 389 */
375 390 public function callback_delete_comment( $comment_id ) {
376 391 $comment = get_comment( $comment_id );
377 392
@@ -382,9 +397,10 @@
382 397 $user_id = $this->get_comment_author( $comment, 'id' );
383 398 $user_name = $this->get_comment_author( $comment, 'name' );
384 399 $post_id = absint( $comment->comment_post_ID );
385 400 $post_type = get_post_type( $post_id );
386 - $post_title = ( $post = get_post( $post_id ) ) ? "\"$post->post_title\"" : esc_html__( 'a post', 'stream' );
401 + $post = get_post( $post_id );
402 + $post_title = $post ? "\"$post->post_title\"" : esc_html__( 'a post', 'stream' );
387 403 $comment_type = mb_strtolower( $this->get_comment_type_label( $comment_id ) );
388 404
389 405 if ( $this->delete_post === $post_id ) {
390 406 return;
@@ -390,8 +406,9 @@
390 406 return;
391 407 }
392 408
393 409 $this->log(
410 + /* translators: %1$s: a comment author, %2$s: a post title, %3$s: a comment type */
394 411 _x(
395 412 '%1$s\'s %3$s on %2$s deleted permanently',
396 413 '1: Comment author, 2: Post title, 3: Comment type',
397 414 'stream'
@@ -407,9 +424,9 @@
407 424 * Tracks comment trashing
408 425 *
409 426 * @action trash_comment
410 427 *
411 - * @param int $comment_id
428 + * @param int $comment_id Comment ID.
412 429 */
413 430 public function callback_trash_comment( $comment_id ) {
414 431 $comment = get_comment( $comment_id );
415 432
@@ -420,12 +437,14 @@
420 437 $user_id = $this->get_comment_author( $comment, 'id' );
421 438 $user_name = $this->get_comment_author( $comment, 'name' );
422 439 $post_id = $comment->comment_post_ID;
423 440 $post_type = get_post_type( $post_id );
424 - $post_title = ( $post = get_post( $post_id ) ) ? "\"$post->post_title\"" : esc_html__( 'a post', 'stream' );
441 + $post = get_post( $post_id );
442 + $post_title = $post ? "\"$post->post_title\"" : esc_html__( 'a post', 'stream' );
425 443 $comment_type = mb_strtolower( $this->get_comment_type_label( $comment_id ) );
426 444
427 445 $this->log(
446 + /* translators: %1$s: a comment author, %2$s a post title, %3$s a comment type */
428 447 _x(
429 448 '%1$s\'s %3$s on %2$s trashed',
430 449 '1: Comment author, 2: Post title, 3: Comment type',
431 450 'stream'
@@ -441,9 +460,9 @@
441 460 * Tracks comment trashing
442 461 *
443 462 * @action untrash_comment
444 463 *
445 - * @param int $comment_id
464 + * @param int $comment_id Comment ID.
446 465 */
447 466 public function callback_untrash_comment( $comment_id ) {
448 467 $comment = get_comment( $comment_id );
449 468
@@ -454,12 +473,14 @@
454 473 $user_id = $this->get_comment_author( $comment, 'id' );
455 474 $user_name = $this->get_comment_author( $comment, 'name' );
456 475 $post_id = $comment->comment_post_ID;
457 476 $post_type = get_post_type( $post_id );
458 - $post_title = ( $post = get_post( $post_id ) ) ? "\"$post->post_title\"" : esc_html__( 'a post', 'stream' );
477 + $post = get_post( $post_id );
478 + $post_title = $post ? "\"$post->post_title\"" : esc_html__( 'a post', 'stream' );
459 479 $comment_type = mb_strtolower( $this->get_comment_type_label( $comment_id ) );
460 480
461 481 $this->log(
482 + /* translators: %1$s: a comment author, %2$s: a post title, %3$s: a comment type */
462 483 _x(
463 484 '%1$s\'s %3$s on %2$s restored',
464 485 '1: Comment author, 2: Post title, 3: Comment type',
465 486 'stream'
@@ -475,9 +496,9 @@
475 496 * Tracks comment marking as spam
476 497 *
477 498 * @action spam_comment
478 499 *
479 - * @param int $comment_id
500 + * @param int $comment_id Comment ID.
480 501 */
481 502 public function callback_spam_comment( $comment_id ) {
482 503 $comment = get_comment( $comment_id );
483 504
@@ -488,12 +509,14 @@
488 509 $user_id = $this->get_comment_author( $comment, 'id' );
489 510 $user_name = $this->get_comment_author( $comment, 'name' );
490 511 $post_id = $comment->comment_post_ID;
491 512 $post_type = get_post_type( $post_id );
492 - $post_title = ( $post = get_post( $post_id ) ) ? "\"$post->post_title\"" : esc_html__( 'a post', 'stream' );
513 + $post = get_post( $post_id );
514 + $post_title = $post ? "\"$post->post_title\"" : esc_html__( 'a post', 'stream' );
493 515 $comment_type = mb_strtolower( $this->get_comment_type_label( $comment_id ) );
494 516
495 517 $this->log(
518 + /* translators: %1$s: a comment author, %2$s: a post title, %3$s: a comment type */
496 519 _x(
497 520 '%1$s\'s %3$s on %2$s marked as spam',
498 521 '1: Comment author, 2: Post title, 3: Comment type',
499 522 'stream'
@@ -509,9 +532,9 @@
509 532 * Tracks comment unmarking as spam
510 533 *
511 534 * @action unspam_comment
512 535 *
513 - * @param int $comment_id
536 + * @param int $comment_id Comment ID.
514 537 */
515 538 public function callback_unspam_comment( $comment_id ) {
516 539 $comment = get_comment( $comment_id );
517 540
@@ -522,12 +545,14 @@
522 545 $user_id = $this->get_comment_author( $comment, 'id' );
523 546 $user_name = $this->get_comment_author( $comment, 'name' );
524 547 $post_id = $comment->comment_post_ID;
525 548 $post_type = get_post_type( $post_id );
526 - $post_title = ( $post = get_post( $post_id ) ) ? "\"$post->post_title\"" : esc_html__( 'a post', 'stream' );
549 + $post = get_post( $post_id );
550 + $post_title = $post ? "\"$post->post_title\"" : esc_html__( 'a post', 'stream' );
527 551 $comment_type = mb_strtolower( $this->get_comment_type_label( $comment_id ) );
528 552
529 553 $this->log(
554 + /* translators: %1$s: a comment author, %2$s: a post title, %3$s: a comment type */
530 555 _x(
531 556 '%1$s\'s %3$s on %2$s unmarked as spam',
532 557 '1: Comment author, 2: Post title, 3: Comment type',
533 558 'stream'
@@ -543,11 +568,11 @@
543 568 * Track comment status transition
544 569 *
545 570 * @action transition_comment_status
546 571 *
547 - * @param string $new_status
548 - * @param string $old_status
549 - * @param object $comment
572 + * @param string $new_status New comment status.
573 + * @param string $old_status Old comment status.
574 + * @param WP_Comment $comment Comment object.
550 575 */
551 576 public function callback_transition_comment_status( $new_status, $old_status, $comment ) {
552 577 if ( in_array( $comment->comment_type, $this->get_ignored_comment_types(), true ) ) {
553 578 return;
@@ -560,12 +585,14 @@
560 585 $user_id = $this->get_comment_author( $comment, 'id' );
561 586 $user_name = $this->get_comment_author( $comment, 'name' );
562 587 $post_id = $comment->comment_post_ID;
563 588 $post_type = get_post_type( $post_id );
564 - $post_title = ( $post = get_post( $post_id ) ) ? "\"$post->post_title\"" : esc_html__( 'a post', 'stream' );
589 + $post = get_post( $post_id );
590 + $post_title = $post ? "\"$post->post_title\"" : esc_html__( 'a post', 'stream' );
565 591 $comment_type = get_comment_type( $comment->comment_ID );
566 592
567 593 $this->log(
594 + /* translators: %1$s: a comment author, %2$s: a post title, %3$s: a comment type */
568 595 _x(
569 596 '%1$s\'s %3$s %2$s',
570 597 'Comment status transition. 1: Comment author, 2: Post title, 3: Comment type',
571 598 'stream'
@@ -581,13 +608,15 @@
581 608 * Track attempts to add duplicate comments
582 609 *
583 610 * @action comment_duplicate_trigger
584 611 *
585 - * @param array $comment_data
612 + * @param array $comment_data Comment data.
586 613 */
587 614 public function callback_comment_duplicate_trigger( $comment_data ) {
588 615 global $wpdb;
589 - unset( $comment_data );
616 + if ( ! empty( $wpdb->last_result ) ) {
617 + return;
618 + }
590 619
591 620 $comment_id = $wpdb->last_result[0]->comment_ID;
592 621 $comment = get_comment( $comment_id );
593 622
@@ -598,12 +627,14 @@
598 627 $user_id = $this->get_comment_author( $comment, 'id' );
599 628 $user_name = $this->get_comment_author( $comment, 'name' );
600 629 $post_id = $comment->comment_post_ID;
601 630 $post_type = get_post_type( $post_id );
602 - $post_title = ( $post = get_post( $post_id ) ) ? "\"$post->post_title\"" : esc_html__( 'a post', 'stream' );
631 + $post = get_post( $post_id );
632 + $post_title = $post ? "\"$post->post_title\"" : esc_html__( 'a post', 'stream' );
603 633 $comment_type = mb_strtolower( $this->get_comment_type_label( $comment_id ) );
604 634
605 635 $this->log(
636 + /* translators: %1$s: a comment author, %2$s: a post title, %3$s: a comment type */
606 637 _x(
607 638 'Duplicate %3$s by %1$s prevented on %2$s',
608 639 '1: Comment author, 2: Post title, 3: Comment type',
609 640 'stream'