PluginProbe
Activity Logs, User Activity Tracking, Multisite Activity Log from Logtivity / 1.18.0
Activity Logs, User Activity Tracking, Multisite Activity Log from Logtivity v1.18.0
3.3.9 3.3.8 trunk 1.0 1.1.0 1.10.0 1.11.0 1.11.1 1.12.0 1.13.0 1.14.0 1.15.0 1.16.0 1.17.0 1.17.1 1.18.0 1.19.0 1.2.0 1.20.0 1.20.1 1.3.0 1.3.1 1.4.0 1.5.0 1.6.0 All 67 releases
logtivity / Logs / Core / Logtivity_Meta.php

Logtivity_Meta.php in Activity Logs, User Activity Tracking, Multisite Activity Log from Logtivity 1.18.0, at Logs/Core/Logtivity_Meta.php

113 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class Logtivity_Meta extends Logtivity_Abstract_Logger
4 {
5 protected $ignoreKeys = [
6 'logtivity_last_logged',
7 '_edit_lock',
8 '_edit_last',
9 '_wp_attachment_metadata',
10 '_encloseme',
11 '_wp_trash_meta_status',
12 '_wp_trash_meta_time',
13 '_wp_desired_post_slug',
14 '_wp_trash_meta_comments_status',
15 '_pingme',
16 ];
17
18 protected $ignorePostTypes = [
19 'nav_menu_item',
20 'edd_payment',
21 'edd_log',
22 ];
23
24 protected $ignorePostTypesIfNotInAdminArea = [
25 'shop_order',
26 'dlm_download',
27 'dlm_download_version',
28 ];
29
30 public function __construct()
31 {
32 add_action('update_post_meta', [$this, 'updatingPostMeta'], 10, 4);
33 add_action( "added_post_meta", [$this, 'addedPostMeta'], 10, 4);
34 add_action( "delete_post_meta", [$this, 'deletingPostMeta'], 10, 4);
35 // add_action('update_comment_meta', [$this, 'updatingCommentMeta'], 10, 4);
36 // add_action('update_user_meta', [$this, 'updatingUserMeta'], 10, 4);
37 // add_action('update_term_meta', [$this, 'updatingTermMeta'], 10, 4);
38 }
39
40 public function deletingPostMeta($meta_id, $object_id, $meta_key, $_meta_value)
41 {
42 return $this->recordPostMetaChanges($meta_id, $object_id, $meta_key, $_meta_value, 'Deleted');
43 }
44
45 public function addedPostMeta($meta_id, $object_id, $meta_key, $_meta_value)
46 {
47 return $this->recordPostMetaChanges($meta_id, $object_id, $meta_key, $_meta_value, 'Added');
48 }
49
50 public function updatingPostMeta($meta_id, $object_id, $meta_key, $_meta_value)
51 {
52 return $this->recordPostMetaChanges($meta_id, $object_id, $meta_key, $_meta_value, 'Updated');
53 }
54
55 public function recordPostMetaChanges($meta_id, $object_id, $meta_key, $_meta_value, $keyword)
56 {
57 if (in_array($meta_key, $this->ignoreKeys)) {
58 return;
59 }
60
61 $post_type = get_post_type($object_id);
62
63 if (in_array($post_type, $this->ignorePostTypes)) {
64 return;
65 }
66
67 if ((in_array($post_type, $this->ignorePostTypesIfNotInAdminArea)) && (!is_admin())) {
68 return;
69 }
70
71 if ($meta_key === '_thumbnail_id') {
72 return $this->postThumbnailChanged($meta_id, $object_id, $meta_key, $_meta_value, $keyword);
73 }
74
75 return Logtivity_Logger::log()
76 ->setAction($this->getPostTypeLabel($object_id) . ' Meta '. $keyword)
77 ->setContext($meta_key)
78 ->setPostType(get_post_type($object_id))
79 ->setPostId($object_id)
80 ->addMeta('Meta Key', $meta_key)
81 ->addMeta('Meta Value', $_meta_value)
82 ->addMeta('Previous Value', get_post_meta($object_id, $meta_key, true))
83 ->addMeta('View Post', get_edit_post_link($object_id))
84 ->send();
85 }
86
87 public function postThumbnailChanged($meta_id, $object_id, $meta_key, $_meta_value, $keyword)
88 {
89 $previousThumbnailId = get_post_meta($object_id, $meta_key, true);
90
91 return Logtivity_Logger::log()
92 ->setAction('Post Thumbnail ' . ( $keyword == 'Deleted' ? 'Removed' : 'Changed'))
93 ->setContext(get_the_title($object_id))
94 ->setPostType(get_post_type($object_id))
95 ->setPostId($object_id)
96 ->addMetaIf($_meta_value != '', 'New Thumbnail ID', $_meta_value)
97 ->addMetaIf($_meta_value != '', 'New Filename', basename(get_attached_file($_meta_value)))
98 ->addMetaIf(
99 $previousThumbnailId != '' && $previousThumbnailId != $_meta_value,
100 'Previous Thumbnail ID',
101 $previousThumbnailId
102 )
103 ->addMetaIf(
104 $previousThumbnailId != '' && $previousThumbnailId != $_meta_value,
105 'Previous Filename',
106 basename(get_attached_file($previousThumbnailId))
107 )
108 ->addMeta('View Post', get_edit_post_link($object_id))
109 ->send();
110 }
111 }
112
113 $Logtivity_Meta = new Logtivity_Meta;