# logtivity/1.6.0/Logs/Core/Logtivity_Comment.php

Activity Logs, User Activity Tracking, Multisite Activity Log from Logtivity, version 1.6.0. 42 lines.

- Page: https://pluginprobe.com/plugins/logtivity/1.6.0/code/Logs/Core/Logtivity_Comment.php
- Raw: https://pluginprobe.com/plugins/logtivity/1.6.0/raw/Logs/Core/Logtivity_Comment.php
- Modified: 2021-07-27T11:44:18+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/logtivity/1.6.0/code/Logs/Core/Logtivity_Comment.php#L10-L20`.

```php
<?php

class Logtivity_Comment
{
	public function __construct()
	{
		add_action('comment_post', [$this, 'commentCreated'], 10, 3);
		add_action( 'wp_set_comment_status', [$this, 'statusChanged'], 10, 2);
		add_action( 'unspam_comment', [$this, 'commentMarkedAsNotspam'], 10, 2);
	}

	public function commentCreated($comment_ID, $comment_approved, $commentdata)
	{
		return Logtivity_Logger::log()
			->setAction('Comment Created')
			->setContext(substr(strip_tags($commentdata['comment_content']), 0, 30).'...') 
			->addMeta('Author', $commentdata['comment_author'] ?? null)
			->addMeta('Approved', $comment_approved)
			->addMeta('Post URL', get_permalink($commentdata['comment_post_ID']))
			->send();
	}

	public function statusChanged($comment_id, $comment_status)
	{
		if (in_array($comment_status, ['0', '1'])) {
			return;
		}

		return Logtivity_Logger::log()
			->setAction('Comment Status Changed')
			->setContext($comment_status) 
			->addMeta('Comment ID', $comment_id)
			->send();
	}

	public function commentMarkedAsNotspam($comment_ID, $comment)
	{
		return $this->statusChanged($comment->comment_ID, 'Not Spam');
	}
}

$Logtivity_Comment = new Logtivity_Comment;
```
