PluginProbe
Patchstack – WordPress & Plugins Security / 2.1.15
Patchstack – WordPress & Plugins Security v2.1.15
2.3.7 trunk 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.16 2.1.17 2.1.18 2.1.19 2.1.2 2.1.20 2.1.21 2.1.22 2.1.23 2.1.24 2.1.25 2.1.3 2.1.4 2.1.5 2.1.6 All 49 releases
← All changes | includes/events/posts.php +110 -114 trunk2.1.15 View file →
@@ -1,114 +1,110 @@
1 -<?php
2 -
3 -// Do not allow the file to be called directly.
4 -if ( ! defined( 'ABSPATH' ) ) {
5 - exit;
6 -}
7 -
8 -/**
9 - * This class is used to log any post related action.
10 - */
11 -class P_Event_Posts extends P_Event_Log {
12 -
13 - /**
14 - * Hook into the actions so we can log it.
15 - *
16 - * @return void
17 - */
18 - public function __construct() {
19 - if ( ! get_option( 'patchstack_activity_log_posts', 0 ) ) {
20 - return;
21 - }
22 -
23 - add_action( 'transition_post_status', [ &$this, 'transition_post_status' ], 10, 3 );
24 - add_action( 'delete_post', [ &$this, 'delete_post' ] );
25 - }
26 -
27 - /**
28 - * Determine the title.
29 - *
30 - * @param integer $post
31 - * @return string
32 - */
33 - protected function _draft_or_post_title( $post = 0 ) {
34 - $title = esc_html( get_the_title( $post ) );
35 - if ( empty( $title ) ) {
36 - return esc_attr__( '(no title)', 'patchstack' );
37 - }
38 -
39 - return $title;
40 - }
41 -
42 - /**
43 - * When the status of a post is transitioned.
44 - *
45 - * @param string $new_status
46 - * @param string $old_status
47 - * @param object $post
48 - * @return void
49 - */
50 - public function transition_post_status( $new_status, $old_status, $post ) {
51 - // Determine the action.
52 - if ( $old_status === 'auto-draft' && ( $new_status !== 'auto-draft' && $new_status !== 'inherit' ) ) {
53 - $action = 'created';
54 - } elseif ( $new_status === 'auto-draft' || ( $old_status === 'new' && $new_status === 'inherit' ) ) {
55 - return;
56 - } elseif ( $new_status === 'trash' ) {
57 - $action = 'trashed';
58 - } elseif ( $old_status === 'trash' ) {
59 - $action = 'restored';
60 - } else {
61 - $action = 'updated';
62 - }
63 -
64 - // No need to log revisions.
65 - if ( wp_is_post_revision( $post->ID ) ) {
66 - return;
67 - }
68 -
69 - // Skip for menu items.
70 - if ( get_post_type( $post->ID ) === 'nav_menu_item' ) {
71 - return;
72 - }
73 -
74 - $this->insert(
75 - [
76 - 'object' => 'post',
77 - 'object_id' => $post->ID,
78 - 'action' => $action,
79 - 'object_name' => $this->_draft_or_post_title( $post->ID ),
80 - ]
81 - );
82 - }
83 -
84 - /**
85 - * When a post is deleted.
86 - *
87 - * @param integer $post_id
88 - * @return void
89 - */
90 - public function delete_post( $post_id ) {
91 - if ( wp_is_post_revision( $post_id ) ) {
92 - return;
93 - }
94 -
95 - $post = get_post( $post_id );
96 - if ( in_array( $post->post_status, [ 'auto-draft', 'inherit' ] ) ) {
97 - return;
98 - }
99 -
100 - // Skip for menu items.
101 - if ( get_post_type( $post->ID ) === 'nav_menu_item' ) {
102 - return;
103 - }
104 -
105 - $this->insert(
106 - [
107 - 'object' => 'post',
108 - 'object_id' => $post->ID,
109 - 'action' => 'deleted',
110 - 'object_name' => $this->_draft_or_post_title( $post->ID ),
111 - ]
112 - );
113 - }
114 -}
1 +<?php
2 +
3 +// Do not allow the file to be called directly.
4 +if ( ! defined( 'ABSPATH' ) ) {
5 + exit;
6 +}
7 +
8 +/**
9 + * This class is used to log any post related action.
10 + */
11 +class P_Event_Posts extends P_Event_Log {
12 +
13 + /**
14 + * Hook into the actions so we can log it.
15 + *
16 + * @return void
17 + */
18 + public function __construct() {
19 + add_action( 'transition_post_status', array( &$this, 'transition_post_status' ), 10, 3 );
20 + add_action( 'delete_post', array( &$this, 'delete_post' ) );
21 + }
22 +
23 + /**
24 + * Determine the title.
25 + *
26 + * @param integer $post
27 + * @return string
28 + */
29 + protected function _draft_or_post_title( $post = 0 ) {
30 + $title = esc_html( get_the_title( $post ) );
31 + if ( empty( $title ) ) {
32 + return __( '(no title)', 'patchstack' );
33 + }
34 +
35 + return $title;
36 + }
37 +
38 + /**
39 + * When the status of a post is transitioned.
40 + *
41 + * @param string $new_status
42 + * @param string $old_status
43 + * @param object $post
44 + * @return void
45 + */
46 + public function transition_post_status( $new_status, $old_status, $post ) {
47 + // Determine the action.
48 + if ( $old_status === 'auto-draft' && ( $new_status !== 'auto-draft' && $new_status !== 'inherit' ) ) {
49 + $action = 'created';
50 + } elseif ( $new_status === 'auto-draft' || ( $old_status === 'new' && $new_status === 'inherit' ) ) {
51 + return;
52 + } elseif ( $new_status === 'trash' ) {
53 + $action = 'trashed';
54 + } elseif ( $old_status === 'trash' ) {
55 + $action = 'restored';
56 + } else {
57 + $action = 'updated';
58 + }
59 +
60 + // No need to log revisions.
61 + if ( wp_is_post_revision( $post->ID ) ) {
62 + return;
63 + }
64 +
65 + // Skip for menu items.
66 + if ( get_post_type( $post->ID ) === 'nav_menu_item' ) {
67 + return;
68 + }
69 +
70 + $this->insert(
71 + array(
72 + 'object' => 'post',
73 + 'object_id' => $post->ID,
74 + 'action' => $action,
75 + 'object_name' => $this->_draft_or_post_title( $post->ID ),
76 + )
77 + );
78 + }
79 +
80 + /**
81 + * When a post is deleted.
82 + *
83 + * @param integer $post_id
84 + * @return void
85 + */
86 + public function delete_post( $post_id ) {
87 + if ( wp_is_post_revision( $post_id ) ) {
88 + return;
89 + }
90 +
91 + $post = get_post( $post_id );
92 + if ( in_array( $post->post_status, array( 'auto-draft', 'inherit' ) ) ) {
93 + return;
94 + }
95 +
96 + // Skip for menu items.
97 + if ( get_post_type( $post->ID ) === 'nav_menu_item' ) {
98 + return;
99 + }
100 +
101 + $this->insert(
102 + array(
103 + 'object' => 'post',
104 + 'object_id' => $post->ID,
105 + 'action' => 'deleted',
106 + 'object_name' => $this->_draft_or_post_title( $post->ID ),
107 + )
108 + );
109 + }
110 +}