PluginProbe
The WP Remote WordPress Plugin / 5.53
The WP Remote WordPress Plugin v5.53
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 5.53, at wp_actlog.php

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