| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPAdminify\Inc\Modules\ActivityLogs\Hooks; |
| 4 |
|
| 5 |
use WPAdminify\Inc\Modules\ActivityLogs\Inc\Hooks_Base; |
| 6 |
|
| 7 |
// no direct access allowed |
| 8 |
if (!defined('ABSPATH')) exit; |
| 9 |
|
| 10 |
class WP_Adminify_Logs_Attachments extends Hooks_Base |
| 11 |
{ |
| 12 |
public function __construct() |
| 13 |
{ |
| 14 |
add_action('add_attachment', [$this, 'hooks_add_attachment']); |
| 15 |
add_action('edit_attachment', [$this, 'hooks_edit_attachment']); |
| 16 |
add_action('delete_attachment', [$this, 'hooks_delete_attachment']); |
| 17 |
|
| 18 |
parent::__construct(); |
| 19 |
} |
| 20 |
|
| 21 |
protected function _add_log_attachment($action, $attachment_id) |
| 22 |
{ |
| 23 |
$post = get_post($attachment_id); |
| 24 |
|
| 25 |
adminify_activity_logs(array( |
| 26 |
'action' => $action, |
| 27 |
'object_type' => 'Attachment', |
| 28 |
'object_subtype' => $post->post_type, |
| 29 |
'object_id' => $attachment_id, |
| 30 |
'object_name' => esc_html(get_the_title($post->ID)), |
| 31 |
)); |
| 32 |
} |
| 33 |
|
| 34 |
public function hooks_delete_attachment($attachment_id) |
| 35 |
{ |
| 36 |
$this->_add_log_attachment('deleted', $attachment_id); |
| 37 |
} |
| 38 |
|
| 39 |
public function hooks_edit_attachment($attachment_id) |
| 40 |
{ |
| 41 |
$this->_add_log_attachment('updated', $attachment_id); |
| 42 |
} |
| 43 |
|
| 44 |
public function hooks_add_attachment($attachment_id) |
| 45 |
{ |
| 46 |
$this->_add_log_attachment('added', $attachment_id); |
| 47 |
} |
| 48 |
} |
| 49 |
|