PluginProbe ʕ •ᴥ•ʔ
CommerceBird – AI Command Center, ERP Integrations & B2B for WooCommerce (Zoho, Exact Online). / 2.3.2
CommerceBird – AI Command Center, ERP Integrations & B2B for WooCommerce (Zoho, Exact Online). v2.3.2
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 index.php 1 year ago
class-plugin.php
182 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 'eo_item_id',
54 );
55 $user_meta_keys = array(
56 'zi_contact_id',
57 'zi_primary_contact_id',
58 'zi_created_time',
59 'zi_last_modified_time',
60 'zi_billing_address_id',
61 'zi_shipping_address_id',
62 'zi_contact_persons_id',
63 'zi_currency_id',
64 'zi_currency_code',
65 'eo_contact_id',
66 'eo_account_id',
67 'eo_gl_account',
68 );
69 $zi_option_keys = array(
70 'cmbird_zi_webhook_password',
71 'cmbird_zoho_inventory_cron_class',
72 'cmbird_zoho_sync_status',
73 'cmbird_zoho_item_category',
74 'cmbird_zoho_stock_sync_status',
75 'cmbird_zoho_item_name_sync_status',
76 'cmbird_zoho_enable_auto_no_status',
77 'cmbird_zoho_product_sync_status',
78 'cmbird_zoho_disable_image_sync_status',
79 'cmbird_zoho_disable_price_sync_status',
80 'cmbird_zoho_disable_name_sync_status',
81 'cmbird_zoho_disable_description_sync_status',
82 'cmbird_zoho_enable_accounting_stock_status',
83 'cmbird_zoho_enable_order_status',
84 'cmbird_wootozoho_custom_fields',
85 'cmbird_zoho_pricelist_id',
86 'cmbird_zoho_warehouse_id_status',
87 'cmbird_zoho_inventory_auth_code',
88 'cmbird_zoho_inventory_access_token',
89 'cmbird_zoho_inventory_refresh_token',
90 'cmbird_zoho_inventory_timestamp',
91 'cmbird_zoho_inventory_oid',
92 'cmbird_zoho_inventory_url',
93 'cmbird_zoho_inventory_cid',
94 'cmbird_zoho_inventory_cs',
95 'cmbird_zoho_inventory_domain',
96 'cmbird_authorization_redirect_uri',
97 'cmbird_zoho_crm_auth_code',
98 'cmbird_zoho_crm_access_token',
99 'cmbird_zoho_crm_refresh_token',
100 'cmbird_zoho_crm_timestamp',
101 'cmbird_warehouse_data',
102 );
103
104 foreach ( $zi_option_keys as $zi_option ) {
105 delete_option( $zi_option );
106 }
107
108 foreach ( $post_meta_keys as $post_key ) {
109 delete_post_meta_by_key( $post_key );
110 }
111
112 $users = get_users(
113 array(
114 'fields' => array( 'ID' ),
115 )
116 );
117 foreach ( $users as $user_id ) {
118 foreach ( $user_meta_keys as $user_key ) {
119 delete_user_meta( $user_id, $user_key );
120 }
121 }
122 // deleting mapped categories
123 global $wpdb;
124 $table_name = $wpdb->prefix . 'options';
125 $sql = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM %s WHERE option_name LIKE %s', $table_name, '%zoho_id_for_term_id_%' ) );
126 foreach ( $sql as $key => $row ) {
127 $option_name = $row->option_name;
128 $wpdb->delete( $table_name, array( 'option_name' => $option_name ), array( '%s' ) );
129 }
130 // clear scheduled zcrm_refresh_token
131 wp_clear_scheduled_hook( 'zcrm_refresh_token' );
132 }
133
134 public static function init() {
135 if ( is_admin() ) {
136 $php_min_version = '7.4';
137 $php_current_version = phpversion();
138
139 if ( version_compare( $php_min_version, $php_current_version, '>' ) ) {
140 $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, );
141 wp_die(
142 esc_html( $error_message ),
143 'Plugin Activation Error',
144 array(
145 'response' => 200,
146 'back_link' => true,
147 )
148 );
149 }
150 $zoho_inventory_access_token = get_option( 'cmbird_zoho_inventory_access_token' );
151 // remove option zoho_inventory_access_token if it contains only one character
152 if ( $zoho_inventory_access_token && strlen( $zoho_inventory_access_token ) === 1 ) {
153 delete_option( 'cmbird_zoho_inventory_access_token' );
154 } else {
155 // schedule cronjob for import sync
156 $interval = get_option( 'zi_cron_interval' );
157 if ( 'none' !== $interval && ! empty( $zoho_inventory_access_token ) ) {
158 if ( ! wp_next_scheduled( 'zi_execute_import_sync' ) ) {
159 wp_schedule_event( time(), $interval, 'zi_execute_import_sync' );
160 }
161 } else {
162 wp_clear_scheduled_hook( 'zi_execute_import_sync' );
163 }
164 }
165 // create webhook password if does not exists.
166 if ( ! get_option( 'cmbird_zi_webhook_password', false ) ) {
167 add_option( 'cmbird_zi_webhook_password', password_hash( 'commercebird-zi-webhook-token', PASSWORD_BCRYPT ) );
168 }
169 Template::instance();
170 ZohoInventoryAjax::instance();
171 ZohoCRMAjax::instance();
172 AcfAjax::instance();
173 Cors::instance();
174 }
175 ExactOnlineAjax::instance();
176 if ( class_exists( 'ACF' ) ) {
177 Cmbird_Acf::instance();
178 }
179 new Cmbird_WC_API();
180 }
181 }
182