PluginProbe
Activity Logs, User Activity Tracking, Multisite Activity Log from Logtivity / 1.14.0
Activity Logs, User Activity Tracking, Multisite Activity Log from Logtivity v1.14.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.14.0, at Logs/Core/Logtivity_Meta.php

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