PluginProbe
Patchstack – WordPress & Plugins Security / 2.1.2
Patchstack – WordPress & Plugins Security v2.1.2
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
patchstack / includes / events / attachment.php

attachment.php in Patchstack – WordPress & Plugins Security 2.1.2, at includes/events/attachment.php

73 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 attachment related event.
10 */
11 class P_Event_Attachment 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( 'add_attachment', array( &$this, 'addAttachment' ) );
20 add_action( 'edit_attachment', array( &$this, 'editAttachment' ) );
21 add_action( 'delete_attachment', array( &$this, 'deleteAttachment' ) );
22 }
23
24 /**
25 * Log the action regarding the attachment.
26 *
27 * @param string $action
28 * @param integer $attachment_id
29 * @return void
30 */
31 protected function _addLogAttachment( $action, $attachment_id ) {
32 $attachment = get_post( $attachment_id );
33 $this->insert(
34 array(
35 'action' => $action,
36 'object' => 'attachment',
37 'object_id' => $attachment_id,
38 'object_name' => esc_html( get_the_title( $attachment->ID ) ),
39 )
40 );
41 }
42
43 /**
44 * When an attachment is deleted.
45 *
46 * @param integer $attachment_id
47 * @return void
48 */
49 public function deleteAttachment( $attachment_id ) {
50 $this->_addLogAttachment( 'deleted', $attachment_id );
51 }
52
53 /**
54 * When an attachment is modified.
55 *
56 * @param integer $attachment_id
57 * @return void
58 */
59 public function editAttachment( $attachment_id ) {
60 $this->_addLogAttachment( 'updated', $attachment_id );
61 }
62
63 /**
64 * When an attachment is added.
65 *
66 * @param integer $attachment_id
67 * @return void
68 */
69 public function addAttachment( $attachment_id ) {
70 $this->_addLogAttachment( 'added', $attachment_id );
71 }
72 }
73