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 / Core / Logtivity_Plugin.php

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

140 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class Logtivity_Plugin extends Logtivity_Abstract_Logger
4 {
5 public function registerHooks()
6 {
7 add_action( 'activated_plugin', [$this, 'pluginActivated'], 10, 2 );
8 add_action( 'deactivated_plugin', [$this, 'pluginDeactivated'], 10, 2 );
9 add_action( 'upgrader_process_complete', [$this, 'upgradeProcessComplete'], 10, 2);
10 add_filter( 'editable_extensions', [$this, 'pluginFileModified'], 10, 2 );
11 add_action( 'deleted_plugin', [$this, 'pluginDeleted'], 10, 2 );
12 }
13
14 public function pluginActivated($plugin, $network_wide)
15 {
16 return Logtivity_Logger::log('Plugin Activated. [' . $plugin . ']', [
17 'key' => 'network_wide',
18 'value' => $network_wide
19 ]);
20 }
21
22 public function pluginDeactivated($plugin, $network_deactivating)
23 {
24 return Logtivity_Logger::log('Plugin Deactivated. [' . $plugin . ']', [
25 'key' => 'network_deactivating',
26 'value' => $network_deactivating
27 ]);
28 }
29
30 public function pluginDeleted($plugin_file, $deleted)
31 {
32 return Logtivity_Logger::log()
33 ->setAction('Plugin Deleted. [' . $plugin_file . ']')
34 ->addMeta('Plugin Name', $plugin_file)
35 ->addMeta('Deletion Successful', $deleted)
36 ->send();
37 }
38
39 public function upgradeProcessComplete( $upgrader_object, $options )
40 {
41 if ( $options['type'] != 'plugin' ) {
42 return;
43 }
44
45 if ($options['action'] == 'update') {
46
47 return $this->pluginUpdated($upgrader_object, $options);
48
49 }
50
51 if ($options['action'] == 'install') {
52
53 return $this->pluginInstalled($upgrader_object, $options);
54
55 }
56 }
57
58 public function pluginUpdated($upgrader_object, $options)
59 {
60 if ( isset( $options['bulk'] ) && true == $options['bulk'] ) {
61 $slugs = $options['plugins'];
62 } else {
63 if ( ! isset( $upgrader->skin->plugin ) ) {
64 return;
65 }
66
67 $slugs = array( $upgrader->skin->plugin );
68 }
69
70 foreach ( $slugs as $slug )
71 {
72 $data = get_plugin_data( WP_PLUGIN_DIR . '/' . $slug, true, false );
73
74 Logtivity_Logger::log()
75 ->setAction('Plugin Updated. [' . $data['Name'] . ']')
76 ->addMeta('Plugin Name', $data['Name'])
77 ->addMeta('Version', ( isset($data['Version']) ? $data['Version'] : 'Not set'))
78 ->addMeta('Bulk', $options['bulk'])
79 ->send();
80 }
81
82 }
83
84 public function pluginInstalled($upgrader_object, $options)
85 {
86 $path = $upgrader_object->plugin_info();
87
88 if ( ! $path ) {
89 return;
90 }
91
92 $data = get_plugin_data( $upgrader_object->skin->result['local_destination'] . '/' . $path, true, false );
93
94 return Logtivity_Logger::log()
95 ->setAction('Plugin Installed. [' . $data['Name'] . ']')
96 ->addMeta('Plugin Name', $data['Name'])
97 ->addMeta('Version', $data['Version'])
98 ->send();
99 }
100
101 public function pluginFileModified( $editable_extensions, $plugin ) {
102
103 if ( ! isset($_POST['action']) || $_POST['action'] != 'edit-theme-plugin-file' ) {
104 return $editable_extensions;
105 }
106
107 if (!isset($_POST['plugin'])) {
108 return $editable_extensions;
109 }
110
111 $log = Logtivity_Logger::log()->setAction('Plugin File Edited');
112
113 if ( ! empty( $_REQUEST['file'] ) ) {
114
115 $plugin_dir = explode( '/', sanitize_text_field($_REQUEST['file'] ));
116 $plugin_data = array_values( get_plugins( '/' . $plugin_dir[0] ) );
117 $plugin_data = array_shift( $plugin_data );
118
119 if ( ! empty( $_POST['file'] ) ) {
120
121 $log->addMeta('File', sanitize_text_field($_POST['file']));
122
123 }
124
125 if ( isset($plugin_data['Name']) ) {
126
127 $log->addMeta('Plugin', $plugin_data['Name']);
128
129 }
130
131 }
132
133 $log->send();
134
135 return $editable_extensions;
136 }
137
138 }
139
140 $Logtivity_Plugin = new Logtivity_Plugin;