PluginProbe
Activity Logs, User Activity Tracking, Multisite Activity Log from Logtivity / 1.2.0
Activity Logs, User Activity Tracking, Multisite Activity Log from Logtivity v1.2.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_Post.php

Logtivity_Post.php in Activity Logs, User Activity Tracking, Multisite Activity Log from Logtivity 1.2.0, at Logs/Core/Logtivity_Post.php

142 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class Logtivity_Post extends Logtivity_Abstract_Logger
4 {
5 public function registerHooks()
6 {
7 add_action( 'transition_post_status', [$this, 'postStatusChanged'], 10, 3);
8 add_action( 'wp_trash_post', [$this, 'postWasTrashed'], 10, 1 );
9 add_filter('wp_handle_upload', [$this, 'mediaUploaded'], 10, 2);
10 add_action('delete_post', [$this, 'postPermanentlyDeleted'], 10, 1);
11 add_filter( 'wp_ajax_save-attachment', [$this, 'mediaMetaUpdated'], -1 );
12 }
13
14 public function postStatusChanged($new_status, $old_status, $post)
15 {
16 if ($this->shouldIgnore($post)) {
17 return;
18 }
19
20 if ($old_status == 'trash') {
21 return $this->postWasRestored($post);
22 }
23
24 if ($old_status != 'publish' && $new_status == 'publish') {
25 return $this->postWasPublished($post);
26 }
27
28 return $this->postWasUpdated($post, $old_status);
29 }
30
31 public function postWasPublished($post)
32 {
33 return Logtivity_Logger::log()
34 ->setAction($this->getPostTypeLabel($post->ID) . ' Published')
35 ->setContext($post->post_title)
36 ->addMeta('Post ID', $post->ID)
37 ->addMeta('Post Title', $post->post_title)
38 ->addMeta('Post Type', $post->post_type)
39 ->addMeta('Post Status', $post->post_status)
40 ->send();
41 }
42
43 /**
44 * Post was updated or created. ignoring certain auto save system actions
45 *
46 * @param integer $post_id
47 * @param WP_Post $post
48 * @param bool $update
49 * @return void
50 */
51 public function postWasUpdated($post, $old_status)
52 {
53 return Logtivity_Logger::log()
54 ->setAction($this->getPostTypeLabel($post->ID) . ' Updated')
55 ->setContext($post->post_title)
56 ->addMeta('Post ID', $post->ID)
57 ->addMeta('Post Title', $post->post_title)
58 ->addMeta('Post Type', $post->post_type)
59 ->addMeta('Post Status', $post->post_status)
60 ->addMeta('Old Status', $old_status)
61 ->send();
62 }
63
64 public function postWasTrashed($post_id)
65 {
66 if (get_post_type($post_id) == 'customize_changeset') {
67 return;
68 }
69
70 return Logtivity_Logger::log()
71 ->setAction($this->getPostTypeLabel($post_id) . ' Trashed')
72 ->setContext(get_the_title($post_id))
73 ->addMeta('Post ID', $post_id)
74 ->addMeta('Post Type', get_post_type($post_id))
75 ->addMeta('Post Title', get_the_title($post_id))
76 ->send();
77 }
78
79 public function postWasRestored($post)
80 {
81 return Logtivity_Logger::log()
82 ->setAction(
83 $this->getPostTypeLabel($post->ID) . ' Restored from Trash'
84 )
85 ->setContext($post->post_title)
86 ->addMeta('Post ID', $post->ID)
87 ->addMeta('Post Type', $post->post_type)
88 ->addMeta('Post Title', $post->post_title)
89 ->send();
90 }
91
92 public function postPermanentlyDeleted($post_id)
93 {
94 if ($this->ignoringPostType(get_post_type($post_id))) {
95 return;
96 }
97
98 if ($this->ignoringPostTitle(get_the_title($post_id))) {
99 return;
100 }
101
102 return Logtivity_Logger::log()
103 ->setAction(
104 $this->getPostTypeLabel($post_id) . ' Permanently Deleted'
105 )
106 ->setContext(get_the_title($post_id))
107 ->addMeta('Post ID', $post_id)
108 ->addMeta('Post Type', get_post_type($post_id))
109 ->addMeta('Post Title', get_the_title($post_id))
110 ->send();
111 }
112
113 public function mediaUploaded($upload, $context)
114 {
115 Logtivity_Logger::log()
116 ->setAction('Attachment Uploaded')
117 ->setContext(basename($upload['file']))
118 ->addMeta('Url', $upload['url'])
119 ->addMeta('Type', $upload['type'])
120 ->addMeta('Context', $context)
121 ->send();
122
123 return $upload;
124 }
125
126 public function mediaMetaUpdated()
127 {
128 $post_id = absint($_POST['id']);
129
130 if ($post_id) {
131 Logtivity_Logger::log()
132 ->setAction('Attachment Meta Updated.')
133 ->addMeta("Media ID", $post_id)
134 ->addMeta("Changes", ( isset($_POST['changes']) ? $_POST['changes'] : null))
135 ->send();
136 }
137
138 return $post;
139 }
140 }
141
142 $Logtivity_Post = new Logtivity_Post;