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

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