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

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