: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
if (!defined('ABSPATH')) exit;
if (!class_exists('BVWPDynSync')) :
public static $dynsync_table = 'dynamic_sync';
public function __construct($db, $settings, $config) {
$this->settings = $settings;
$this->ignored_events = array_key_exists('ignored_events', $config) ? $config['ignored_events'] : array();
$this->add_actions_and_listeners();
add_action('clear_dynsync_config', array($this, 'clearConfig'));
public function clearConfig() {
$this->db->dropBVTable(BVWPDynSync::$dynsync_table);
function add_event($event_type, $event_data) {
global $wp_current_filter;
$site_id = get_current_blog_id();
$values = array ( "event_type" => $event_type, "event_tag" => end($wp_current_filter), "event_data" => maybe_serialize($event_data), "site_id" => $site_id);
$this->db->replaceIntoBVTable(BVWPDynSync::$dynsync_table, $values);
function add_db_event($table, $message) {
$_msg['data'] = $message;
$this->add_event('db', $_msg);
function post_action_handler($post_id) {
if (current_filter() == 'delete_post')
$this->add_db_event('posts', array('ID' => $post_id, 'msg_type' => $msg_type));
function get_ignored_postmeta() {
$ignored_postmeta = $this->ignored_events['postmeta'];
if (empty($ignored_postmeta)) {
$ignored_postmeta = array();
return array_unique($ignored_postmeta);
function postmeta_insert_handler($meta_id, $post_id, $meta_key, $meta_value='') {
if ($this->is_key_ignored($this->get_ignored_postmeta(), $meta_key))
$this->add_db_event('postmeta', array('meta_id' => $meta_id));
function postmeta_modification_handler($meta_id, $object_id, $meta_key, $meta_value) {
if ($this->is_key_ignored($this->get_ignored_postmeta(), $meta_key))
return $this->add_db_event('postmeta', array('meta_id' => $meta_id));
foreach ($meta_id as $id) {
$this->add_db_event('postmeta', array('meta_id' => $id));
function postmeta_action_handler($meta_id, $post_id = null, $meta_key = null) {
if ($this->is_key_ignored($this->get_ignored_postmeta(), $meta_key))
if ( !is_array($meta_id) )
return $this->add_db_event('postmeta', array('meta_id' => $meta_id));
foreach ( $meta_id as $id )
$this->add_db_event('postmeta', array('meta_id' => $id));
function comment_action_handler($comment_id) {
if (current_filter() == 'delete_comment')
if (!is_array($comment_id)) {
if (wp_get_comment_status($comment_id) != 'spam')
$this->add_db_event('comments', array('comment_ID' => $comment_id, 'msg_type' => $msg_type));
foreach ($comment_id as $id) {
if (wp_get_comment_status($comment_id) != 'spam')
$this->add_db_event('comments', array('comment_ID' => $id, 'msg_type' => $msg_type));
function commentmeta_insert_handler($meta_id, $comment_id = null) {
if (empty($comment_id) || wp_get_comment_status($comment_id) != 'spam')
$this->add_db_event('commentmeta', array('meta_id' => $meta_id));
function commentmeta_modification_handler($meta_id, $object_id, $meta_key, $meta_value) {
if (current_filter() == 'deleted_comment_meta')
return $this->add_db_event('commentmeta', array('meta_id' => $meta_id, 'msg_type' => $msg_type));
foreach ($meta_id as $id) {
$this->add_db_event('commentmeta', array('meta_id' => $id, 'msg_type' => $msg_type));
function userid_action_handler($user_or_id) {
if (is_object($user_or_id))
$userid = intval( $user_or_id->ID );
$userid = intval( $user_or_id );
if (current_filter() == 'deleted_user')
$this->add_db_event('users', array('ID' => $userid));
function usermeta_insert_handler($umeta_id, $user_id = null) {
$this->add_db_event('usermeta', array('umeta_id' => $umeta_id));
function usermeta_modification_handler($umeta_id, $object_id, $meta_key, $meta_value = '') {
if (current_filter() == 'delete_usermeta')
if (!is_array($umeta_id))
return $this->add_db_event('usermeta', array('umeta_id' => $umeta_id, 'msg_type' => $msg_type));
foreach ($umeta_id as $id) {
$this->add_db_event('usermeta', array('umeta_id' => $id, 'msg_type' => $msg_type));
function link_action_handler($link_id) {
$this->add_db_event('links', array('link_id' => $link_id));
function edited_terms_handler($term_id, $taxonomy = null) {
$this->add_db_event('terms', array('term_id' => $term_id));
function term_handler($term_id, $tt_id, $taxonomy) {
$this->add_db_event('terms', array('term_id' => $term_id));
$this->term_taxonomy_handler($tt_id, $taxonomy);
function delete_term_handler($term, $tt_id, $taxonomy, $deleted_term ) {
$this->add_db_event('terms', array('term_id' => $term, 'msg_type' => 'delete'));
function term_taxonomy_handler($tt_id, $taxonomy = null) {
$this->add_db_event('term_taxonomy', array('term_taxonomy_id' => $tt_id));
function term_taxonomies_handler($tt_ids) {
foreach((array)$tt_ids as $tt_id) {
$this->term_taxonomy_handler($tt_id);
function term_relationship_handler($object_id, $term_id) {
$this->add_db_event('term_relationships', array('term_taxonomy_id' => $term_id, 'object_id' => $object_id));
function term_relationships_handler($object_id, $term_ids) {
foreach ((array)$term_ids as $term_id) {
$this->term_relationship_handler($object_id, $term_id);
function set_object_terms_handler( $object_id, $terms, $tt_ids ) {
$this->term_relationships_handler( $object_id, $tt_ids );
function get_ignored_options() {
$ignored_options = $this->ignored_events['options'];
if (empty($ignored_options)) {
$ignored_options = array();
return array_unique($ignored_options);
function is_key_ignored($ignored_keys, $value) {
foreach($ignored_keys as $val) {
if (BVHelper::safePregMatch($val, $value))
function option_handler($option_name) {
if (current_filter() == 'deleted_option')
$is_ignored = $this->is_key_ignored($this->get_ignored_options(), $option_name);
$this->add_db_event('options', array('option_name' => $option_name, 'msg_type' => $msg_type));
function theme_action_handler($theme) {
$this->add_event('themes', array('theme' => $this->settings->getOption('stylesheet')));
function plugin_action_handler($plugin='') {
$this->add_event('plugins', array('name' => $plugin));
function upload_handler($file) {
$this->add_event('uploads', array('file' => $file['file']));
function attachment_metadata_handler($data = null, $post_id = null) {
if(!empty($data) && !empty($data['file'])) {
$this->add_event('uploads', array('file' => $data['file'], 'sizes' => $data['sizes']));
function wpmu_new_blog_create_handler($site_id) {
$this->add_db_event('blogs', array('site_id' => $site_id));
function sitemeta_handler($option) {
$is_ignored = $this->is_key_ignored($this->get_ignored_options(), $option);
if (!$is_ignored && is_multisite()) {
$this->add_db_event('sitemeta', array('site_id' => $this->db->getSiteId(), 'meta_key' => $option));
/* WOOCOMMERCE SUPPORT FUNCTIONS BEGINS FROM HERE*/
function handle_order_items($order_id, $type = null) {
$this->add_db_event('woocommerce_order_items', array('order_id' => $order_id, 'msg_type' => 'delete'));
$itemmeta_table = $this->db->getWPTable('woocommerce_order_itemmeta');
$items_table = $this->db->getWPTable('woocommerce_order_items');
$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}";
$query .= " AND {$items_table}.order_item_type = '{$type}'";
foreach ($this->db->getResult($query) as $row) {
if (!in_array($row['meta_id'], $meta_ids, true)) {
$meta_ids[] = $row['meta_id'];
$this->add_db_event('woocommerce_order_itemmeta', array('meta_id' => $row['meta_id'], 'msg_type' => 'delete'));
function woocommerce_remove_order_items_handler($order, $type = null) {
$order_id = $order->get_id();
$this->handle_order_items($order_id, $type);
function woocommerce_resume_order_handler($order_id) {
$this->handle_order_items($order_id);
function woocommerce_update_order_handler($order_id, $order = null) {
$this->add_db_event('wc_orders', array('id' => $order_id));
$this->add_db_event('wc_orders_meta', array('order_id' => $order_id));
$this->add_db_event('wc_order_addresses', array('order_id' => $order_id));
$this->add_db_event('wc_order_operational_data', array('order_id' => $order_id));
function woocommerce_trash_order_handler($order_id) {
$this->add_db_event('wc_orders', array('id' => $order_id));
$this->add_db_event('wc_orders_meta', array('order_id' => $order_id));
function woocommerce_delete_order_handler($order_id) {
$this->add_db_event('wc_orders', array('id' => $order_id, 'msg_type' => 'delete'));
$this->add_db_event('wc_orders_meta', array('order_id' => $order_id, 'msg_type' => 'delete'));
$this->add_db_event('wc_order_addresses', array('order_id' => $order_id, 'msg_type' => 'delete'));
$this->add_db_event('wc_order_operational_data', array('order_id' => $order_id, 'msg_type' => 'delete'));
function woocommerce_new_order_item_handler($item_id, $item, $order_id) {
$this->add_db_event('woocommerce_order_items', array('order_item_id' => $item_id));
$this->add_db_event('woocommerce_order_itemmeta', array('order_item_id' => $item_id));
function woocommerce_update_order_item_handler($item_id, $args){
$this->add_db_event('woocommerce_order_items', array('order_item_id' => $item_id));
function woocommerce_delete_order_item_handler($item_id) {
$this->add_db_event('woocommerce_order_itemmeta', array('order_item_id' => $item_id, 'msg_type' => 'delete'));
$this->add_db_event('woocommerce_order_items', array('order_item_id' => $item_id, 'msg_type' => 'delete'));
function woocommerce_attribute_added_handler($attribute_id, $attribute) {
$this->add_db_event('woocommerce_attribute_taxonomies', array('attribute_id' => $attribute_id));
function woocommerce_attribute_updated_handler($attribute_id, $attribute, $old_attribute_name) {
$this->add_db_event('woocommerce_attribute_taxonomies', array('attribute_id' => $attribute_id));
# $woocommerce->attribute_taxonomy_name( $attribute_name )
$this->add_db_event('term_taxonomy', array('taxonomy' => wc_attribute_taxonomy_name($attribute['attribute_name'])));
# sanitize_title( $attribute_name )
$this->add_db_event('woocommerce_termmeta', array('meta_key' => 'order_pa_' . $attribute['attribute_name']));#deprecated
$this->add_db_event('termmeta', array('meta_key' => 'order_pa_' . $attribute['attribute_name']));
$this->add_db_event('postmeta', array('meta_key' => '_product_attributes'));
# sanitize_title( $attribute_name )
$this->add_db_event('postmeta', array('meta_key' => 'attribute_pa_' . $attribute['attribute_name']));
function woocommerce_attribute_deleted_handler($attribute_id, $attribute_name, $taxonomy) {
return $this->add_db_event('woocommerce_attribute_taxonomies', array('attribute_id' => $attribute_id, 'msg_type' => 'delete'));
function woocommerce_revoke_access_to_product_download_handler($download_id, $product_id, $order_id, $permission_id ) {
$this->add_db_event('woocommerce_downloadable_product_permissions', array('permission_id' => $permission_id, 'msg_type' => 'delete'));
function woocommerce_tax_rate_handler($tax_rate_id, $_tax_rate) {
$this->add_db_event('woocommerce_tax_rates', array('tax_rate_id' => $tax_rate_id));
function woocommerce_tax_rate_deleted_handler($tax_rate_id) {
$this->add_db_event('woocommerce_tax_rates', array('tax_rate_id' => $tax_rate_id, 'msg_type' => 'delete'));
$this->add_db_event('woocommerce_tax_rate_locations', array('tax_rate_id' => $tax_rate_id, 'msg_type' => 'delete'));
function woocommerce_grant_product_download_access_handler($data) {
$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']));
function woocommerce_download_product_handler($user_email, $order_key, $product_id, $user_id, $download_id, $order_id) {
$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));
function woocommerce_delete_order_items_handler($postid) {
$order_item_ids = array();
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) {
if (!in_array($row['meta_id'], $meta_ids, true)) {
$meta_ids[] = $row['meta_id'];
$this->add_db_event('woocommerce_order_itemmeta', array('meta_id' => $row['meta_id'], 'msg_type' => 'delete'));
if (!in_array($row['order_item_id'], $order_item_ids, true)) {
$order_item_ids[] = $row['order_item_id'];
$this->add_db_event('woocommerce_order_items', array('order_item_id' => $row['order_item_id'], 'msg_type' => 'delete'));
function woocommerce_payment_token_handler($token_id) {
$this->add_db_event('woocommerce_payment_tokens', array('token_id' => $token_id));
function woocommerce_payment_token_deleted_handler($token_id, $object) {
$this->add_db_event('woocommerce_payment_tokens', array('token_id' => $token_id, 'msg_type' => 'delete'));
$this->add_db_event('woocommerce_payment_tokenmeta', array('payment_token_id' => $token_id, 'msg_type' => 'delete'));
function woocommerce_shipping_zone_method_added_handler($instance_id, $method_id, $zone_id) {
$this->add_db_event('woocommerce_shipping_zone_methods', array('instance_id' => $instance_id));
$this->add_db_event('woocommerce_shipping_zones', array('zone_id' => $zone_id));
$this->add_db_event('woocommerce_shipping_zone_locations', array('zone_id' => $zone_id));
function woocommerce_shipping_zone_method_deleted_handler($instance_id, $method_id, $zone_id) {
$this->add_db_event('woocommerce_shipping_zone_methods', array('instance_id' => $instance_id, 'msg_type' => 'delete'));
function woocommerce_shipping_zone_method_status_toggled_handler($instance_id, $method_id, $zone_id, $is_enabled) {
$this->add_db_event('woocommerce_shipping_zone_methods', array('instance_id' => absint( $instance_id )));
function woocommerce_deleted_order_downloadable_permissions_handler($post_id) {
$this->add_db_event('woocommerce_downloadable_product_permissions', array('order_id' => $post_id, 'msg_type' => 'delete'));
function woocommerce_delete_shipping_zone_handler($zone_id) {
$this->add_db_event('woocommerce_shipping_zone_methods', array('zone_id' => $zone_id, 'msg_type' => 'delete'));
$this->add_db_event('woocommerce_shipping_zone_locations', array('zone_id' => $zone_id, 'msg_type' => 'delete'));
$this->add_db_event('woocommerce_shipping_zones', array('zone_id' => $zone_id, 'msg_type' => 'delete'));
function woocommerce_webhook_handler($webhook_id) {
$this->add_db_event('wc_webhooks', array('webhook_id' => $webhook_id));
function woocommerce_webhook_delete_handler($webhook_id, $webhook) {
$this->add_db_event('wc_webhooks', array('webhook_id' => $webhook_id, 'msg_type' => 'delete'));
function woocommerce_delete_shipping_zone_method_handler($instance_id) {
$this->add_db_event('woocommerce_shipping_zone_methods', array('instance_id' => $instance_id, 'msg_type' => 'delete'));
function woocommerce_order_term_meta_handler($meta_id, $object_id, $meta_key, $meta_value) {
if (current_filter() == 'deleted_order_item_meta')
if (!is_array($meta_id)) {
$this->add_db_event('woocommerce_order_itemmeta', array('meta_id' => $meta_id, 'msg_type' => $msg_type));
foreach ($meta_id as $id) {
$this->add_db_event('woocommerce_order_itemmeta', array('meta_id' => $id, 'msg_type' => $msg_type));
function woocommerce_payment_token_meta_handler($meta_id, $object_id, $meta_key, $meta_value) {
if (current_filter() == 'deleted_payment_token_meta')
if (!is_array($meta_id)) {
$this->add_db_event('woocommerce_payment_tokenmeta', array('meta_id' => $meta_id, 'msg_type' => $msg_type));
foreach ($meta_id as $id) {
$this->add_db_event('woocommerce_payment_tokenmeta', array('meta_id' => $id, 'msg_type' => $msg_type));
function woocommerce_api_product_attribute_handler($id, $data) {
$this->add_db_event('woocommerce_attribute_taxonomies', array('attribute_id' => $id));
function woocommerce_note_created_handler($note_id) {
$this->add_db_event('wc_admin_notes', array('note_id' => $note_id));
$this->add_db_event('wc_admin_note_actions', array('note_id' => $note_id));
function woocommerce_note_modification_handler($note_id) {
if (current_filter() == 'wooocommerce_note_deleted')
$this->add_db_event('wc_admin_notes', array('note_id' => $note_id, 'msg_type' => $msg_type));
$this->add_db_event('wc_admin_note_actions', array('note_id' => $note_id, 'msg_type' => $msg_type));
function woocommerce_analytics_order_stats_modification_handler($order_id) {
if (current_filter() == 'woocommerce_analytics_delete_order_stats')
$this->add_db_event('wc_order_stats', array('order_id' => $order_id, 'msg_type' => $msg_type));
function woocommerce_analytics_product_update_handler($order_item_id, $order_id) {
$this->add_db_event('wc_order_product_lookup', array('order_item_id' => $order_item_id, 'msg_type' => 'edit'));
function woocommerce_analytics_product_delete_handler($order_item_id, $order_id) {
$this->add_db_event('wc_order_product_lookup', array('order_id' => $order_id, 'msg_type' => 'delete'));
function woocommerce_analytics_new_customer_handler($customer_id) {
$this->add_db_event('wc_customer_lookup', array('customer_id' => $customer_id));
function woocommerce_analytics_customer_modification_handler($customer_id) {
if (current_filter() == 'woocommerce_analytics_delete_customer')
$this->add_db_event('wc_customer_lookup', array('customer_id' => $customer_id, 'msg_type' => $msg_type));
function woocommerce_analytics_coupon_update_handler($coupon_id, $order_id) {
$this->add_db_event('wc_order_coupon_lookup', array('coupon_id' => $coupon_id, 'order_id' => $order_id, 'msg_type' => 'edit'));
function woocommerce_analytics_coupon_delete_handler($coupon_id, $order_id) {
$this->add_db_event('wc_order_coupon_lookup', array('order_id' => $order_id, 'msg_type' => 'delete'));
function woocommerce_analytics_tax_update_handler($tax_rate_id, $order_id) {