PluginProbe ʕ •ᴥ•ʔ
CommerceBird – AI Command Center, ERP Integrations & B2B for WooCommerce (Zoho, Exact Online). / 2.4.0
CommerceBird – AI Command Center, ERP Integrations & B2B for WooCommerce (Zoho, Exact Online). v2.4.0
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 11 months ago purchase-orders 1 year ago zoho-crm 1 year ago zoho-inventory 11 months ago class-api-handler-zoho.php 11 months ago class-auth-zoho.php 1 year ago class-common.php 1 year ago class-plugin.php 11 months ago class-wc-api.php 1 year ago index.php 1 year ago
class-plugin.php
185 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\Actions\Ajax\SettingsAjax;
16 use CommerceBird\Admin\Template;
17 use CommerceBird\Admin\Cmbird_Acf;
18 use CommerceBird\Cmbird_WC_API;
19 use CMBIRD_Purchase_Orders_Automation;
20
21 class Plugin {
22
23
24 public function __construct() {
25 add_action( 'admin_init', array( $this, 'init' ) );
26 }
27
28 public static function activate() {
29 // create log table
30 // global $wpdb;
31 // $charset_collate = $wpdb->get_charset_collate();
32 // $zi_product_log_table = "{$wpdb->prefix}cmbird_zi_product_error";
33 // $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;";
34 // dbDelta( $zi_create_sql );
35 }
36
37 public static function deactivate() {
38 wp_clear_scheduled_hook( 'zi_execute_import_sync' );
39 wp_clear_scheduled_hook( 'cmbird_eo_get_payment_statuses' );
40 wp_clear_scheduled_hook( 'cmbird_exact_online_sync_orders' );
41 wp_clear_scheduled_hook( 'cmbird_zoho_sync_category_cron' );
42 wp_clear_scheduled_hook( 'cmbird_zoho_contact_sync' );
43 }
44
45 public static function uninstall() {
46 $post_meta_keys = array(
47 'zi_item_id',
48 'zi_purchase_account_id',
49 'zi_account_id',
50 'zi_account_name',
51 'zi_inventory_account_id',
52 'zi_salesorder_id',
53 'zi_category_id',
54 '_cost_price',
55 'eo_item_id',
56 );
57 $user_meta_keys = array(
58 'zi_contact_id',
59 'zi_primary_contact_id',
60 'zi_created_time',
61 'zi_last_modified_time',
62 'zi_billing_address_id',
63 'zi_shipping_address_id',
64 'zi_contact_persons_id',
65 'zi_currency_id',
66 'zi_currency_code',
67 'eo_contact_id',
68 'eo_account_id',
69 'eo_gl_account',
70 );
71 $zi_option_keys = array(
72 'cmbird_zi_webhook_password',
73 'cmbird_zoho_inventory_cron_class',
74 'cmbird_zoho_sync_status',
75 'cmbird_zoho_item_category',
76 'cmbird_zoho_stock_sync_status',
77 'cmbird_zoho_item_name_sync_status',
78 'cmbird_zoho_enable_auto_no_status',
79 'cmbird_zoho_product_sync_status',
80 'cmbird_zoho_disable_image_sync_status',
81 'cmbird_zoho_disable_price_sync_status',
82 'cmbird_zoho_disable_name_sync_status',
83 'cmbird_zoho_disable_description_sync_status',
84 'cmbird_zoho_enable_accounting_stock_status',
85 'cmbird_zoho_enable_order_status',
86 'cmbird_wootozoho_custom_fields',
87 'cmbird_zoho_pricelist_id',
88 'cmbird_zoho_location_id_status',
89 'cmbird_zoho_inventory_auth_code',
90 'cmbird_zoho_inventory_access_token',
91 'cmbird_zoho_inventory_refresh_token',
92 'cmbird_zoho_inventory_timestamp',
93 'cmbird_zoho_inventory_oid',
94 'cmbird_zoho_inventory_url',
95 'cmbird_zoho_inventory_cid',
96 'cmbird_zoho_inventory_cs',
97 'cmbird_zoho_inventory_domain',
98 'cmbird_authorization_redirect_uri',
99 'cmbird_zoho_crm_auth_code',
100 'cmbird_zoho_crm_access_token',
101 'cmbird_zoho_crm_refresh_token',
102 'cmbird_zoho_crm_timestamp',
103 'cmbird_location_data',
104 );
105
106 foreach ( $zi_option_keys as $zi_option ) {
107 delete_option( $zi_option );
108 }
109
110 foreach ( $post_meta_keys as $post_key ) {
111 delete_post_meta_by_key( $post_key );
112 }
113
114 $users = get_users(
115 array(
116 'fields' => array( 'ID' ),
117 )
118 );
119 foreach ( $users as $user_id ) {
120 foreach ( $user_meta_keys as $user_key ) {
121 delete_user_meta( $user_id, $user_key );
122 }
123 }
124 // deleting mapped categories
125 global $wpdb;
126 $table_name = $wpdb->prefix . 'options';
127 $sql = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM %s WHERE option_name LIKE %s', $table_name, '%zoho_id_for_term_id_%' ) );
128 foreach ( $sql as $key => $row ) {
129 $option_name = $row->option_name;
130 $wpdb->delete( $table_name, array( 'option_name' => $option_name ), array( '%s' ) );
131 }
132 // clear scheduled zcrm_refresh_token
133 wp_clear_scheduled_hook( 'zcrm_refresh_token' );
134 }
135
136 public static function init() {
137 if ( is_admin() ) {
138 $php_min_version = '8.2';
139 $php_current_version = phpversion();
140
141 if ( version_compare( $php_min_version, $php_current_version, '>' ) ) {
142 $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, );
143 wp_die(
144 esc_html( $error_message ),
145 'Plugin Activation Error',
146 array(
147 'response' => 200,
148 'back_link' => true,
149 )
150 );
151 }
152 $zoho_inventory_access_token = get_option( 'cmbird_zoho_inventory_access_token' );
153 // remove option zoho_inventory_access_token if it contains only one character
154 if ( $zoho_inventory_access_token && strlen( $zoho_inventory_access_token ) === 1 ) {
155 delete_option( 'cmbird_zoho_inventory_access_token' );
156 } else {
157 // schedule cronjob for import sync
158 $interval = get_option( 'zi_cron_interval' );
159 if ( 'none' !== $interval && ! empty( $zoho_inventory_access_token ) ) {
160 if ( ! wp_next_scheduled( 'zi_execute_import_sync' ) ) {
161 wp_schedule_event( time(), $interval, 'zi_execute_import_sync' );
162 }
163 } else {
164 wp_clear_scheduled_hook( 'zi_execute_import_sync' );
165 }
166 }
167 // create webhook password if does not exists.
168 if ( ! get_option( 'cmbird_zi_webhook_password', false ) ) {
169 add_option( 'cmbird_zi_webhook_password', password_hash( 'commercebird-zi-webhook-token', PASSWORD_BCRYPT ) );
170 }
171 Template::instance();
172 ZohoInventoryAjax::instance();
173 ZohoCRMAjax::instance();
174 AcfAjax::instance();
175 SettingsAjax::instance();
176 }
177 ExactOnlineAjax::instance();
178 if ( class_exists( 'ACF' ) ) {
179 Cmbird_Acf::instance();
180 }
181 new Cmbird_WC_API();
182 new CMBIRD_Purchase_Orders_Automation();
183 }
184 }
185