PluginProbe
Activity Logs, User Activity Tracking, Multisite Activity Log from Logtivity / 1.0
Activity Logs, User Activity Tracking, Multisite Activity Log from Logtivity v1.0
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 1.6.1 All 66 releases
logtivity / Logs / Logtivity_Abstract_Logger.php

Logtivity_Abstract_Logger.php in Activity Logs, User Activity Tracking, Multisite Activity Log from Logtivity 1.0, at Logs/Logtivity_Abstract_Logger.php

87 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 abstract class Logtivity_Abstract_Logger
4 {
5 protected $logger;
6
7 protected $ignoredPostTypes = ['revision', 'customize_changeset'];
8
9 protected $ignoredPostTitles = ['Auto Draft'];
10
11 protected $ignoredPostStatuses = ['trash'];
12
13 public function __construct()
14 {
15 $this->registerHooks();
16 }
17
18 /**
19 * Check against certain rules on whether we should ignore the logging of a certain post
20 *
21 * @param WP_Post $post
22 * @return bool
23 */
24 protected function shouldIgnore($post)
25 {
26 if ($this->ignoringPostType($post->post_type)) {
27 return true;
28 }
29
30 if ($this->ignoringPostTitle($post->post_title)) {
31 return true;
32 }
33
34 if ($this->ignoringPostStatus($post->post_status)) {
35 return true;
36 }
37
38 return false;
39 }
40
41 /**
42 * Ignoring certain post statuses. Example: trash.
43 * We already have a postWasTrashed hook so
44 * don't need to log twice.
45 *
46 * @param string $post_status
47 * @return bool
48 */
49 protected function ignoringPostStatus($post_status)
50 {
51 return in_array($post_status, $this->ignoredPostStatuses);
52 }
53
54 /**
55 * Ignoring certain post types. Particularly system generated
56 * that are not directly triggered by the user.
57 *
58 * @param string $post_type
59 * @return bool
60 */
61 protected function ignoringPostType($post_type)
62 {
63 return in_array($post_type, $this->ignoredPostTypes);
64 }
65
66 /**
67 * Ignore certain system generated post titles
68 *
69 * @param string $title
70 * @return bool
71 */
72 protected function ignoringPostTitle($title)
73 {
74 return in_array($title, $this->ignoredPostTitles);
75 }
76
77 /**
78 * Generate a label version of the given post ids post type
79 *
80 * @param integer $post_id
81 * @return string
82 */
83 protected function getPostTypeLabel($post_id)
84 {
85 return ucwords( str_replace(['_', '-'], ' ', get_post_type($post_id)) );
86 }
87 }