PluginProbe
The WP Remote WordPress Plugin / 5.72
The WP Remote WordPress Plugin v5.72
6.72 6.69 6.65 6.62 6.48 6.47 4.87 4.97 5.05 5.09 5.16 5.22 5.24 5.25 5.38 5.41 5.42 5.45 5.47 5.53 5.56 5.65 5.68 5.72 5.73 All 53 releases
wpremote / wp_dynsync.php

wp_dynsync.php in The WP Remote WordPress Plugin 5.72, at wp_dynsync.php

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