PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 2.0.3
Adminify – White Label, Admin Menu Editor, Login Customizer v2.0.3
4.3.1 4.3.0 4.2.26 4.2.25 4.2.24 4.2.23 4.2.22 4.2.21 4.2.20 4.2.19 4.2.18 4.2.17 4.2.16 4.2.15 4.2.14 4.2.13 4.2.12 4.2.11 4.2.10 4.2.9 4.2.8 4.2.7 4.2.6 4.2.5 4.1.17 All 164 releases
adminify / Inc / Modules / ActivityLogs / Hooks / WP_Adminify_Logs_Posts.php

WP_Adminify_Logs_Posts.php in Adminify – White Label, Admin Menu Editor, Login Customizer 2.0.3, at Inc/Modules/ActivityLogs/Hooks/WP_Adminify_Logs_Posts.php

95 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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_Posts extends Hooks_Base
11 {
12 public function __construct()
13 {
14 parent::__construct();
15 add_action('transition_post_status', [$this, 'hooks_transition_post_status'], 10, 3);
16 add_action('delete_post', [$this, 'hooks_delete_post']);
17 }
18
19
20 protected function _draft_or_post_title($post = 0)
21 {
22 $title = esc_html(get_the_title($post));
23
24 if (empty($title))
25 $title = __('(no title)', WP_ADMINIFY_TD);
26
27 return $title;
28 }
29
30 public function hooks_transition_post_status($new_status, $old_status, $post)
31 {
32 if ('auto-draft' === $old_status && ('auto-draft' !== $new_status && 'inherit' !== $new_status)) {
33 // page created
34 $action = 'created';
35 } elseif ('auto-draft' === $new_status || ('new' === $old_status && 'inherit' === $new_status)) {
36 // nvm.. ignore it.
37 return;
38 } elseif ('trash' === $new_status) {
39 // page was deleted.
40 $action = 'trashed';
41 } elseif ('trash' === $old_status) {
42 $action = 'restored';
43 } else {
44 // page updated. I guess.
45 $action = 'updated';
46 }
47
48 if (wp_is_post_revision($post->ID))
49 return;
50
51 // Skip for menu items.
52 if ('nav_menu_item' === get_post_type($post->ID))
53 return;
54
55 adminify_activity_logs(
56 array(
57 'action' => $action,
58 'object_type' => 'Post',
59 'object_subtype' => $post->post_type,
60 'object_id' => $post->ID,
61 'object_name' => $this->_draft_or_post_title($post->ID),
62 )
63 );
64 }
65
66 public function hooks_delete_post($post_id)
67 {
68 if (wp_is_post_revision($post_id))
69 return;
70
71 $post = get_post($post_id);
72
73 if (!$post) {
74 return;
75 }
76
77 if (in_array($post->post_status, array('auto-draft', 'inherit')))
78 return;
79
80 // Skip for menu items.
81 if ('nav_menu_item' === get_post_type($post->ID))
82 return;
83
84 adminify_activity_logs(
85 array(
86 'action' => 'deleted',
87 'object_type' => 'Post',
88 'object_subtype' => $post->post_type,
89 'object_id' => $post->ID,
90 'object_name' => $this->_draft_or_post_title($post->ID),
91 )
92 );
93 }
94 }
95