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

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