PluginProbe
The WP Remote WordPress Plugin / 4.83
The WP Remote WordPress Plugin v4.83
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.83, at wp_actlog.php

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