PluginProbe
The WP Remote WordPress Plugin / 5.09
The WP Remote WordPress Plugin v5.09
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.09, at wp_dynsync.php

704 lines 33.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('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 woocommerce_resume_order_handler($order_id) {
260 $this->add_db_event('woocommerce_order_items', array('order_id' => $order_id, 'msg_type' => 'delete'));
261 $meta_ids = array();
262 $itemmeta_table = $this->db->getWPTable('woocommerce_order_itemmeta');
263 $items_table = $this->db->getWPTable('woocommerce_order_items');
264 foreach( $this->db->getResult($this->db->prepare("SELECT {$itemmeta_table}.meta_id FROM {$itemmeta_table} INNER JOIN {$items_table} WHERE {$items_table}.order_item_id = {$itemmeta_table}.order_item_id AND {$items_table}.order_id = %d", $order_id)) as $key => $row) {
265 if (!in_array($row->meta_id, $meta_ids, true)) {
266 $meta_ids[] = $row->meta_id;
267 $this->add_db_event('woocommerce_order_itemmeta', array('meta_id' => $row->meta_id, 'msg_type' => 'delete'));
268 }
269 }
270 }
271
272 function woocommerce_update_order_handler($order_id, $order = null) {
273 $this->add_db_event('wc_orders', array('id' => $order_id));
274 $this->add_db_event('wc_orders_meta', array('order_id' => $order_id));
275 $this->add_db_event('wc_order_addresses', array('order_id' => $order_id));
276 $this->add_db_event('wc_order_operational_data', array('order_id' => $order_id));
277 }
278
279 function woocommerce_trash_order_handler($order_id) {
280 $this->add_db_event('wc_orders', array('id' => $order_id));
281 $this->add_db_event('wc_orders_meta', array('order_id' => $order_id));
282 }
283
284 function woocommerce_delete_order_handler($order_id) {
285 $this->add_db_event('wc_orders', array('id' => $order_id, 'msg_type' => 'delete'));
286 $this->add_db_event('wc_orders_meta', array('order_id' => $order_id, 'msg_type' => 'delete'));
287 $this->add_db_event('wc_order_addresses', array('order_id' => $order_id, 'msg_type' => 'delete'));
288 $this->add_db_event('wc_order_operational_data', array('order_id' => $order_id, 'msg_type' => 'delete'));
289 }
290
291 function woocommerce_new_order_item_handler($item_id, $item, $order_id) {
292 $this->add_db_event('woocommerce_order_items', array('order_item_id' => $item_id));
293 $this->add_db_event('woocommerce_order_itemmeta', array('order_item_id' => $item_id));
294 }
295
296 function woocommerce_update_order_item_handler($item_id, $args){
297 $this->add_db_event('woocommerce_order_items', array('order_item_id' => $item_id));
298 }
299
300 function woocommerce_delete_order_item_handler($item_id) {
301 $this->add_db_event('woocommerce_order_itemmeta', array('order_item_id' => $item_id, 'msg_type' => 'delete'));
302 $this->add_db_event('woocommerce_order_items', array('order_item_id' => $item_id, 'msg_type' => 'delete'));
303 }
304
305 function woocommerce_attribute_added_handler($attribute_id, $attribute) {
306 $this->add_db_event('woocommerce_attribute_taxonomies', array('attribute_id' => $attribute_id));
307 }
308
309 function woocommerce_attribute_updated_handler($attribute_id, $attribute, $old_attribute_name) {
310 $this->add_db_event('woocommerce_attribute_taxonomies', array('attribute_id' => $attribute_id));
311 # $woocommerce->attribute_taxonomy_name( $attribute_name )
312 $this->add_db_event('term_taxonomy', array('taxonomy' => wc_attribute_taxonomy_name($attribute['attribute_name'])));
313 # sanitize_title( $attribute_name )
314 $this->add_db_event('woocommerce_termmeta', array('meta_key' => 'order_pa_' . $attribute['attribute_name']));#deprecated
315 $this->add_db_event('termmeta', array('meta_key' => 'order_pa_' . $attribute['attribute_name']));
316 $this->add_db_event('postmeta', array('meta_key' => '_product_attributes'));
317 # sanitize_title( $attribute_name )
318 $this->add_db_event('postmeta', array('meta_key' => 'attribute_pa_' . $attribute['attribute_name']));
319 }
320
321 function woocommerce_attribute_deleted_handler($attribute_id, $attribute_name, $taxonomy) {
322 return $this->add_db_event('woocommerce_attribute_taxonomies', array('attribute_id' => $attribute_id, 'msg_type' => 'delete'));
323 }
324
325 function woocommerce_revoke_access_to_product_download_handler($download_id, $product_id, $order_id, $permission_id ) {
326 $this->add_db_event('woocommerce_downloadable_product_permissions', array('permission_id' => $permission_id, 'msg_type' => 'delete'));
327 }
328
329 function woocommerce_tax_rate_handler($tax_rate_id, $_tax_rate) {
330 $this->add_db_event('woocommerce_tax_rates', array('tax_rate_id' => $tax_rate_id));
331 $this->add_db_event('woocommerce_tax_rate_locations', array('tax_rate_id' => $tax_rate_id));
332 }
333
334 function woocommerce_tax_rate_deleted_handler($tax_rate_id) {
335 $this->add_db_event('woocommerce_tax_rates', array('tax_rate_id' => $tax_rate_id, 'msg_type' => 'delete'));
336 $this->add_db_event('woocommerce_tax_rate_locations', array('tax_rate_id' => $tax_rate_id, 'msg_type' => 'delete'));
337 }
338
339 function woocommerce_grant_product_download_access_handler($data) {
340 $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']));
341 }
342
343 function woocommerce_download_product_handler($user_email, $order_key, $product_id, $user_id, $download_id, $order_id) {
344 $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));
345 }
346
347 function woocommerce_delete_order_items_handler($postid) {
348 $meta_ids = array();
349 $order_item_ids = array();
350 foreach( $this->db->getResult("SELECT {$this->db->dbprefix()}woocommerce_order_itemmeta.meta_id, {$this->db->dbprefix()}woocommerce_order_items.order_item_id FROM {$this->db->dbprefix()}woocommerce_order_items JOIN {$this->db->dbprefix()}woocommerce_order_itemmeta ON {$this->db->dbprefix()}woocommerce_order_items.order_item_id = {$this->db->dbprefix()}woocommerce_order_itemmeta.order_item_id WHERE {$this->db->dbprefix()}woocommerce_order_items.order_id = '{$postid}'") as $key => $row) {
351 if (!in_array($row['meta_id'], $meta_ids, true)) {
352 $meta_ids[] = $row['meta_id'];
353 $this->add_db_event('woocommerce_order_itemmeta', array('meta_id' => $row['meta_id'], 'msg_type' => 'delete'));
354 }
355 if (!in_array($row['order_item_id'], $order_item_ids, true)) {
356 $order_item_ids[] = $row['order_item_id'];
357 $this->add_db_event('woocommerce_order_items', array('order_item_id' => $row['order_item_id'], 'msg_type' => 'delete'));
358 }
359 }
360 }
361
362 function woocommerce_payment_token_handler($token_id) {
363 $this->add_db_event('woocommerce_payment_tokens', array('token_id' => $token_id));
364 }
365
366 function woocommerce_payment_token_deleted_handler($token_id, $object) {
367 $this->add_db_event('woocommerce_payment_tokens', array('token_id' => $token_id, 'msg_type' => 'delete'));
368 $this->add_db_event('woocommerce_payment_tokenmeta', array('payment_token_id' => $token_id, 'msg_type' => 'delete'));
369 }
370
371 function woocommerce_shipping_zone_method_added_handler($instance_id, $method_id, $zone_id) {
372 $this->add_db_event('woocommerce_shipping_zone_methods', array('instance_id' => $instance_id));
373 $this->add_db_event('woocommerce_shipping_zones', array('zone_id' => $zone_id));
374 $this->add_db_event('woocommerce_shipping_zone_locations', array('zone_id' => $zone_id));
375 }
376
377 function woocommerce_shipping_zone_method_deleted_handler($instance_id, $method_id, $zone_id) {
378 $this->add_db_event('woocommerce_shipping_zone_methods', array('instance_id' => $instance_id, 'msg_type' => 'delete'));
379 }
380
381 function woocommerce_shipping_zone_method_status_toggled_handler($instance_id, $method_id, $zone_id, $is_enabled) {
382 $this->add_db_event('woocommerce_shipping_zone_methods', array('instance_id' => absint( $instance_id )));
383 }
384
385 function woocommerce_deleted_order_downloadable_permissions_handler($post_id) {
386 $this->add_db_event('woocommerce_downloadable_product_permissions', array('order_id' => $post_id, 'msg_type' => 'delete'));
387 }
388
389 function woocommerce_delete_shipping_zone_handler($zone_id) {
390 $this->add_db_event('woocommerce_shipping_zone_methods', array('zone_id' => $zone_id, 'msg_type' => 'delete'));
391 $this->add_db_event('woocommerce_shipping_zone_locations', array('zone_id' => $zone_id, 'msg_type' => 'delete'));
392 $this->add_db_event('woocommerce_shipping_zones', array('zone_id' => $zone_id, 'msg_type' => 'delete'));
393 }
394
395 function woocommerce_webhook_handler($webhook_id) {
396 $this->add_db_event('wc_webhooks', array('webhook_id' => $webhook_id));
397 }
398
399 function woocommerce_webhook_delete_handler($webhook_id, $webhook) {
400 $this->add_db_event('wc_webhooks', array('webhook_id' => $webhook_id, 'msg_type' => 'delete'));
401 }
402
403 function woocommerce_delete_shipping_zone_method_handler($instance_id) {
404 $this->add_db_event('woocommerce_shipping_zone_methods', array('instance_id' => $instance_id, 'msg_type' => 'delete'));
405 }
406
407 function woocommerce_order_term_meta_handler($meta_id, $object_id, $meta_key, $meta_value) {
408 if (current_filter() == 'deleted_order_item_meta')
409 $msg_type = 'delete';
410 else
411 $msg_type = 'edit';
412 if (!is_array($meta_id)) {
413 $this->add_db_event('woocommerce_order_itemmeta', array('meta_id' => $meta_id, 'msg_type' => $msg_type));
414 } else {
415 foreach ($meta_id as $id) {
416 $this->add_db_event('woocommerce_order_itemmeta', array('meta_id' => $id, 'msg_type' => $msg_type));
417 }
418 }
419 }
420
421 function woocommerce_payment_token_meta_handler($meta_id, $object_id, $meta_key, $meta_value) {
422 if (current_filter() == 'deleted_payment_token_meta')
423 $msg_type = 'delete';
424 else
425 $msg_type = 'edit';
426 if (!is_array($meta_id)) {
427 $this->add_db_event('woocommerce_payment_tokenmeta', array('meta_id' => $meta_id, 'msg_type' => $msg_type));
428 } else {
429 foreach ($meta_id as $id) {
430 $this->add_db_event('woocommerce_payment_tokenmeta', array('meta_id' => $id, 'msg_type' => $msg_type));
431 }
432 }
433 }
434
435 function woocommerce_api_product_attribute_handler($id, $data) {
436 $this->add_db_event('woocommerce_attribute_taxonomies', array('attribute_id' => $id));
437 }
438
439 function woocommerce_note_created_handler($note_id) {
440 $this->add_db_event('wc_admin_notes', array('note_id' => $note_id));
441 $this->add_db_event('wc_admin_note_actions', array('note_id' => $note_id));
442 }
443
444 function woocommerce_note_modification_handler($note_id) {
445 if (current_filter() == 'wooocommerce_note_deleted')
446 $msg_type = 'delete';
447 else
448 $msg_type = 'edit';
449 $this->add_db_event('wc_admin_notes', array('note_id' => $note_id, 'msg_type' => $msg_type));
450 $this->add_db_event('wc_admin_note_actions', array('note_id' => $note_id, 'msg_type' => $msg_type));
451 }
452
453 function woocommerce_analytics_order_stats_modification_handler($order_id) {
454 if (current_filter() == 'woocommerce_analytics_delete_order_stats')
455 $msg_type = 'delete';
456 else
457 $msg_type = 'edit';
458 $this->add_db_event('wc_order_stats', array('order_id' => $order_id, 'msg_type' => $msg_type));
459 }
460
461 function woocommerce_analytics_product_update_handler($order_item_id, $order_id) {
462 $this->add_db_event('wc_order_product_lookup', array('order_item_id' => $order_item_id, 'msg_type' => 'edit'));
463 }
464
465 function woocommerce_analytics_product_delete_handler($order_item_id, $order_id) {
466 $this->add_db_event('wc_order_product_lookup', array('order_id' => $order_id, 'msg_type' => 'delete'));
467 }
468
469 function woocommerce_analytics_new_customer_handler($customer_id) {
470 $this->add_db_event('wc_customer_lookup', array('customer_id' => $customer_id));
471 }
472
473 function woocommerce_analytics_customer_modification_handler($customer_id) {
474 if (current_filter() == 'woocommerce_analytics_delete_customer')
475 $msg_type = 'delete';
476 else
477 $msg_type = 'edit';
478 $this->add_db_event('wc_customer_lookup', array('customer_id' => $customer_id, 'msg_type' => $msg_type));
479 }
480
481 function woocommerce_analytics_coupon_update_handler($coupon_id, $order_id) {
482 $this->add_db_event('wc_order_coupon_lookup', array('coupon_id' => $coupon_id, 'order_id' => $order_id, 'msg_type' => 'edit'));
483 }
484
485 function woocommerce_analytics_coupon_delete_handler($coupon_id, $order_id) {
486 $this->add_db_event('wc_order_coupon_lookup', array('order_id' => $order_id, 'msg_type' => 'delete'));
487 }
488
489 function woocommerce_analytics_tax_update_handler($tax_rate_id, $order_id) {
490 $this->add_db_event('wc_order_tax_lookup', array('tax_rate_id' => $tax_rate_id, 'order_id' => $order_id, 'msg_type' => 'edit'));
491 }
492
493 function woocommerce_analytics_tax_delete_handler($tax_rate_id, $order_id) {
494 $this->add_db_event('wc_order_tax_lookup', array('order_id' => $order_id, 'msg_type' => 'delete'));
495 }
496
497 function woocommerce_product_update_handler($product_id) {
498 $this->add_db_event('wc_product_meta_lookup', array('product_id' => $product_id, 'msg_type' => 'edit'));
499 }
500
501 function woocommerce_trash_untrash_post_handler($post_id) {
502 if (!$post_id) {
503 return;
504 }
505 $results = $this->db->getResult($this->db->prepare("SELECT ID FROM {$this->db->dbprefix()}posts WHERE post_type = 'shop_order_refund' AND post_parent = %d", $post_id));
506 foreach ( $results as $post ) {
507 $this->add_db_event('posts', array('ID' => $post['ID']));
508 }
509 }
510
511 function woocommerce_product_and_order_actions_handler($post_id, $arg = null) {
512 $this->add_db_event('posts', array('ID' => $post_id));
513 }
514
515 function woocommerce_payment_token_set_default_handler($token_id, $token) {
516 $results = $this->db->getResult($this->db->prepare("SELECT user_id FROM {$this->db->dbprefix()}woocommerce_payment_tokens WHERE token_id = %d", $token_id));
517 $user_ids = array();
518 foreach ( $results as $tok ){
519 if (!in_array($tok['user_id'], $user_ids, true)) {
520 $user_ids[] = $tok['user_id'];
521 $this->add_db_event('woocommerce_payment_tokens', array('user_id' => $tok['user_id']));
522 }
523 }
524 }
525
526 function woocommerce_grant_product_download_permissions_handler($order_id) {
527 $this->add_db_event('woocommerce_downloadable_product_permissions', array('order_id' => $order_id));
528 }
529
530 /* ADDING ACTION AND LISTENERS FOR CAPTURING EVENTS. */
531 public function add_actions_and_listeners() {
532 /* CAPTURING EVENTS FOR WP_COMMENTS TABLE */
533 add_action('delete_comment', array($this, 'comment_action_handler'));
534 add_action('wp_set_comment_status', array($this, 'comment_action_handler'));
535 add_action('trashed_comment', array($this, 'comment_action_handler'));
536 add_action('untrashed_comment', array($this, 'comment_action_handler'));
537 add_action('wp_insert_comment', array($this, 'comment_action_handler'));
538 add_action('comment_post', array($this, 'comment_action_handler'));
539 add_action('edit_comment', array($this, 'comment_action_handler'));
540
541 /* CAPTURING EVENTS FOR WP_COMMENTMETA TABLE */
542 add_action('added_comment_meta', array($this, 'commentmeta_insert_handler' ), 10, 2);
543 add_action('updated_comment_meta', array($this, 'commentmeta_modification_handler'), 10, 4);
544 add_action('deleted_comment_meta', array($this, 'commentmeta_modification_handler'), 10, 4);
545
546 /* CAPTURING EVENTS FOR WP_USERMETA TABLE */
547 add_action('added_user_meta', array($this, 'usermeta_insert_handler' ), 10, 2);
548 add_action('updated_user_meta', array($this, 'usermeta_modification_handler' ), 10, 4);
549 add_action('deleted_user_meta', array($this, 'usermeta_modification_handler' ), 10, 4);
550 add_action('added_usermeta', array( $this, 'usermeta_modification_handler'), 10, 4);
551 add_action('update_usermeta', array( $this, 'usermeta_modification_handler'), 10, 4);
552 add_action('delete_usermeta', array( $this, 'usermeta_modification_handler'), 10, 4);
553
554 /* CAPTURING EVENTS FOR WP_USERS TABLE */
555 add_action('user_register', array($this, 'userid_action_handler'));
556 add_action('password_reset', array($this, 'userid_action_handler'));
557 add_action('profile_update', array($this, 'userid_action_handler'));
558 add_action('deleted_user', array($this, 'userid_action_handler'));
559
560 /* CAPTURING EVENTS FOR WP_POSTS TABLE */
561 add_action('delete_post', array($this, 'post_action_handler'));
562 add_action('trash_post', array($this, 'post_action_handler'));
563 add_action('untrash_post', array($this, 'post_action_handler'));
564 add_action('edit_post', array($this, 'post_action_handler'));
565 add_action('save_post', array($this, 'post_action_handler'));
566 add_action('wp_insert_post', array($this, 'post_action_handler'));
567 add_action('edit_attachment', array($this, 'post_action_handler'));
568 add_action('add_attachment', array($this, 'post_action_handler'));
569 add_action('delete_attachment', array($this, 'post_action_handler'));
570 add_action('private_to_publish', array($this, 'post_action_handler'));
571 add_action('wp_restore_post_revision', array($this, 'post_action_handler'));
572
573 /* CAPTURING EVENTS FOR WP_POSTMETA TABLE */
574 // Why events for both delete and deleted
575 add_action('added_post_meta', array($this, 'postmeta_insert_handler'), 10, 4);
576 add_action('update_post_meta', array($this, 'postmeta_modification_handler'), 10, 4);
577 add_action('updated_post_meta', array($this, 'postmeta_modification_handler'), 10, 4);
578 add_action('delete_post_meta', array($this, 'postmeta_modification_handler'), 10, 4);
579 add_action('deleted_post_meta', array($this, 'postmeta_modification_handler'), 10, 4);
580 add_action('added_postmeta', array($this, 'postmeta_action_handler'), 10, 3);
581 add_action('update_postmeta', array($this, 'postmeta_action_handler'), 10, 3);
582 add_action('delete_postmeta', array($this, 'postmeta_action_handler'), 10, 3);
583
584 /* CAPTURING EVENTS FOR WP_LINKS TABLE */
585 add_action('edit_link', array($this, 'link_action_handler'));
586 add_action('add_link', array($this, 'link_action_handler'));
587 add_action('delete_link', array($this, 'link_action_handler'));
588
589 /* CAPTURING EVENTS FOR WP_TERM AND WP_TERM_TAXONOMY TABLE */
590 add_action('created_term', array($this, 'term_handler'), 10, 3);
591 add_action('edited_term', array( $this, 'term_handler' ), 10, 3);
592 add_action('edited_terms', array($this, 'edited_terms_handler'), 10, 2);
593 add_action('delete_term', array($this, 'delete_term_handler'), 10, 4);
594 add_action('edit_term_taxonomy', array($this, 'term_taxonomy_handler'), 10, 2);
595 add_action('delete_term_taxonomy', array($this, 'term_taxonomy_handler'));
596 add_action('edit_term_taxonomies', array($this, 'term_taxonomies_handler'));
597 add_action('add_term_relationship', array($this, 'term_relationship_handler'), 10, 2);
598 add_action('delete_term_relationships', array($this, 'term_relationships_handler'), 10, 2);
599 add_action('set_object_terms', array($this, 'set_object_terms_handler'), 10, 3);
600
601 add_action('switch_theme', array($this, 'theme_action_handler'));
602 add_action('activate_plugin', array($this, 'plugin_action_handler'));
603 add_action('deactivate_plugin', array($this, 'plugin_action_handler'));
604
605 /* CAPTURING EVENTS FOR WP_OPTIONS */
606 add_action('deleted_option', array($this, 'option_handler'));
607 add_action('updated_option', array($this, 'option_handler'));
608 add_action('added_option', array($this, 'option_handler'));
609
610 /* CAPTURING EVENTS FOR FILES UPLOAD */
611 add_action('wp_handle_upload', array($this, 'upload_handler'));
612 add_action('wp_update_attachment_metadata', array($this, 'attachment_metadata_handler'), 10, 2);
613
614 /* These are applicable only in case of WPMU */
615 /* XNOTE: Handle registration_log_handler from within the server */
616 add_action('wpmu_new_blog', array($this, 'wpmu_new_blog_create_handler'), 10, 1);
617 add_action('delete_site_option',array($this, 'sitemeta_handler'), 10, 1);
618 add_action('add_site_option', array($this, 'sitemeta_handler'), 10, 1);
619 add_action('update_site_option', array($this, 'sitemeta_handler'), 10, 1);
620
621 /* CAPTURING EVENTS FOR WOOCOMMERCE */
622 add_action('woocommerce_update_order', array($this, 'woocommerce_update_order_handler'), 10, 2);
623 add_action('woocommerce_delete_order', array($this, 'woocommerce_delete_order_handler'), 10, 1);
624 add_action('woocommerce_trash_order', array($this, 'woocommerce_trash_order_handler'), 10, 1);
625 add_action('woocommerce_resume_order', array($this, 'woocommerce_resume_order_handler'), 10, 1);
626 add_action('woocommerce_new_order_item', array($this, 'woocommerce_new_order_item_handler'), 10, 3);
627 add_action('woocommerce_update_order_item', array($this, 'woocommerce_update_order_item_handler'), 10, 2);
628 add_action('woocommerce_delete_order_item', array($this, 'woocommerce_delete_order_item_handler'), 10, 1);
629 add_action('woocommerce_delete_order_items', array($this, 'woocommerce_delete_order_items_handler'), 10, 1);
630 add_action('added_order_item_meta', array($this, 'woocommerce_order_term_meta_handler' ), 10, 4);
631 add_action('updated_order_item_meta', array($this, 'woocommerce_order_term_meta_handler'), 10, 4);
632 add_action('deleted_order_item_meta', array($this, 'woocommerce_order_term_meta_handler'), 10, 4);
633
634 add_action('woocommerce_attribute_added', array($this, 'woocommerce_attribute_added_handler' ), 10, 2 );
635 add_action('woocommerce_attribute_updated', array($this, 'woocommerce_attribute_updated_handler'), 10, 3 );
636 add_action('woocommerce_attribute_deleted', array($this, 'woocommerce_attribute_deleted_handler'), 10, 3 );
637
638 add_action('woocommerce_tax_rate_added', array($this, 'woocommerce_tax_rate_handler'), 10, 2);
639 add_action('woocommerce_tax_rate_deleted', array($this, 'woocommerce_tax_rate_deleted_handler'), 10, 1);
640 add_action('woocommerce_tax_rate_updated', array($this, 'woocommerce_tax_rate_handler'), 10, 2);
641
642 add_action('woocommerce_new_webhook', array($this, 'woocommerce_webhook_handler'), 10, 1);
643 add_action('woocommerce_webhook_updated', array($this, 'woocommerce_webhook_handler'), 10, 1);
644 add_action('woocommerce_webhook_deleted', array($this, 'woocommerce_webhook_delete_handler'), 10, 2);
645
646 add_action('woocommerce_download_product', array($this, 'woocommerce_download_product_handler'), 10, 6);
647 add_action('woocommerce_grant_product_download_access', array($this, 'woocommerce_grant_product_download_access_handler'), 10, 1);
648 add_action('woocommerce_ajax_revoke_access_to_product_download', array($this, 'woocommerce_revoke_access_to_product_download_handler'), 10, 4);
649 add_action('woocommerce_deleted_order_downloadable_permissions', array($this, 'woocommerce_deleted_order_downloadable_permissions_handler'), 10, 1);
650
651 add_action('woocommerce_new_payment_token', array($this, 'woocommerce_payment_token_handler'), 10, 1);
652 add_action('woocommerce_payment_token_created', array($this, 'woocommerce_payment_token_handler'), 10, 1);
653 add_action('woocommerce_payment_token_updated', array($this, 'woocommerce_payment_token_handler'), 10, 1);
654 add_action('woocommerce_payment_token_deleted', array($this, 'woocommerce_payment_token_deleted_handler'), 10, 2);
655 add_action('added_payment_token_meta', array($this, 'woocommerce_payment_token_meta_handler' ), 10, 4);
656 add_action('updated_payment_token_meta', array($this, 'woocommerce_payment_token_meta_handler'), 10, 4);
657 add_action('deleted_payment_token_meta', array($this, 'woocommerce_payment_token_meta_handler'), 10, 4);
658
659 add_action('woocommerce_shipping_zone_method_added', array($this, 'woocommerce_shipping_zone_method_added_handler'), 10, 3);
660 add_action('woocommerce_shipping_zone_method_status_toggled', array($this, 'woocommerce_shipping_zone_method_status_toggled_handler'), 10, 4);
661 add_action('woocommerce_shipping_zone_method_deleted', array($this, 'woocommerce_shipping_zone_method_deleted_handler'), 10, 3);
662
663 add_action('woocommerce_delete_shipping_zone', array($this, 'woocommerce_delete_shipping_zone_handler'), 10, 1);
664 add_action('woocommerce_delete_shipping_zone_method', array($this, 'woocommerce_delete_shipping_zone_method_handler'), 10, 1);
665
666 add_action('woocommerce_api_create_product_attribute', array($this, 'woocommerce_api_product_attribute_handler'), 10, 2);
667 add_action('woocommerce_api_edit_product_attribute', array($this, 'woocommerce_api_product_attribute_handler'), 10, 2);
668
669 add_action('woocommerce_note_created', array($this, 'woocommerce_note_created_handler'), 10, 1);
670 add_action('woocommerce_note_updated', array($this, 'woocommerce_note_modification_handler'), 10, 1);
671 add_action('woocommerce_note_deleted', array($this, 'woocommerce_note_modification_handler'), 10, 1);
672
673 add_action('woocommerce_analytics_update_order_stats', array($this, 'woocommerce_analytics_order_stats_modification_handler'), 10, 1);
674 add_action('woocommerce_analytics_delete_order_stats', array($this, 'woocommerce_analytics_order_stats_modification_handler'), 10, 1);
675
676 add_action('woocommerce_analytics_update_product', array($this, 'woocommerce_analytics_product_update_handler'), 10, 2);
677 add_action('woocommerce_analytics_delete_product', array($this, 'woocommerce_analytics_product_delete_handler'), 10, 2);
678
679 add_action('woocommerce_analytics_new_customer', array($this, 'woocommerce_analytics_new_customer_handler'), 10, 1);
680 add_action('woocommerce_analytics_update_customer', array($this, 'woocommerce_analytics_customer_modification_handler'), 10, 1);
681 add_action('woocommerce_analytics_delete_customer', array($this, 'woocommerce_analytics_customer_modification_handler'), 10, 1);
682
683 add_action('woocommerce_analytics_update_coupon', array($this, 'woocommerce_analytics_coupon_update_handler'), 10, 2);
684 add_action('woocommerce_analytics_delete_coupon', array($this, 'woocommerce_analytics_coupon_delete_handler'), 10, 2);
685
686 add_action('woocommerce_analytics_update_tax', array($this, 'woocommerce_analytics_tax_update_handler'), 10, 2);
687 add_action('woocommerce_analytics_delete_tax', array($this, 'woocommerce_analytics_tax_delete_handler'), 10, 2);
688
689 add_action('woocommerce_updated_product_stock', array($this, 'woocommerce_product_update_handler'), 10, 1);
690 add_action('woocommerce_updated_product_sales', array($this, 'woocommerce_product_update_handler'), 10, 1);
691 add_action('woocommerce_updated_product_price', array($this, 'woocommerce_product_update_handler'), 10, 1);
692
693 add_action('wp_trash_post', array($this, 'woocommerce_trash_untrash_post_handler'), 10, 1);
694 add_action('untrashed_post', array($this, 'woocommerce_trash_untrash_post_handler'), 10, 1);
695
696 add_action('woocommerce_after_single_product_ordering', array($this, 'woocommerce_product_and_order_actions_handler'), 10, 2);
697 add_action('woocommerce_update_product', array($this, 'woocommerce_product_and_order_actions_handler'), 10, 2);
698 add_action('woocommerce_update_product_variation', array($this, 'woocommerce_product_and_order_actions_handler'), 10, 2);
699
700 add_action('woocommerce_payment_token_set_default', array($this, 'woocommerce_payment_token_set_default_handler'), 10, 2);
701 add_action('woocommerce_grant_product_download_permissions', array($this, 'woocommerce_grant_product_download_permissions_handler'), 10, 1);
702 }
703 }
704 endif;