PluginProbe
Patchstack – WordPress & Plugins Security / 2.2.3
Patchstack – WordPress & Plugins Security v2.2.3
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 / event-log.php

event-log.php in Patchstack – WordPress & Plugins Security 2.2.3, at includes/event-log.php

86 lines 2.5 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 events that happen on the WordPress site.
10 */
11 class P_Event_Log extends P_Core {
12
13 /**
14 * Add the actions required for the activity logger.
15 *
16 * @param Patchstack $core
17 * @return void
18 */
19 public function __construct( $core ) {
20 parent::__construct( $core );
21 if ( ! $this->get_option( 'patchstack_activity_log_is_enabled', true ) ) {
22 return;
23 }
24
25 // The activity logger feature can only be used on an activated license.
26 if ( ! $this->license_is_active() || $this->get_option( 'patchstack_license_free', 0 ) == 1 || $this->is_community() ) {
27 return;
28 }
29
30 // Include all the different event loggers.
31 foreach ( [ 'posts', 'plugins', 'core', 'options', 'users', 'comments', 'attachment' ] as $event ) {
32 require_once dirname( __FILE__ ) . '/events/' . $event . '.php';
33 $class = 'P_Event_' . ucfirst( $event );
34 new $class();
35 }
36 }
37
38 /**
39 * If any of our event listeners get triggered, it will insert data using this method.
40 *
41 * @param array $args The arguments to log.
42 * @return void
43 */
44 public function insert( $args ) {
45 // Get the author name, if the user is logged in.
46 $user = get_user_by( 'id', get_current_user_id() );
47 $author = ! $user ? 'Unauthenticated user' : $user->data->user_login;
48
49 // If it's a scheduled task running, we override the name.
50 if ( defined( 'DOING_CRON' ) && DOING_CRON ) {
51 $author = 'WPCron';
52 }
53
54 // Exception for when the action is 'logged in'.
55 if ( $args['action'] == 'logged in' ) {
56 $author = $args['object_name'];
57 }
58
59 // Log the action.
60 if ( ! is_null( $this->get_ip() ) ) {
61
62 // Skip unauthenticated user on post object.
63 if ( $author == 'Unauthenticated user' && $args['object'] == 'post' ) {
64 return;
65 }
66
67 // Insert into the logs.
68 global $wpdb;
69 $wpdb->insert(
70 $wpdb->prefix . 'patchstack_event_log',
71 [
72 'author' => $author,
73 'ip' => $this->get_ip(),
74 'object' => isset( $args['object'] ) ? $args['object'] : '',
75 'object_id' => isset( $args['object_id'] ) ? (int) $args['object_id'] : '',
76 'action' => isset( $args['action'] ) ? $args['action'] : '',
77 'object_name' => isset( $args['object_name'] ) ? $args['object_name'] : '',
78 'date' => current_time( 'mysql' ),
79 'flag' => '',
80 ],
81 [ '%s', '%s', '%s', '%d', '%s', '%s', '%s' ]
82 );
83 }
84 }
85 }
86