PluginProbe
The WP Remote WordPress Plugin / 5.85
The WP Remote WordPress Plugin v5.85
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_dynsync.php

wp_dynsync.php in The WP Remote WordPress Plugin 5.85, at wp_dynsync.php

751 lines 34.7 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('BVWPDynSync')) :
5
6 class BVWPDynSync {
7
8 public static $dynsync_table = 'dynamic_sync';
9 public $db;
10 public $settings;
11 public $config;
12 public $ignored_events;
13
14 public function __construct($db, $settings, $config) {
15 $this->db = $db;
16 $this->settings = $settings;
17 $this->config = $config;
18 $this->ignored_events = array_key_exists('ignored_events', $config) ? $config['ignored_events'] : array();
19 }
20
21 function init() {
22 $this->add_actions_and_listeners();
23 add_action('wpr_clear_dynsync_config', array($this, 'clearConfig'));
24 }
25
26 public function clearConfig() {
27 $this->db->dropBVTable(BVWPDynSync::$dynsync_table);
28 }
29
30 function add_event($event_type, $event_data) {
31 global $wp_current_filter;
32 $site_id = get_current_blog_id();
33 $values = array ( "event_type" => $event_type, "event_tag" => end($wp_current_filter), "event_data" => maybe_serialize($event_data), "site_id" => $site_id);
34 $this->db->replaceIntoBVTable(BVWPDynSync::$dynsync_table, $values);
35 }
36
37 function add_db_event($table, $message) {
38 $_msg = array();
39 $_msg['table'] = $table;
40 $_msg['data'] = $message;
41 $this->add_event('db', $_msg);
42 }
43
44 function post_action_handler($post_id) {
45 if (current_filter() == 'delete_post')
46 $msg_type = 'delete';
47 else
48 $msg_type = 'edit';
49 $this->add_db_event('posts', array('ID' => $post_id, 'msg_type' => $msg_type));
50 }
51
52 function get_ignored_postmeta() {
53 $ignored_postmeta = $this->ignored_events['postmeta'];
54 if (empty($ignored_postmeta)) {
55 $ignored_postmeta = array();
56 }
57 return array_unique($ignored_postmeta);
58 }
59
60 function postmeta_insert_handler($meta_id, $post_id, $meta_key, $meta_value='') {
61 if ($this->is_key_ignored($this->get_ignored_postmeta(), $meta_key))
62 return;
63 $this->add_db_event('postmeta', array('meta_id' => $meta_id));
64 }
65
66 function postmeta_modification_handler($meta_id, $object_id, $meta_key, $meta_value) {
67 if ($this->is_key_ignored($this->get_ignored_postmeta(), $meta_key))
68 return;
69 if (!is_array($meta_id))
70 return $this->add_db_event('postmeta', array('meta_id' => $meta_id));
71 foreach ($meta_id as $id) {
72 $this->add_db_event('postmeta', array('meta_id' => $id));
73 }
74 }
75
76 function postmeta_action_handler($meta_id, $post_id = null, $meta_key = null) {
77 if ($this->is_key_ignored($this->get_ignored_postmeta(), $meta_key))
78 return;
79 if ( !is_array($meta_id) )
80 return $this->add_db_event('postmeta', array('meta_id' => $meta_id));
81 foreach ( $meta_id as $id )
82 $this->add_db_event('postmeta', array('meta_id' => $id));
83 }
84
85 function comment_action_handler($comment_id) {
86 if (current_filter() == 'delete_comment')
87 $msg_type = 'delete';
88 else
89 $msg_type = 'edit';
90 if (!is_array($comment_id)) {
91 if (wp_get_comment_status($comment_id) != 'spam')
92 $this->add_db_event('comments', array('comment_ID' => $comment_id, 'msg_type' => $msg_type));
93 } else {
94 foreach ($comment_id as $id) {
95 if (wp_get_comment_status($comment_id) != 'spam')
96 $this->add_db_event('comments', array('comment_ID' => $id, 'msg_type' => $msg_type));
97 }
98 }
99 }
100
101 function commentmeta_insert_handler($meta_id, $comment_id = null) {
102 if (empty($comment_id) || wp_get_comment_status($comment_id) != 'spam')
103 $this->add_db_event('commentmeta', array('meta_id' => $meta_id));
104 }
105
106 function commentmeta_modification_handler($meta_id, $object_id, $meta_key, $meta_value) {
107 if (current_filter() == 'deleted_comment_meta')
108 $msg_type = 'delete';
109 else
110 $msg_type = 'edit';
111 if (!is_array($meta_id))
112 return $this->add_db_event('commentmeta', array('meta_id' => $meta_id, 'msg_type' => $msg_type));
113 foreach ($meta_id as $id) {
114 $this->add_db_event('commentmeta', array('meta_id' => $id, 'msg_type' => $msg_type));
115 }
116 }
117
118 function userid_action_handler($user_or_id) {
119 if (is_object($user_or_id))
120 $userid = intval( $user_or_id->ID );
121 else
122 $userid = intval( $user_or_id );
123 if ( !$userid )
124 return;
125 if (current_filter() == 'deleted_user')
126 $msg_type = 'delete';
127 else
128 $msg_type = 'edit';
129
130 $this->add_db_event('users', array('ID' => $userid));
131 }
132
133 function usermeta_insert_handler($umeta_id, $user_id = null) {
134 $this->add_db_event('usermeta', array('umeta_id' => $umeta_id));
135 }
136
137 function usermeta_modification_handler($umeta_id, $object_id, $meta_key, $meta_value = '') {
138 if (current_filter() == 'delete_usermeta')
139 $msg_type = 'delete';
140 else
141 $msg_type = 'edit';
142 if (!is_array($umeta_id))
143 return $this->add_db_event('usermeta', array('umeta_id' => $umeta_id, 'msg_type' => $msg_type));
144 foreach ($umeta_id as $id) {
145 $this->add_db_event('usermeta', array('umeta_id' => $id, 'msg_type' => $msg_type));
146 }
147 }
148
149 function link_action_handler($link_id) {
150 $this->add_db_event('links', array('link_id' => $link_id));
151 }
152
153 function edited_terms_handler($term_id, $taxonomy = null) {
154 $this->add_db_event('terms', array('term_id' => $term_id));
155 }
156
157 function term_handler($term_id, $tt_id, $taxonomy) {
158 $this->add_db_event('terms', array('term_id' => $term_id));
159 $this->term_taxonomy_handler($tt_id, $taxonomy);
160 }
161
162 function delete_term_handler($term, $tt_id, $taxonomy, $deleted_term ) {
163 $this->add_db_event('terms', array('term_id' => $term, 'msg_type' => 'delete'));
164 }
165
166 function term_taxonomy_handler($tt_id, $taxonomy = null) {
167 $this->add_db_event('term_taxonomy', array('term_taxonomy_id' => $tt_id));
168 }
169
170 function term_taxonomies_handler($tt_ids) {
171 foreach((array)$tt_ids as $tt_id) {
172 $this->term_taxonomy_handler($tt_id);
173 }
174 }
175
176 function term_relationship_handler($object_id, $term_id) {
177 $this->add_db_event('term_relationships', array('term_taxonomy_id' => $term_id, 'object_id' => $object_id));
178 }
179
180 function term_relationships_handler($object_id, $term_ids) {
181 foreach ((array)$term_ids as $term_id) {
182 $this->term_relationship_handler($object_id, $term_id);
183 }
184 }
185
186 function set_object_terms_handler( $object_id, $terms, $tt_ids ) {
187 $this->term_relationships_handler( $object_id, $tt_ids );
188 }
189
190 function get_ignored_options() {
191 $ignored_options = $this->ignored_events['options'];
192 if (empty($ignored_options)) {
193 $ignored_options = array();
194 }
195 return array_unique($ignored_options);
196 }
197
198 function is_key_ignored($ignored_keys, $value) {
199 $is_ignored = false;
200 foreach($ignored_keys as $val) {
201 if ($val[0] == '/') {
202 if (WPRHelper::safePregMatch($val, $value))
203 $is_ignored = true;
204 } else {
205 if ($val == $value)
206 $is_ignored = true;
207 }
208 if ($is_ignored)
209 break;
210 }
211 return $is_ignored;
212 }
213
214 function option_handler($option_name) {
215 if (current_filter() == 'deleted_option')
216 $msg_type = 'delete';
217 else
218 $msg_type = 'edit';
219 $is_ignored = $this->is_key_ignored($this->get_ignored_options(), $option_name);
220 if (!$is_ignored)
221 $this->add_db_event('options', array('option_name' => $option_name, 'msg_type' => $msg_type));
222 return $option_name;
223 }
224
225 function theme_action_handler($theme) {
226 $this->add_event('themes', array('theme' => $this->settings->getOption('stylesheet')));
227 }
228
229 function plugin_action_handler($plugin='') {
230 $this->add_event('plugins', array('name' => $plugin));
231 }
232
233 function upload_handler($file) {
234 $this->add_event('uploads', array('file' => $file['file']));
235 return $file;
236 }
237
238 function attachment_metadata_handler($data = null, $post_id = null) {
239 if(!empty($data) && !empty($data['file'])) {
240 $this->add_event('uploads', array('file' => $data['file'], 'sizes' => $data['sizes']));
241 }
242 return $data;
243 }
244
245 function wpmu_new_blog_create_handler($site_id) {
246 $this->add_db_event('blogs', array('site_id' => $site_id));
247 }
248
249 function sitemeta_handler($option) {
250 $is_ignored = $this->is_key_ignored($this->get_ignored_options(), $option);
251 if (!$is_ignored && is_multisite()) {
252 $this->add_db_event('sitemeta', array('site_id' => $this->db->getSiteId(), 'meta_key' => $option));
253 }
254 return !$is_ignored;
255 }
256
257 /* WOOCOMMERCE SUPPORT FUNCTIONS BEGINS FROM HERE*/
258
259 function handle_order_items($order_id, $type = null) {
260 $this->add_db_event('woocommerce_order_items', array('order_id' => $order_id, 'msg_type' => 'delete'));
261 $itemmeta_table = $this->db->getWPTable('woocommerce_order_itemmeta');
262 $items_table = $this->db->getWPTable('woocommerce_order_items');
263
264 $query = "SELECT imt.meta_id FROM %i imt INNER JOIN %i it WHERE imt.order_item_id = it.order_item_id AND it.order_id = %d";
265
266 $args = array($itemmeta_table, $items_table, $order_id);
267
268 if (!empty($type)) {
269 $query .= " AND it.order_item_type = %s";
270 $args[] = $type;
271 }
272
273 $meta_ids = array();
274 foreach ($this->db->getResult($query, $args) as $row) {
275 if (!in_array($row['meta_id'], $meta_ids, true)) {
276 $meta_ids[] = $row['meta_id'];
277 $this->add_db_event('woocommerce_order_itemmeta', array('meta_id' => $row['meta_id'], 'msg_type' => 'delete'));
278 }
279 }
280 }
281
282 function woocommerce_remove_order_items_handler($order, $type = null) {
283 $order_id = $order->get_id();
284 $this->handle_order_items($order_id, $type);
285 }
286
287 function woocommerce_resume_order_handler($order_id) {
288 $this->handle_order_items($order_id);
289 }
290
291 function woocommerce_update_order_handler($order_id, $order = null) {
292 $this->add_db_event('wc_orders', array('id' => $order_id));
293 $this->add_db_event('wc_orders_meta', array('order_id' => $order_id));
294 $this->add_db_event('wc_order_addresses', array('order_id' => $order_id));
295 $this->add_db_event('wc_order_operational_data', array('order_id' => $order_id));
296 }
297
298 function woocommerce_trash_order_handler($order_id) {
299 $this->add_db_event('wc_orders', array('id' => $order_id));
300 $this->add_db_event('wc_orders_meta', array('order_id' => $order_id));
301 }
302
303 function woocommerce_delete_order_handler($order_id) {
304 $this->add_db_event('wc_orders', array('id' => $order_id, 'msg_type' => 'delete'));
305 $this->add_db_event('wc_orders_meta', array('order_id' => $order_id, 'msg_type' => 'delete'));
306 $this->add_db_event('wc_order_addresses', array('order_id' => $order_id, 'msg_type' => 'delete'));
307 $this->add_db_event('wc_order_operational_data', array('order_id' => $order_id, 'msg_type' => 'delete'));
308 }
309
310 function woocommerce_new_order_item_handler($item_id, $item, $order_id) {
311 $this->add_db_event('woocommerce_order_items', array('order_item_id' => $item_id));
312 $this->add_db_event('woocommerce_order_itemmeta', array('order_item_id' => $item_id));
313 }
314
315 function woocommerce_update_order_item_handler($item_id, $args){
316 $this->add_db_event('woocommerce_order_items', array('order_item_id' => $item_id));
317 }
318
319 function woocommerce_delete_order_item_handler($item_id) {
320 $this->add_db_event('woocommerce_order_itemmeta', array('order_item_id' => $item_id, 'msg_type' => 'delete'));
321 $this->add_db_event('woocommerce_order_items', array('order_item_id' => $item_id, 'msg_type' => 'delete'));
322 }
323
324 function woocommerce_attribute_added_handler($attribute_id, $attribute) {
325 $this->add_db_event('woocommerce_attribute_taxonomies', array('attribute_id' => $attribute_id));
326 }
327
328 function woocommerce_attribute_updated_handler($attribute_id, $attribute, $old_attribute_name) {
329 $this->add_db_event('woocommerce_attribute_taxonomies', array('attribute_id' => $attribute_id));
330 # $woocommerce->attribute_taxonomy_name( $attribute_name )
331 $this->add_db_event('term_taxonomy', array('taxonomy' => wc_attribute_taxonomy_name($attribute['attribute_name'])));
332 # sanitize_title( $attribute_name )
333 $this->add_db_event('woocommerce_termmeta', array('meta_key' => 'order_pa_' . $attribute['attribute_name']));#deprecated
334 $this->add_db_event('termmeta', array('meta_key' => 'order_pa_' . $attribute['attribute_name']));
335 $this->add_db_event('postmeta', array('meta_key' => '_product_attributes'));
336 # sanitize_title( $attribute_name )
337 $this->add_db_event('postmeta', array('meta_key' => 'attribute_pa_' . $attribute['attribute_name']));
338 }
339
340 function woocommerce_attribute_deleted_handler($attribute_id, $attribute_name, $taxonomy) {
341 return $this->add_db_event('woocommerce_attribute_taxonomies', array('attribute_id' => $attribute_id, 'msg_type' => 'delete'));
342 }
343
344 function woocommerce_revoke_access_to_product_download_handler($download_id, $product_id, $order_id, $permission_id ) {
345 $this->add_db_event('woocommerce_downloadable_product_permissions', array('permission_id' => $permission_id, 'msg_type' => 'delete'));
346 }
347
348 function woocommerce_tax_rate_handler($tax_rate_id, $_tax_rate) {
349 $this->add_db_event('woocommerce_tax_rates', array('tax_rate_id' => $tax_rate_id));
350 }
351
352 function woocommerce_tax_rate_deleted_handler($tax_rate_id) {
353 $this->add_db_event('woocommerce_tax_rates', array('tax_rate_id' => $tax_rate_id, 'msg_type' => 'delete'));
354 $this->add_db_event('woocommerce_tax_rate_locations', array('tax_rate_id' => $tax_rate_id, 'msg_type' => 'delete'));
355 }
356
357 function woocommerce_grant_product_download_access_handler($data) {
358 $this->add_db_event('woocommerce_downloadable_product_permissions', array('download_id' => $data['download_id'], 'user_id' => $data['user_id'], 'order_id' => $data['order_id'], 'product_id' => $data['product_id']));
359 }
360
361 function woocommerce_download_product_handler($user_email, $order_key, $product_id, $user_id, $download_id, $order_id) {
362 $this->add_db_event('woocommerce_downloadable_product_permissions', array('order_id' => $order_id, 'user_id' => $user_id, 'order_key' => $order_key, 'product_id' => $product_id));
363 }
364
365 function woocommerce_delete_order_items_handler($postid) {
366 $meta_ids = array();
367 $order_item_ids = array();
368 $query = "SELECT wom.meta_id, woi.order_item_id
369 FROM %i wom JOIN %i woi
370 ON woi.order_item_id = wom.order_item_id
371 WHERE woi.order_id = %d";
372
373 $args = array($this->db->getWPTable('woocommerce_order_itemmeta'), $this->db->getWPTable('woocommerce_order_items'), $postid);
374 foreach ($this->db->getResult($query, $args) as $row) {
375 if (!in_array($row['meta_id'], $meta_ids, true)) {
376 $meta_ids[] = $row['meta_id'];
377 $this->add_db_event('woocommerce_order_itemmeta', array('meta_id' => $row['meta_id'], 'msg_type' => 'delete'));
378 }
379 if (!in_array($row['order_item_id'], $order_item_ids, true)) {
380 $order_item_ids[] = $row['order_item_id'];
381 $this->add_db_event('woocommerce_order_items', array('order_item_id' => $row['order_item_id'], 'msg_type' => 'delete'));
382 }
383 }
384 }
385
386 function woocommerce_payment_token_handler($token_id) {
387 $this->add_db_event('woocommerce_payment_tokens', array('token_id' => $token_id));
388 }
389
390 function woocommerce_payment_token_deleted_handler($token_id, $object) {
391 $this->add_db_event('woocommerce_payment_tokens', array('token_id' => $token_id, 'msg_type' => 'delete'));
392 $this->add_db_event('woocommerce_payment_tokenmeta', array('payment_token_id' => $token_id, 'msg_type' => 'delete'));
393 }
394
395 function woocommerce_shipping_zone_method_added_handler($instance_id, $method_id, $zone_id) {
396 $this->add_db_event('woocommerce_shipping_zone_methods', array('instance_id' => $instance_id));
397 $this->add_db_event('woocommerce_shipping_zones', array('zone_id' => $zone_id));
398 $this->add_db_event('woocommerce_shipping_zone_locations', array('zone_id' => $zone_id));
399 }
400
401 function woocommerce_shipping_zone_method_deleted_handler($instance_id, $method_id, $zone_id) {
402 $this->add_db_event('woocommerce_shipping_zone_methods', array('instance_id' => $instance_id, 'msg_type' => 'delete'));
403 }
404
405 function woocommerce_shipping_zone_method_status_toggled_handler($instance_id, $method_id, $zone_id, $is_enabled) {
406 $this->add_db_event('woocommerce_shipping_zone_methods', array('instance_id' => absint( $instance_id )));
407 }
408
409 function woocommerce_deleted_order_downloadable_permissions_handler($post_id) {
410 $this->add_db_event('woocommerce_downloadable_product_permissions', array('order_id' => $post_id, 'msg_type' => 'delete'));
411 }
412
413 function woocommerce_delete_shipping_zone_handler($zone_id) {
414 $this->add_db_event('woocommerce_shipping_zone_methods', array('zone_id' => $zone_id, 'msg_type' => 'delete'));
415 $this->add_db_event('woocommerce_shipping_zone_locations', array('zone_id' => $zone_id, 'msg_type' => 'delete'));
416 $this->add_db_event('woocommerce_shipping_zones', array('zone_id' => $zone_id, 'msg_type' => 'delete'));
417 }
418
419 function woocommerce_webhook_handler($webhook_id) {
420 $this->add_db_event('wc_webhooks', array('webhook_id' => $webhook_id));
421 }
422
423 function woocommerce_webhook_delete_handler($webhook_id, $webhook) {
424 $this->add_db_event('wc_webhooks', array('webhook_id' => $webhook_id, 'msg_type' => 'delete'));
425 }
426
427 function woocommerce_delete_shipping_zone_method_handler($instance_id) {
428 $this->add_db_event('woocommerce_shipping_zone_methods', array('instance_id' => $instance_id, 'msg_type' => 'delete'));
429 }
430
431 function woocommerce_order_term_meta_handler($meta_id, $object_id, $meta_key, $meta_value) {
432 if (current_filter() == 'deleted_order_item_meta')
433 $msg_type = 'delete';
434 else
435 $msg_type = 'edit';
436 if (!is_array($meta_id)) {
437 $this->add_db_event('woocommerce_order_itemmeta', array('meta_id' => $meta_id, 'msg_type' => $msg_type));
438 } else {
439 foreach ($meta_id as $id) {
440 $this->add_db_event('woocommerce_order_itemmeta', array('meta_id' => $id, 'msg_type' => $msg_type));
441 }
442 }
443 }
444
445 function woocommerce_payment_token_meta_handler($meta_id, $object_id, $meta_key, $meta_value) {
446 if (current_filter() == 'deleted_payment_token_meta')
447 $msg_type = 'delete';
448 else
449 $msg_type = 'edit';
450 if (!is_array($meta_id)) {
451 $this->add_db_event('woocommerce_payment_tokenmeta', array('meta_id' => $meta_id, 'msg_type' => $msg_type));
452 } else {
453 foreach ($meta_id as $id) {
454 $this->add_db_event('woocommerce_payment_tokenmeta', array('meta_id' => $id, 'msg_type' => $msg_type));
455 }
456 }
457 }
458
459 function woocommerce_api_product_attribute_handler($id, $data) {
460 $this->add_db_event('woocommerce_attribute_taxonomies', array('attribute_id' => $id));
461 }
462
463 function woocommerce_note_created_handler($note_id) {
464 $this->add_db_event('wc_admin_notes', array('note_id' => $note_id));
465 $this->add_db_event('wc_admin_note_actions', array('note_id' => $note_id));
466 }
467
468 function woocommerce_note_modification_handler($note_id) {
469 if (current_filter() == 'wooocommerce_note_deleted')
470 $msg_type = 'delete';
471 else
472 $msg_type = 'edit';
473 $this->add_db_event('wc_admin_notes', array('note_id' => $note_id, 'msg_type' => $msg_type));
474 $this->add_db_event('wc_admin_note_actions', array('note_id' => $note_id, 'msg_type' => $msg_type));
475 }
476
477 function woocommerce_analytics_order_stats_modification_handler($order_id) {
478 if (current_filter() == 'woocommerce_analytics_delete_order_stats')
479 $msg_type = 'delete';
480 else
481 $msg_type = 'edit';
482 $this->add_db_event('wc_order_stats', array('order_id' => $order_id, 'msg_type' => $msg_type));
483 }
484
485 function woocommerce_analytics_product_update_handler($order_item_id, $order_id) {
486 $this->add_db_event('wc_order_product_lookup', array('order_item_id' => $order_item_id, 'msg_type' => 'edit'));
487 }
488
489 function woocommerce_analytics_product_delete_handler($order_item_id, $order_id) {
490 $this->add_db_event('wc_order_product_lookup', array('order_id' => $order_id, 'msg_type' => 'delete'));
491 }
492
493 function woocommerce_analytics_new_customer_handler($customer_id) {
494 $this->add_db_event('wc_customer_lookup', array('customer_id' => $customer_id));
495 }
496
497 function woocommerce_analytics_customer_modification_handler($customer_id) {
498 if (current_filter() == 'woocommerce_analytics_delete_customer')
499 $msg_type = 'delete';
500 else
501 $msg_type = 'edit';
502 $this->add_db_event('wc_customer_lookup', array('customer_id' => $customer_id, 'msg_type' => $msg_type));
503 }
504
505 function woocommerce_analytics_coupon_update_handler($coupon_id, $order_id) {
506 $this->add_db_event('wc_order_coupon_lookup', array('coupon_id' => $coupon_id, 'order_id' => $order_id, 'msg_type' => 'edit'));
507 }
508
509 function woocommerce_analytics_coupon_delete_handler($coupon_id, $order_id) {
510 $this->add_db_event('wc_order_coupon_lookup', array('order_id' => $order_id, 'msg_type' => 'delete'));
511 }
512
513 function woocommerce_analytics_tax_update_handler($tax_rate_id, $order_id) {
514 $this->add_db_event('wc_order_tax_lookup', array('tax_rate_id' => $tax_rate_id, 'order_id' => $order_id, 'msg_type' => 'edit'));
515 }
516
517 function woocommerce_analytics_tax_delete_handler($tax_rate_id, $order_id) {
518 $this->add_db_event('wc_order_tax_lookup', array('order_id' => $order_id, 'msg_type' => 'delete'));
519 }
520
521 function woocommerce_product_update_handler($product_id, $meta_key = null) {
522 $this->add_db_event('wc_product_meta_lookup', array('product_id' => $product_id, 'msg_type' => 'edit'));
523 if(!empty($meta_key)) {
524 $args = array($this->db->getWPTable('postmeta'), $product_id, $meta_key);
525 $query = "SELECT meta_id FROM %i WHERE post_id = %d AND meta_key = %s";
526 $meta_ids = $this->db->getResult($query, $args);
527 $this->postmeta_action_handler(array_column($meta_ids, 'meta_id'), null, $meta_key);
528 }
529 }
530
531 function woocommerce_product_stock_update_handler($product_id) {
532 $this->woocommerce_product_update_handler($product_id, '_stock');
533 }
534
535 function woocommerce_product_sales_update_handler($product_id) {
536 $this->woocommerce_product_update_handler($product_id, 'total_sales');
537 }
538
539 function woocommerce_product_price_update_handler($product_id) {
540 $this->woocommerce_product_update_handler($product_id);
541 }
542
543 function woocommerce_trash_untrash_post_handler($post_id) {
544 if (!$post_id) {
545 return;
546 }
547 $table = $this->db->dbprefix() . 'posts';
548 $query = "SELECT ID FROM %i WHERE post_type = 'shop_order_refund' AND post_parent = %d";
549 $results = $this->db->getResult($query, array($table, $post_id));
550 foreach ($results as $post) {
551 $this->add_db_event('posts', array('ID' => $post['ID']));
552 }
553 }
554
555 function woocommerce_product_and_order_actions_handler($post_id, $arg = null) {
556 $this->add_db_event('posts', array('ID' => $post_id));
557 }
558
559 function woocommerce_payment_token_set_default_handler($token_id, $token) {
560 $query = "SELECT user_id FROM %i WHERE token_id = %d";
561 $args = array($this->db->getWPTable('woocommerce_payment_tokens'), $token_id);
562 $results = $this->db->getResult($query, $args);
563 $user_ids = array();
564 foreach ($results as $tok) {
565 if (!in_array($tok['user_id'], $user_ids, true)) {
566 $user_ids[] = $tok['user_id'];
567 $this->add_db_event('woocommerce_payment_tokens', array('user_id' => $tok['user_id']));
568 }
569 }
570 }
571
572 function woocommerce_grant_product_download_permissions_handler($order_id) {
573 $this->add_db_event('woocommerce_downloadable_product_permissions', array('order_id' => $order_id));
574 }
575
576 /* ADDING ACTION AND LISTENERS FOR CAPTURING EVENTS. */
577 public function add_actions_and_listeners() {
578 /* CAPTURING EVENTS FOR WP_COMMENTS TABLE */
579 add_action('delete_comment', array($this, 'comment_action_handler'));
580 add_action('wp_set_comment_status', array($this, 'comment_action_handler'));
581 add_action('trashed_comment', array($this, 'comment_action_handler'));
582 add_action('untrashed_comment', array($this, 'comment_action_handler'));
583 add_action('wp_insert_comment', array($this, 'comment_action_handler'));
584 add_action('comment_post', array($this, 'comment_action_handler'));
585 add_action('edit_comment', array($this, 'comment_action_handler'));
586
587 /* CAPTURING EVENTS FOR WP_COMMENTMETA TABLE */
588 add_action('added_comment_meta', array($this, 'commentmeta_insert_handler' ), 10, 2);
589 add_action('updated_comment_meta', array($this, 'commentmeta_modification_handler'), 10, 4);
590 add_action('deleted_comment_meta', array($this, 'commentmeta_modification_handler'), 10, 4);
591
592 /* CAPTURING EVENTS FOR WP_USERMETA TABLE */
593 add_action('added_user_meta', array($this, 'usermeta_insert_handler' ), 10, 2);
594 add_action('updated_user_meta', array($this, 'usermeta_modification_handler' ), 10, 4);
595 add_action('deleted_user_meta', array($this, 'usermeta_modification_handler' ), 10, 4);
596 add_action('added_usermeta', array( $this, 'usermeta_modification_handler'), 10, 4);
597 add_action('update_usermeta', array( $this, 'usermeta_modification_handler'), 10, 4);
598 add_action('delete_usermeta', array( $this, 'usermeta_modification_handler'), 10, 4);
599
600 /* CAPTURING EVENTS FOR WP_USERS TABLE */
601 add_action('user_register', array($this, 'userid_action_handler'));
602 add_action('password_reset', array($this, 'userid_action_handler'));
603 add_action('profile_update', array($this, 'userid_action_handler'));
604 add_action('deleted_user', array($this, 'userid_action_handler'));
605
606 /* CAPTURING EVENTS FOR WP_POSTS TABLE */
607 add_action('delete_post', array($this, 'post_action_handler'));
608 add_action('trash_post', array($this, 'post_action_handler'));
609 add_action('untrash_post', array($this, 'post_action_handler'));
610 add_action('edit_post', array($this, 'post_action_handler'));
611 add_action('save_post', array($this, 'post_action_handler'));
612 add_action('wp_insert_post', array($this, 'post_action_handler'));
613 add_action('edit_attachment', array($this, 'post_action_handler'));
614 add_action('add_attachment', array($this, 'post_action_handler'));
615 add_action('delete_attachment', array($this, 'post_action_handler'));
616 add_action('private_to_publish', array($this, 'post_action_handler'));
617 add_action('wp_restore_post_revision', array($this, 'post_action_handler'));
618
619 /* CAPTURING EVENTS FOR WP_POSTMETA TABLE */
620 // Why events for both delete and deleted
621 add_action('added_post_meta', array($this, 'postmeta_insert_handler'), 10, 4);
622 add_action('update_post_meta', array($this, 'postmeta_modification_handler'), 10, 4);
623 add_action('updated_post_meta', array($this, 'postmeta_modification_handler'), 10, 4);
624 add_action('delete_post_meta', array($this, 'postmeta_modification_handler'), 10, 4);
625 add_action('deleted_post_meta', array($this, 'postmeta_modification_handler'), 10, 4);
626 add_action('added_postmeta', array($this, 'postmeta_action_handler'), 10, 3);
627 add_action('update_postmeta', array($this, 'postmeta_action_handler'), 10, 3);
628 add_action('delete_postmeta', array($this, 'postmeta_action_handler'), 10, 3);
629
630 /* CAPTURING EVENTS FOR WP_LINKS TABLE */
631 add_action('edit_link', array($this, 'link_action_handler'));
632 add_action('add_link', array($this, 'link_action_handler'));
633 add_action('delete_link', array($this, 'link_action_handler'));
634
635 /* CAPTURING EVENTS FOR WP_TERM AND WP_TERM_TAXONOMY TABLE */
636 add_action('created_term', array($this, 'term_handler'), 10, 3);
637 add_action('edited_term', array( $this, 'term_handler' ), 10, 3);
638 add_action('edited_terms', array($this, 'edited_terms_handler'), 10, 2);
639 add_action('delete_term', array($this, 'delete_term_handler'), 10, 4);
640 add_action('edit_term_taxonomy', array($this, 'term_taxonomy_handler'), 10, 2);
641 add_action('delete_term_taxonomy', array($this, 'term_taxonomy_handler'));
642 add_action('edit_term_taxonomies', array($this, 'term_taxonomies_handler'));
643 add_action('add_term_relationship', array($this, 'term_relationship_handler'), 10, 2);
644 add_action('delete_term_relationships', array($this, 'term_relationships_handler'), 10, 2);
645 add_action('set_object_terms', array($this, 'set_object_terms_handler'), 10, 3);
646
647 add_action('switch_theme', array($this, 'theme_action_handler'));
648 add_action('activate_plugin', array($this, 'plugin_action_handler'));
649 add_action('deactivate_plugin', array($this, 'plugin_action_handler'));
650
651 /* CAPTURING EVENTS FOR WP_OPTIONS */
652 add_action('deleted_option', array($this, 'option_handler'));
653 add_action('updated_option', array($this, 'option_handler'));
654 add_action('added_option', array($this, 'option_handler'));
655
656 /* CAPTURING EVENTS FOR FILES UPLOAD */
657 add_action('wp_handle_upload', array($this, 'upload_handler'));
658 add_action('wp_update_attachment_metadata', array($this, 'attachment_metadata_handler'), 10, 2);
659
660 /* These are applicable only in case of WPMU */
661 /* XNOTE: Handle registration_log_handler from within the server */
662 add_action('wpmu_new_blog', array($this, 'wpmu_new_blog_create_handler'), 10, 1);
663 add_action('delete_site_option',array($this, 'sitemeta_handler'), 10, 1);
664 add_action('add_site_option', array($this, 'sitemeta_handler'), 10, 1);
665 add_action('update_site_option', array($this, 'sitemeta_handler'), 10, 1);
666
667 /* CAPTURING EVENTS FOR WOOCOMMERCE */
668 add_action('woocommerce_remove_order_items', array($this, 'woocommerce_remove_order_items_handler'), 10, 2);
669 add_action('woocommerce_update_order', array($this, 'woocommerce_update_order_handler'), 10, 2);
670 add_action('woocommerce_delete_order', array($this, 'woocommerce_delete_order_handler'), 10, 1);
671 add_action('woocommerce_trash_order', array($this, 'woocommerce_trash_order_handler'), 10, 1);
672 add_action('woocommerce_resume_order', array($this, 'woocommerce_resume_order_handler'), 10, 1);
673 add_action('woocommerce_new_order_item', array($this, 'woocommerce_new_order_item_handler'), 10, 3);
674 add_action('woocommerce_update_order_item', array($this, 'woocommerce_update_order_item_handler'), 10, 2);
675 add_action('woocommerce_delete_order_item', array($this, 'woocommerce_delete_order_item_handler'), 10, 1);
676 add_action('woocommerce_delete_order_items', array($this, 'woocommerce_delete_order_items_handler'), 10, 1);
677 add_action('added_order_item_meta', array($this, 'woocommerce_order_term_meta_handler' ), 10, 4);
678 add_action('updated_order_item_meta', array($this, 'woocommerce_order_term_meta_handler'), 10, 4);
679 add_action('deleted_order_item_meta', array($this, 'woocommerce_order_term_meta_handler'), 10, 4);
680
681 add_action('woocommerce_attribute_added', array($this, 'woocommerce_attribute_added_handler' ), 10, 2 );
682 add_action('woocommerce_attribute_updated', array($this, 'woocommerce_attribute_updated_handler'), 10, 3 );
683 add_action('woocommerce_attribute_deleted', array($this, 'woocommerce_attribute_deleted_handler'), 10, 3 );
684
685 add_action('woocommerce_tax_rate_added', array($this, 'woocommerce_tax_rate_handler'), 10, 2);
686 add_action('woocommerce_tax_rate_deleted', array($this, 'woocommerce_tax_rate_deleted_handler'), 10, 1);
687 add_action('woocommerce_tax_rate_updated', array($this, 'woocommerce_tax_rate_handler'), 10, 2);
688
689 add_action('woocommerce_new_webhook', array($this, 'woocommerce_webhook_handler'), 10, 1);
690 add_action('woocommerce_webhook_updated', array($this, 'woocommerce_webhook_handler'), 10, 1);
691 add_action('woocommerce_webhook_deleted', array($this, 'woocommerce_webhook_delete_handler'), 10, 2);
692
693 add_action('woocommerce_download_product', array($this, 'woocommerce_download_product_handler'), 10, 6);
694 add_action('woocommerce_grant_product_download_access', array($this, 'woocommerce_grant_product_download_access_handler'), 10, 1);
695 add_action('woocommerce_ajax_revoke_access_to_product_download', array($this, 'woocommerce_revoke_access_to_product_download_handler'), 10, 4);
696 add_action('woocommerce_deleted_order_downloadable_permissions', array($this, 'woocommerce_deleted_order_downloadable_permissions_handler'), 10, 1);
697
698 add_action('woocommerce_new_payment_token', array($this, 'woocommerce_payment_token_handler'), 10, 1);
699 add_action('woocommerce_payment_token_created', array($this, 'woocommerce_payment_token_handler'), 10, 1);
700 add_action('woocommerce_payment_token_updated', array($this, 'woocommerce_payment_token_handler'), 10, 1);
701 add_action('woocommerce_payment_token_deleted', array($this, 'woocommerce_payment_token_deleted_handler'), 10, 2);
702 add_action('added_payment_token_meta', array($this, 'woocommerce_payment_token_meta_handler' ), 10, 4);
703 add_action('updated_payment_token_meta', array($this, 'woocommerce_payment_token_meta_handler'), 10, 4);
704 add_action('deleted_payment_token_meta', array($this, 'woocommerce_payment_token_meta_handler'), 10, 4);
705
706 add_action('woocommerce_shipping_zone_method_added', array($this, 'woocommerce_shipping_zone_method_added_handler'), 10, 3);
707 add_action('woocommerce_shipping_zone_method_status_toggled', array($this, 'woocommerce_shipping_zone_method_status_toggled_handler'), 10, 4);
708 add_action('woocommerce_shipping_zone_method_deleted', array($this, 'woocommerce_shipping_zone_method_deleted_handler'), 10, 3);
709
710 add_action('woocommerce_delete_shipping_zone', array($this, 'woocommerce_delete_shipping_zone_handler'), 10, 1);
711 add_action('woocommerce_delete_shipping_zone_method', array($this, 'woocommerce_delete_shipping_zone_method_handler'), 10, 1);
712
713 add_action('woocommerce_api_create_product_attribute', array($this, 'woocommerce_api_product_attribute_handler'), 10, 2);
714 add_action('woocommerce_api_edit_product_attribute', array($this, 'woocommerce_api_product_attribute_handler'), 10, 2);
715
716 add_action('woocommerce_note_created', array($this, 'woocommerce_note_created_handler'), 10, 1);
717 add_action('woocommerce_note_updated', array($this, 'woocommerce_note_modification_handler'), 10, 1);
718 add_action('woocommerce_note_deleted', array($this, 'woocommerce_note_modification_handler'), 10, 1);
719
720 add_action('woocommerce_analytics_update_order_stats', array($this, 'woocommerce_analytics_order_stats_modification_handler'), 10, 1);
721 add_action('woocommerce_analytics_delete_order_stats', array($this, 'woocommerce_analytics_order_stats_modification_handler'), 10, 1);
722
723 add_action('woocommerce_analytics_update_product', array($this, 'woocommerce_analytics_product_update_handler'), 10, 2);
724 add_action('woocommerce_analytics_delete_product', array($this, 'woocommerce_analytics_product_delete_handler'), 10, 2);
725
726 add_action('woocommerce_analytics_new_customer', array($this, 'woocommerce_analytics_new_customer_handler'), 10, 1);
727 add_action('woocommerce_analytics_update_customer', array($this, 'woocommerce_analytics_customer_modification_handler'), 10, 1);
728 add_action('woocommerce_analytics_delete_customer', array($this, 'woocommerce_analytics_customer_modification_handler'), 10, 1);
729
730 add_action('woocommerce_analytics_update_coupon', array($this, 'woocommerce_analytics_coupon_update_handler'), 10, 2);
731 add_action('woocommerce_analytics_delete_coupon', array($this, 'woocommerce_analytics_coupon_delete_handler'), 10, 2);
732
733 add_action('woocommerce_analytics_update_tax', array($this, 'woocommerce_analytics_tax_update_handler'), 10, 2);
734 add_action('woocommerce_analytics_delete_tax', array($this, 'woocommerce_analytics_tax_delete_handler'), 10, 2);
735
736 add_action('woocommerce_updated_product_stock', array($this, 'woocommerce_product_stock_update_handler'), 10, 1);
737 add_action('woocommerce_updated_product_sales', array($this, 'woocommerce_product_sales_update_handler'), 10, 1);
738 add_action('woocommerce_updated_product_price', array($this, 'woocommerce_product_price_update_handler'), 10, 1);
739
740 add_action('wp_trash_post', array($this, 'woocommerce_trash_untrash_post_handler'), 10, 1);
741 add_action('untrashed_post', array($this, 'woocommerce_trash_untrash_post_handler'), 10, 1);
742
743 add_action('woocommerce_after_single_product_ordering', array($this, 'woocommerce_product_and_order_actions_handler'), 10, 2);
744 add_action('woocommerce_update_product', array($this, 'woocommerce_product_and_order_actions_handler'), 10, 2);
745 add_action('woocommerce_update_product_variation', array($this, 'woocommerce_product_and_order_actions_handler'), 10, 2);
746
747 add_action('woocommerce_payment_token_set_default', array($this, 'woocommerce_payment_token_set_default_handler'), 10, 2);
748 add_action('woocommerce_grant_product_download_permissions', array($this, 'woocommerce_grant_product_download_permissions_handler'), 10, 1);
749 }
750 }
751 endif;