PluginProbe ʕ •ᴥ•ʔ
CommerceBird – AI Command Center, ERP Integrations & B2B for WooCommerce (Zoho, Exact Online). / 2.2.18
CommerceBird – AI Command Center, ERP Integrations & B2B for WooCommerce (Zoho, Exact Online). v2.2.18
3.0.3 3.0.2 3.0.1 trunk 2.2.14 2.2.15 2.2.16 2.2.17 2.2.18 2.2.19 2.3.0 2.3.1 2.3.10 2.3.11 2.3.12 2.3.13 2.3.14 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.5.0 2.5.1 2.5.2 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.6.5 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.7.91 2.7.92 2.7.93 2.8.0 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.9.0 2.9.1 2.9.2 2.9.3 3.0.0
commercebird / includes / classes / class-plugin.php
commercebird / includes / classes Last commit date
apis 1 year ago purchase-orders 1 year ago zoho-crm 1 year ago zoho-inventory 1 year ago class-api-handler-zoho.php 1 year ago class-auth-zoho.php 1 year ago class-common.php 1 year ago class-plugin.php 1 year ago class-wc-api.php 1 year ago class-webhook-modify.php 1 year ago index.php 1 year ago
class-plugin.php
175 lines
1 <?php
2
3 namespace CommerceBird;
4
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
10
11 use CommerceBird\Admin\Actions\Ajax\ExactOnlineAjax;
12 use CommerceBird\Admin\Actions\Ajax\ZohoInventoryAjax;
13 use CommerceBird\Admin\Actions\Ajax\ZohoCRMAjax;
14 use CommerceBird\Admin\Actions\Ajax\AcfAjax;
15 use CommerceBird\Admin\Cors;
16 use CommerceBird\Admin\Template;
17 use CommerceBird\Admin\Cmbird_Acf;
18 use CommerceBird\Cmbird_WC_API;
19
20 class Plugin {
21
22 public function __construct() {
23 add_action( 'admin_init', array( $this, 'init' ) );
24 }
25
26 public static function activate() {
27 // create log table
28 // global $wpdb;
29 // $charset_collate = $wpdb->get_charset_collate();
30 // $zi_product_log_table = "{$wpdb->prefix}cmbird_zi_product_error";
31 // $zi_create_sql = "CREATE TABLE $zi_product_log_table ( ID bigint(20) PRIMARY KEY auto_increment, product_id bigint(20) NOT NULL, error_message TEXT NOT NULL, sync_timestamp VARCHAR(20) NOT NULL, status int(10) NOT NULL )$charset_collate;";
32 // dbDelta( $zi_create_sql );
33 }
34
35 public static function deactivate() {
36 wp_clear_scheduled_hook( 'zi_execute_import_sync' );
37 wp_clear_scheduled_hook( 'cmbird_eo_get_payment_statuses' );
38 wp_clear_scheduled_hook( 'cmbird_exact_online_sync_orders' );
39 wp_clear_scheduled_hook( 'cmbird_zoho_sync_category_cron' );
40 wp_clear_scheduled_hook( 'cmbird_zoho_contact_sync' );
41 }
42
43 public static function uninstall() {
44 $post_meta_keys = array(
45 'zi_item_id',
46 'zi_purchase_account_id',
47 'zi_account_id',
48 'zi_account_name',
49 'zi_inventory_account_id',
50 'zi_salesorder_id',
51 'zi_category_id',
52 '_cost_price',
53 );
54 $user_meta_keys = array(
55 'zi_contact_id',
56 'zi_primary_contact_id',
57 'zi_created_time',
58 'zi_last_modified_time',
59 'zi_billing_address_id',
60 'zi_shipping_address_id',
61 'zi_contact_persons_id',
62 'zi_currency_id',
63 'zi_currency_code',
64 );
65 $zi_option_keys = array(
66 'cmbird_zi_webhook_password',
67 'cmbird_zoho_inventory_cron_class',
68 'cmbird_zoho_sync_status',
69 'cmbird_zoho_item_category',
70 'cmbird_zoho_stock_sync_status',
71 'cmbird_zoho_item_name_sync_status',
72 'cmbird_zoho_enable_auto_no_status',
73 'cmbird_zoho_product_sync_status',
74 'cmbird_zoho_disable_image_sync_status',
75 'cmbird_zoho_disable_price_sync_status',
76 'cmbird_zoho_disable_name_sync_status',
77 'cmbird_zoho_disable_description_sync_status',
78 'cmbird_zoho_enable_accounting_stock_status',
79 'cmbird_zoho_enable_order_status',
80 'cmbird_wootozoho_custom_fields',
81 'cmbird_zoho_pricelist_id',
82 'cmbird_zoho_warehouse_id_status',
83 'cmbird_zoho_inventory_auth_code',
84 'cmbird_zoho_inventory_access_token',
85 'cmbird_zoho_inventory_refresh_token',
86 'cmbird_zoho_inventory_timestamp',
87 'cmbird_zoho_inventory_oid',
88 'cmbird_zoho_inventory_url',
89 'cmbird_zoho_inventory_cid',
90 'cmbird_zoho_inventory_cs',
91 'cmbird_zoho_inventory_domain',
92 'cmbird_authorization_redirect_uri',
93 'cmbird_zoho_crm_auth_code',
94 'cmbird_zoho_crm_access_token',
95 'cmbird_zoho_crm_refresh_token',
96 'cmbird_zoho_crm_timestamp',
97 'cmbird_warehouse_data',
98 );
99
100 foreach ( $zi_option_keys as $zi_option ) {
101 delete_option( $zi_option );
102 }
103
104 foreach ( $post_meta_keys as $post_key ) {
105 delete_post_meta_by_key( $post_key );
106 }
107
108 $users = get_users();
109 foreach ( $users as $user ) {
110 foreach ( $user_meta_keys as $user_key ) {
111 delete_user_meta( $user->ID, $user_key );
112 }
113 }
114 // deleting mapped categories
115 global $wpdb;
116 $table_name = $wpdb->prefix . 'options';
117 $sql = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM %s WHERE option_name LIKE %s', $table_name, '%zoho_id_for_term_id_%' ) );
118 foreach ( $sql as $key => $row ) {
119 $option_name = $row->option_name;
120 $wpdb->delete( $table_name, array( 'option_name' => $option_name ), array( '%s' ) );
121 }
122 // clear scheduled zcrm_refresh_token
123 wp_clear_scheduled_hook( 'zcrm_refresh_token' );
124 }
125
126 public static function init() {
127 if ( is_admin() ) {
128 $php_min_version = '7.4';
129 $php_current_version = phpversion();
130
131 if ( version_compare( $php_min_version, $php_current_version, '>' ) ) {
132 $error_message = sprintf( 'Your server is running PHP version %s but the commercebird plugin requires at least PHP %s. Please update your PHP version.', $php_current_version, $php_min_version, );
133 wp_die(
134 esc_html( $error_message ),
135 'Plugin Activation Error',
136 array(
137 'response' => 200,
138 'back_link' => true,
139 )
140 );
141 }
142 $zoho_inventory_access_token = get_option( 'cmbird_zoho_inventory_access_token' );
143 // remove option zoho_inventory_access_token if it contains only one character
144 if ( $zoho_inventory_access_token && strlen( $zoho_inventory_access_token ) === 1 ) {
145 delete_option( 'cmbird_zoho_inventory_access_token' );
146 } else {
147 // schedule cronjob for import sync
148 $interval = get_option( 'zi_cron_interval' );
149 if ( 'none' !== $interval && ! empty( $zoho_inventory_access_token ) ) {
150 if ( ! wp_next_scheduled( 'zi_execute_import_sync' ) ) {
151 wp_schedule_event( time(), $interval, 'zi_execute_import_sync' );
152 }
153 } else {
154 wp_clear_scheduled_hook( 'zi_execute_import_sync' );
155 }
156 }
157 // create webhook password if does not exists.
158 if ( ! get_option( 'cmbird_zi_webhook_password', false ) ) {
159 add_option( 'cmbird_zi_webhook_password', password_hash( 'commercebird-zi-webhook-token', PASSWORD_BCRYPT ) );
160 }
161 Template::instance();
162 ZohoInventoryAjax::instance();
163 ZohoCRMAjax::instance();
164 AcfAjax::instance();
165 Cors::instance();
166 }
167 ExactOnlineAjax::instance();
168 if ( class_exists( 'ACF' ) ) {
169 Cmbird_Acf::instance();
170 }
171 new Cmbird_WC_API();
172 // CMBIRD_Webhook_Modify::instance();
173 }
174 }
175