| 1 |
<?php |
| 2 |
|
| 3 |
class Logtivity_Comment |
| 4 |
{ |
| 5 |
public function __construct() |
| 6 |
{ |
| 7 |
add_action('comment_post', [$this, 'commentCreated'], 10, 3); |
| 8 |
add_action( 'wp_set_comment_status', [$this, 'statusChanged'], 10, 2); |
| 9 |
add_action( 'unspam_comment', [$this, 'commentMarkedAsNotspam'], 10, 2); |
| 10 |
} |
| 11 |
|
| 12 |
public function commentCreated($comment_ID, $comment_approved, $commentdata) |
| 13 |
{ |
| 14 |
if ($comment_approved === 'spam') { |
| 15 |
return; |
| 16 |
} |
| 17 |
|
| 18 |
return Logtivity_Logger::log() |
| 19 |
->setAction('Comment Created') |
| 20 |
->setContext(substr(strip_tags($commentdata['comment_content']), 0, 30).'...') |
| 21 |
->addMeta('Author', $commentdata['comment_author'] ?? null) |
| 22 |
->addMeta('Approved', $comment_approved) |
| 23 |
->addMeta('Post URL', get_permalink($commentdata['comment_post_ID'])) |
| 24 |
->send(); |
| 25 |
} |
| 26 |
|
| 27 |
public function statusChanged($comment_id, $comment_status) |
| 28 |
{ |
| 29 |
if (in_array($comment_status, ['0', '1'])) { |
| 30 |
return; |
| 31 |
} |
| 32 |
|
| 33 |
return Logtivity_Logger::log() |
| 34 |
->setAction('Comment Status Changed') |
| 35 |
->setContext($comment_status) |
| 36 |
->addMeta('Comment ID', $comment_id) |
| 37 |
->send(); |
| 38 |
} |
| 39 |
|
| 40 |
public function commentMarkedAsNotspam($comment_ID, $comment) |
| 41 |
{ |
| 42 |
return $this->statusChanged($comment->comment_ID, 'Not Spam'); |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
$Logtivity_Comment = new Logtivity_Comment; |