PluginProbe
The WP Remote WordPress Plugin / 4.74
The WP Remote WordPress Plugin v4.74
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 4.74, at wp_dynsync.php

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