PluginProbe
The WP Remote WordPress Plugin / 4.66
The WP Remote WordPress Plugin v4.66
6.72 6.69 6.65 6.62 6.48 6.47 4.87 4.97 5.05 5.09 5.16 5.22 5.24 5.25 5.38 5.41 5.42 5.45 5.47 5.53 5.56 5.65 5.68 5.72 5.73 All 53 releases
wpremote / wp_actlog.php

wp_actlog.php in The WP Remote WordPress Plugin 4.66, at wp_actlog.php

485 lines 15.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (!defined('ABSPATH')) exit;
4 if (!class_exists('BVWPActLog')) :
5
6 class BVWPActLog {
7
8 public static $actlog_table = 'activities_store';
9 public $db;
10 public $settings;
11 public $bvinfo;
12
13 public function __construct($db, $settings, $info, $config) {
14 $this->db = $db;
15 $this->settings = $settings;
16 $this->bvinfo = $info;
17 $this->request_id = WPRInfo::getRequestID();
18 $this->ip_header = array_key_exists('ip_header', $config) ? $config['ip_header'] : false;
19 }
20
21 function init() {
22 $this->add_actions_and_listeners();
23 }
24
25 function get_post($post_id) {
26 $post = get_post($post_id);
27 $data = array('id' => $post_id);
28 if (!empty($post)) {
29 $data['title'] = $post->post_title;
30 $data['status'] = $post->post_status;
31 $data['type'] = $post->post_type;
32 $data['url'] = get_permalink($post_id);
33 $data['date'] = $post->post_date;
34 }
35 return $data;
36 }
37
38 function get_comment($comment_id) {
39 $comment = get_comment($comment_id);
40 $data = array('id' => $comment_id);
41 if (!empty($comment)) {
42 $data['author'] = $comment->comment_author;
43 $data['post_id'] = $comment->comment_post_ID;
44 }
45 return $data;
46 }
47
48 function get_term($term_id) {
49 $term = get_term($term_id);
50 $data = array('id' => $term_id);
51 if (!empty($term)) {
52 $data['name'] = $term->name;
53 $data['slug'] = $term->slug;
54 $data['taxonomy'] = $term->taxonomy;
55 }
56 return $data;
57 }
58
59 function get_user($user_id) {
60 $user = get_userdata($user_id);
61 $data = array('id' => $user_id);
62 if (!empty($user)) {
63 $data['username'] = $user->user_login;
64 $data['email'] = $user->user_email;
65 }
66 return $data;
67 }
68
69 function get_blog($blog_id) {
70 $blog = get_blog_details($blog_id);
71 $data = array('id' => $blog_id);
72 if (!empty($blog)) {
73 $data['name'] = $blog->blogname;
74 $data['url'] = $blog->path;
75 }
76 return $data;
77 }
78
79 function wc_get_attribute($attribute_id, $attribute_data = null) {
80 $data = array('id' => $attribute_id);
81 if (!is_null($attribute_data) && is_array($attribute_data)) {
82 $data['name'] = $attribute_data['attribute_label'];
83 $data['slug'] = $attribute_data['attribute_name'];
84 } else {
85 $attribute = wc_get_attribute($attribute_id);
86 if (!empty($attribute)) {
87 $data['name'] = $attribute->name;
88 $data['slug'] = substr($attribute->slug, 3);
89 }
90 }
91 return $data;
92 }
93
94 function wc_get_tax_rate($tax_rate_id, $tax_rate) {
95 $data = array('id' => $tax_rate_id);
96 if (!empty($tax_rate)) {
97 $data['name'] = array_key_exists('tax_rate_name', $tax_rate) ? $tax_rate['tax_rate_name'] : '';
98 $data['country'] = array_key_exists('tax_rate_country', $tax_rate) ? $tax_rate['tax_rate_country'] : '';
99 $data['rate'] = array_key_exists('tax_rate', $tax_rate) ? $tax_rate['tax_rate'] : '';
100 }
101 return $data;
102 }
103
104 function get_ip($ipHeader) {
105 $ip = '127.0.0.1';
106 if ($ipHeader && is_array($ipHeader)) {
107 if (array_key_exists($ipHeader['hdr'], $_SERVER)) {
108 $_ips = preg_split("/(,| |\t)/", $_SERVER[$ipHeader['hdr']]);
109 if (array_key_exists(intval($ipHeader['pos']), $_ips)) {
110 $ip = $_ips[intval($ipHeader['pos'])];
111 }
112 }
113 } else if (array_key_exists('REMOTE_ADDR', $_SERVER)) {
114 $ip = $_SERVER['REMOTE_ADDR'];
115 }
116
117 $ip = trim($ip);
118 if (preg_match('/^\[([0-9a-fA-F:]+)\](:[0-9]+)$/', $ip, $matches)) {
119 $ip = $matches[1];
120 } elseif (preg_match('/^([0-9.]+)(:[0-9]+)$/', $ip, $matches)) {
121 $ip = $matches[1];
122 }
123
124 return $ip;
125 }
126
127 function add_activity($event_data) {
128 if (!function_exists('wp_get_current_user')) {
129 @include_once(ABSPATH . "wp-includes/pluggable.php");
130 }
131
132 $user = wp_get_current_user();
133 $values = array();
134 if (!empty($user)) {
135 $values["user_id"] = $user->ID;
136 $values["username"] = $user->user_login;
137 }
138 $values["request_id"] = $this->request_id;
139 $values["site_id"] = get_current_blog_id();
140 $values["ip"] = $this->get_ip($this->ip_header);
141 $values["event_type"] = current_filter();
142 $values["event_data"] = maybe_serialize($event_data);
143 $values["time"] = time();
144 $this->db->replaceIntoBVTable(BVWPActLog::$actlog_table, $values);
145 }
146
147 function user_login_handler($user_login, $user) {
148 $event_data = array("user" => $this->get_user($user->ID));
149 $this->add_activity($event_data);
150 }
151
152 function user_logout_handler($user_id) {
153 $user = $this->get_user($user_id);
154 $event_data = array("user" => $user);
155 $this->add_activity($event_data);
156 }
157
158 function password_reset_handler($user, $new_pass) {
159 if (!empty($user)) {
160 $event_data = array("user" => $this->get_user($user->ID));
161 $this->add_activity($event_data);
162 }
163 }
164
165 function comment_handler($comment_id) {
166 $comment = $this->get_comment($comment_id);
167 $post = $this->get_post($comment['post_id']);
168 $event_data = array(
169 "comment" => $comment,
170 "post" => $post
171 );
172 $this->add_activity($event_data);
173 }
174
175 function comment_status_changed_handler($new_status, $old_status, $comment) {
176 $post = $this->get_post($comment->comment_post_ID);
177 $event_data = array(
178 "comment" => $this->get_comment($comment->comment_ID),
179 "post" => $post,
180 "old_status" => $old_status,
181 "new_status" => $new_status
182 );
183 $this->add_activity($event_data);
184 }
185
186 function post_handler($post_id) {
187 $post = $this->get_post($post_id);
188 $event_data = array();
189 if ($post["type"] === "product") {
190 $event_data["product"] = $post;
191 } elseif ($post["type"] === "shop_order") {
192 $event_data["order"] = $post;
193 } else {
194 $event_data["post"] = $post;
195 }
196 $this->add_activity($event_data);
197 }
198
199 function post_saved_handler($post_id, $post, $update) {
200 $post = $this->get_post($post_id);
201 $event_data = array();
202 if ($post["type"] === "product") {
203 $event_data["product"] = $post;
204 } elseif ($post["type"] === "shop_order") {
205 $event_data["order"] = $post;
206 } else {
207 $event_data["post"] = $post;
208 }
209 $event_data["updated"] = $update;
210 $this->add_activity($event_data);
211 }
212
213 function term_handler($term_id) {
214 $term = $this->get_term($term_id);
215 $event_data = array(
216 "term" => $term,
217 );
218 $this->add_activity($event_data);
219 }
220
221 function term_updation_handler($data, $term_id) {
222 $term = $this->get_term($term_id);
223 $event_data = array(
224 "term" => $term,
225 "new_term" => $data
226 );
227 $this->add_activity($event_data);
228 return $data;
229 }
230
231 function term_deletion_handler($term_id) {
232 $event_data = array(
233 "term" => array("id" => $term_id)
234 );
235 $this->add_activity($event_data);
236 }
237
238 function user_handler($user_id) {
239 $user = $this->get_user($user_id);
240 $event_data = array(
241 "user" => $user,
242 );
243 $this->add_activity($event_data);
244 }
245
246 function user_update_handler($user_id, $old_userdata) {
247 $new_userdata = $this->get_user($user_id);
248 $event_data = array(
249 "old_user" => $this->get_user($old_userdata->ID),
250 "user" => $new_userdata,
251 );
252 $this->add_activity($event_data);
253 }
254
255 function plugin_action_handler($plugin) {
256 $event_data = array("plugin" => $plugin);
257 $this->add_activity($event_data);
258 }
259
260 function theme_action_handler($theme_name) {
261 $event_data = array("theme" => $theme_name);
262 $this->add_activity($event_data);
263 }
264
265 function mu_handler($blog_id) {
266 $blog = $this->get_blog($blog_id);
267 $event_data = array(
268 "blog" => $blog
269 );
270 $this->add_activity($event_data);
271 }
272
273 function mu_site_handler($blog) {
274 $event_data = array(
275 "blog" => $this->get_blog($blog->blog_id)
276 );
277 $this->add_activity($event_data);
278 }
279
280 function woocommerce_attribute_created_handler($attribute_id, $attribute_data) {
281 $event_data = array(
282 "attribute" => $this->wc_get_attribute($attribute_id, $attribute_data)
283 );
284 $this->add_activity($event_data);
285 }
286
287 function woocommerce_attribute_handler($attribute_id) {
288 $event_data = array(
289 "attribute" => $this->wc_get_attribute($attribute_id)
290 );
291 $this->add_activity($event_data);
292 }
293
294 function woocommerce_tax_rate_handler($tax_rate_id, $tax_rate) {
295 $event_data = array(
296 "tax_rate" => $this->wc_get_tax_rate($tax_rate_id, $tax_rate)
297 );
298 $this->add_activity($event_data);
299 }
300
301 function woocommerce_tax_rate_deleted_handler($tax_rate_id) {
302 $event_data = array(
303 "tax_rate" => array("id" => $tax_rate_id)
304 );
305 $this->add_activity($event_data);
306 }
307
308 function woocommerce_grant_product_download_access_handler($data) {
309 $event_data = array(
310 "download_id" => $data['download_id'],
311 "user_id" => $data['user_id'],
312 "order_id" => $data['order_id'],
313 "product_id" => $data['product_id']
314 );
315 $this->add_activity($event_data);
316 }
317
318 function woocommerce_revoke_access_to_product_download_handler($download_id, $product_id, $order_id) {
319 $event_data = array(
320 "download_id" => $download_id,
321 "product_id" => $product_id,
322 "order_id" => $order_id
323 );
324 $this->add_activity($event_data);
325 }
326
327 function woocommerce_shipping_zone_method_handler($instance_id, $method_id, $zone_id) {
328 $event_data = array(
329 "instance_id" => absint ($instance_id),
330 "method_id" => $method_id,
331 "zone_id" => $zone_id
332 );
333 $this->add_activity($event_data);
334 }
335
336 function get_plugin_update_data($plugins) {
337 $data = array();
338 if (!empty($plugins) && defined('WP_PLUGIN_DIR')) {
339 foreach ($plugins as $plugin) {
340 $plugin_data = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin);
341 $install_data = array('title' => $plugin_data['Name'], 'version' => $plugin_data['Version']);
342 array_push($data, $install_data);
343 }
344 }
345 return $data;
346 }
347
348 function get_theme_update_data($themes) {
349 $data = array();
350 if (!empty($themes)) {
351 foreach ($themes as $theme) {
352 $theme_data = wp_get_theme($theme);
353 $install_data = array('title' => $theme_data['Name'], 'version' => $theme_data['Version']);
354 array_push($data, $install_data);
355 }
356 }
357 return $data;
358 }
359
360 function get_plugin_install_data($upgrader) {
361 $data = array();
362 if ($upgrader->bulk != "1") {
363 $plugin_data = $upgrader->new_plugin_data;
364 $install_data = array('title' => $plugin_data['Name'], 'version' => $plugin_data['Version']);
365 array_push($data, $install_data);
366 }
367 return $data;
368 }
369
370 function get_theme_install_data($upgrader) {
371 $data = array();
372 $theme_data = $upgrader->new_theme_data;
373 $install_data = array('title' => $theme_data['Name'], 'version' => $theme_data['Version']);
374 array_push($data, $install_data);
375 return $data;
376 }
377
378 function get_update_data($options) {
379 global $wp_version;
380 $event_data = array('action' => 'update');
381 if ($options['type'] === 'plugin') {
382 $event_data['type'] = 'plugin';
383 $event_data['plugins'] = $this->get_plugin_update_data($options['plugins']);
384 }
385 else if ($options['type'] === 'theme') {
386 $event_data['type'] = 'theme';
387 $event_data['themes'] = $this->get_theme_update_data($options['themes']);
388 }
389 else if ($options['type'] === 'core') {
390 $event_data['type'] = 'core';
391 $event_data['wp_core'] = array('prev_version' => $wp_version);
392 }
393 return $event_data;
394 }
395
396 function get_install_data($upgrader, $options) {
397 $event_data = array('action' => 'install');
398 if ($options['type'] === 'plugin') {
399 $event_data['type'] = 'plugin';
400 $event_data['plugins'] = $this->get_plugin_install_data($upgrader);
401 }
402 else if ($options['type'] === 'theme') {
403 $event_data['type'] = 'theme';
404 $event_data['themes'] = $this->get_theme_install_data($upgrader);
405 }
406 return $event_data;
407 }
408
409 function upgrade_handler($upgrader, $data) {
410 $event_data = array();
411 if ($data['action'] === 'update') {
412 $event_data = $this->get_update_data($data);
413 } else if ($data['action'] === 'install') {
414 $event_data = $this->get_install_data($upgrader, $data);
415 }
416 $this->add_activity($event_data);
417 }
418
419 /* ADDING ACTION AND LISTENERS FOR SENSING EVENTS. */
420 public function add_actions_and_listeners() {
421 /* SENSORS FOR POST AND PAGE CHANGES */
422 add_action('pre_post_update', array($this, 'post_handler'));
423 add_action('save_post', array($this, 'post_saved_handler'), 10, 3);
424 add_action('post_stuck', array($this, 'post_handler'));
425 add_action('post_unstuck', array($this, 'post_handler'));
426 add_action('delete_post', array($this, 'post_handler'));
427
428 /* SENSORS FOR COMMENTS */
429 add_action('comment_post', array($this, 'comment_handler'));
430 add_action('edit_comment', array($this, 'comment_handler'));
431 add_action('transition_comment_status', array($this, 'comment_status_changed_handler'), 10, 3);
432
433 /* SENSORS FOR TAG AND CATEGORY CHANGES */
434 add_action('create_term', array($this, 'term_handler'));
435 add_action('pre_delete_term', array($this, 'term_handler'));
436 add_action('delete_term', array($this, 'term_deletion_handler'));
437 add_filter('wp_update_term_data', array($this, 'term_updation_handler'), 10, 2);
438
439 /* SENSORS FOR USER CHANGES*/
440 add_action('user_register', array($this, 'user_handler'));
441 add_action('wpmu_new_user', array($this, 'user_handler'));
442 add_action('profile_update', array($this, 'user_update_handler'), 10, 2);
443 add_action('delete_user', array($this, 'user_handler'));
444 add_action('wpmu_delete_user', array($this, 'user_handler'));
445
446 /* SENSORS FOR PLUGIN AND THEME*/
447 add_action('activate_plugin', array($this, 'plugin_action_handler'));
448 add_action('deactivate_plugin', array($this, 'plugin_action_handler'));
449 add_action('switch_theme', array($this, 'theme_action_handler'));
450
451 /* SENSORS FOR MULTISITE CHANGES */
452 add_action('wp_insert_site', array($this, 'mu_site_handler'));
453 add_action('archive_blog', array($this, 'mu_handler'));
454 add_action('unarchive_blog', array( $this, 'mu_handler'));
455 add_action('activate_blog', array($this, 'mu_handler'));
456 add_action('deactivate_blog', array($this, 'mu_handler'));
457 add_action('wp_delete_site', array($this, 'mu_site_handler'));
458
459 /* SENSORS USER ACTIONS AT FRONTEND */
460 add_action('wp_login', array($this, 'user_login_handler'), 10, 2);
461 add_action('wp_logout', array( $this, 'user_logout_handler'), 5, 1);
462 add_action('password_reset', array( $this, 'password_reset_handler'), 10, 2);
463
464 /* SENSOR FOR PLUGIN, THEME, WPCORE UPGRADES */
465 add_action('upgrader_process_complete', array($this, 'upgrade_handler'), 10, 2);
466
467 /* SENSORS FOR WOOCOMMERCE EVENTS */
468 add_action('woocommerce_attribute_added', array($this, 'woocommerce_attribute_created_handler'), 10, 2);
469 add_action('woocommerce_attribute_updated', array($this, 'woocommerce_attribute_handler'), 10, 1);
470 add_action('woocommerce_before_attribute_delete', array($this, 'woocommerce_attribute_handler'), 10, 1);
471 add_action('woocommerce_attribute_deleted', array($this, 'woocommerce_attribute_handler'), 10, 1);
472
473 add_action('woocommerce_tax_rate_added', array($this, 'woocommerce_tax_rate_handler'), 10, 2);
474 add_action('woocommerce_tax_rate_deleted', array($this, 'woocommerce_tax_rate_deleted_handler'), 10, 1);
475 add_action('woocommerce_tax_rate_updated', array($this, 'woocommerce_tax_rate_handler'), 10, 2);
476
477 add_action('woocommerce_grant_product_download_access', array($this, 'woocommerce_grant_product_download_access_handler'), 10, 1);
478 add_action('woocommerce_ajax_revoke_access_to_product_download', array($this, 'woocommerce_revoke_access_to_product_download_handler'), 10, 3);
479
480 add_action('woocommerce_shipping_zone_method_added', array($this, 'woocommerce_shipping_zone_method_handler'), 10, 3);
481 add_action('woocommerce_shipping_zone_method_status_toggled', array($this, 'woocommerce_shipping_zone_method_handler'), 10, 3);
482 add_action('woocommerce_shipping_zone_method_deleted', array($this, 'woocommerce_shipping_zone_method_handler'), 10, 3);
483 }
484 }
485 endif;