| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* @package Logtivity |
| 5 |
* @contact logtivity.io, hello@logtivity.io |
| 6 |
* @copyright 2024-2026 Logtivity. All rights reserved |
| 7 |
* @license https://www.gnu.org/licenses/gpl.html GNU/GPL |
| 8 |
* |
| 9 |
* This file is part of Logtivity. |
| 10 |
* |
| 11 |
* Logtivity is free software: you can redistribute it and/or modify |
| 12 |
* it under the terms of the GNU General Public License as published by |
| 13 |
* the Free Software Foundation, either version 2 of the License, or |
| 14 |
* (at your option) any later version. |
| 15 |
* |
| 16 |
* Logtivity is distributed in the hope that it will be useful, |
| 17 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 |
* GNU General Public License for more details. |
| 20 |
* |
| 21 |
* You should have received a copy of the GNU General Public License |
| 22 |
* along with Logtivity. If not, see <https://www.gnu.org/licenses/>. |
| 23 |
*/ |
| 24 |
|
| 25 |
class Logtivity_Comment |
| 26 |
{ |
| 27 |
public function __construct() |
| 28 |
{ |
| 29 |
add_action('comment_post', [$this, 'commentCreated'], 10, 3); |
| 30 |
add_action('wp_set_comment_status', [$this, 'statusChanged'], 10, 2); |
| 31 |
add_action('unspam_comment', [$this, 'commentMarkedAsNotspam'], 10, 2); |
| 32 |
} |
| 33 |
|
| 34 |
public function commentCreated($comment_ID, $comment_approved, $commentdata) |
| 35 |
{ |
| 36 |
if ($comment_approved !== 'spam') { |
| 37 |
Logtivity::log() |
| 38 |
->setAction('Comment Created') |
| 39 |
->setContext(substr(strip_tags($commentdata['comment_content']), 0, 30) . '...') |
| 40 |
->addMeta('Author', $commentdata['comment_author'] ?? null) |
| 41 |
->addMeta('Approved', $comment_approved) |
| 42 |
->addMeta('Post URL', get_permalink($commentdata['comment_post_ID'])) |
| 43 |
->send(); |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
public function statusChanged($comment_id, $comment_status) |
| 48 |
{ |
| 49 |
if (in_array($comment_status, ['0', '1']) == false) { |
| 50 |
Logtivity::log() |
| 51 |
->setAction('Comment Status Changed') |
| 52 |
->setContext($comment_status) |
| 53 |
->addMeta('Comment ID', $comment_id) |
| 54 |
->send(); |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
public function commentMarkedAsNotspam($comment_ID, $comment) |
| 59 |
{ |
| 60 |
$this->statusChanged($comment->comment_ID, 'Not Spam'); |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
new Logtivity_Comment(); |
| 65 |
|