PluginProbe ʕ •ᴥ•ʔ
CommerceBird – AI Command Center, ERP Integrations & B2B for WooCommerce (Zoho, Exact Online). / 2.6.2
CommerceBird – AI Command Center, ERP Integrations & B2B for WooCommerce (Zoho, Exact Online). v2.6.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 6 months ago purchase-orders 6 months ago zoho-crm 6 months ago zoho-inventory 6 months ago class-api-handler-zoho.php 6 months ago class-auth-zoho.php 6 months ago class-common.php 6 months ago class-plugin.php 9 months ago class-wc-api.php 9 months ago index.php 1 year ago
class-plugin.php
218 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 /**
22 * Main plugin class for CommerceBird.
23 *
24 * Handles activation, deactivation, uninstall, and initialization logic.
25 *
26 * @since 1.0.0
27 */
28 class Plugin {
29
30
31 /**
32 * The constructor for the plugin.
33 *
34 * @since 1.0.0
35 *
36 * This function is called when the plugin is loaded. It hooks the init method to the admin_init action.
37 */
38 public function __construct() {
39 add_action( 'admin_init', array( $this, 'init' ) );
40 }
41
42 /**
43 * This function is run on plugin activation.
44 * It creates a database table to store log data of products which have errors during sync.
45 * The fields of the table are:
46 * - ID: auto incrementing id
47 * - product_id: the id of the product which has errors
48 * - error_message: the error message
49 * - sync_timestamp: the timestamp when the sync was attempted
50 * - status: the status of the sync (success/fail)
51 */
52 public static function activate() {
53 // create log table.
54 // global $wpdb;
55 // $charset_collate = $wpdb->get_charset_collate();
56 // $zi_product_log_table = "{$wpdb->prefix}cmbird_zi_product_error";
57 // $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;";
58 // dbDelta( $zi_create_sql );
59 }
60
61 /**
62 * Clear all the scheduled actions when the plugin is deactivated.
63 *
64 * @since 1.0.0
65 */
66 public static function deactivate() {
67 wp_clear_scheduled_hook( 'zi_execute_import_sync' );
68 wp_clear_scheduled_hook( 'cmbird_eo_get_payment_statuses' );
69 wp_clear_scheduled_hook( 'cmbird_exact_online_sync_orders' );
70 wp_clear_scheduled_hook( 'cmbird_zoho_sync_category_cron' );
71 wp_clear_scheduled_hook( 'cmbird_zoho_contact_sync' );
72 }
73
74 /**
75 * Deletes all the options and post/user meta set by the plugin.
76 *
77 * This function is called when the plugin is uninstalled.
78 *
79 * @since 1.0.0
80 */
81 public static function uninstall() {
82 $post_meta_keys = array(
83 'zi_item_id',
84 'zi_purchase_account_id',
85 'zi_account_id',
86 'zi_account_name',
87 'zi_inventory_account_id',
88 'zi_salesorder_id',
89 'zi_category_id',
90 '_cost_price',
91 'eo_item_id',
92 );
93 $user_meta_keys = array(
94 'zi_contact_id',
95 'zi_primary_contact_id',
96 'zi_created_time',
97 'zi_last_modified_time',
98 'zi_billing_address_id',
99 'zi_shipping_address_id',
100 'zi_contact_persons_id',
101 'zi_currency_id',
102 'zi_currency_code',
103 'eo_contact_id',
104 'eo_account_id',
105 'eo_gl_account',
106 );
107 $zi_option_keys = array(
108 'cmbird_zi_webhook_password',
109 'cmbird_zoho_inventory_cron_class',
110 'cmbird_zoho_sync_status',
111 'cmbird_zoho_item_category',
112 'cmbird_zoho_stock_sync_status',
113 'cmbird_zoho_item_name_sync_status',
114 'cmbird_zoho_enable_auto_no_status',
115 'cmbird_zoho_product_sync_status',
116 'cmbird_zoho_disable_image_sync_status',
117 'cmbird_zoho_disable_price_sync_status',
118 'cmbird_zoho_disable_name_sync_status',
119 'cmbird_zoho_disable_description_sync_status',
120 'cmbird_zoho_enable_accounting_stock_status',
121 'cmbird_zoho_enable_order_status',
122 'cmbird_wootozoho_custom_fields',
123 'cmbird_zoho_pricelist_id',
124 'cmbird_zoho_location_id_status',
125 'cmbird_zoho_inventory_auth_code',
126 'cmbird_zoho_inventory_access_token',
127 'cmbird_zoho_inventory_refresh_token',
128 'cmbird_zoho_inventory_timestamp',
129 'cmbird_zoho_inventory_oid',
130 'cmbird_zoho_inventory_url',
131 'cmbird_zoho_inventory_cid',
132 'cmbird_zoho_inventory_cs',
133 'cmbird_zoho_inventory_domain',
134 'cmbird_authorization_redirect_uri',
135 'cmbird_zoho_crm_auth_code',
136 'cmbird_zoho_crm_access_token',
137 'cmbird_zoho_crm_refresh_token',
138 'cmbird_zoho_crm_timestamp',
139 'cmbird_location_data',
140 );
141
142 foreach ( $zi_option_keys as $zi_option ) {
143 delete_option( $zi_option );
144 }
145
146 foreach ( $post_meta_keys as $post_key ) {
147 delete_post_meta_by_key( $post_key );
148 }
149
150 $users = get_users(
151 array(
152 'fields' => array( 'ID' ),
153 )
154 );
155 foreach ( $users as $user_id ) {
156 foreach ( $user_meta_keys as $user_key ) {
157 delete_user_meta( $user_id, $user_key );
158 }
159 }
160 // deleting mapped categories.
161 global $wpdb;
162 $table_name = $wpdb->prefix . 'options';
163 $sql = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM %s WHERE option_name LIKE %s', $table_name, '%zoho_id_for_term_id_%' ) );
164 foreach ( $sql as $key => $row ) {
165 $option_name = $row->option_name;
166 $wpdb->delete( $table_name, array( 'option_name' => $option_name ), array( '%s' ) );
167 }
168 // clear scheduled zcrm_refresh_token.
169 wp_clear_scheduled_hook( 'zcrm_refresh_token' );
170 }
171
172 /**
173 * Initializes the plugin.
174 *
175 * Removes the option for Zoho Inventory access token if it contains only one character.
176 * Schedules a cronjob for import sync if the access token is not empty and the interval is not set to 'none'.
177 * Creates the webhook password if it does not exist.
178 * Loads the necessary Ajax handlers and templates.
179 *
180 * @since 1.0.0
181 */
182 public static function init() {
183 if ( is_admin() ) {
184 $zoho_inventory_access_token = get_option( 'cmbird_zoho_inventory_access_token' );
185 // remove option zoho_inventory_access_token if it contains only one character.
186 if ( $zoho_inventory_access_token && strlen( $zoho_inventory_access_token ) === 1 ) {
187 delete_option( 'cmbird_zoho_inventory_access_token' );
188 } else {
189 // schedule cronjob for import sync.
190 $interval = get_option( 'zi_cron_interval' );
191 if ( 'none' !== $interval && ! empty( $zoho_inventory_access_token ) ) {
192 if ( ! wp_next_scheduled( 'zi_execute_import_sync' ) ) {
193 wp_schedule_event( time(), $interval, 'zi_execute_import_sync' );
194 }
195 } else {
196 wp_clear_scheduled_hook( 'zi_execute_import_sync' );
197 }
198 }
199 // create webhook password if does not exists.
200 if ( ! get_option( 'cmbird_zi_webhook_password', false ) ) {
201 add_option( 'cmbird_zi_webhook_password', password_hash( 'commercebird-zi-webhook-token', PASSWORD_BCRYPT ) );
202 }
203 Template::instance();
204 // Load the necessary Ajax handlers and templates.
205 ZohoInventoryAjax::instance();
206 ZohoCRMAjax::instance();
207 AcfAjax::instance();
208 SettingsAjax::instance();
209 ExactOnlineAjax::instance();
210 if ( class_exists( 'ACF' ) ) {
211 Cmbird_Acf::instance();
212 }
213 }
214 new Cmbird_WC_API();
215 new CMBIRD_Purchase_Orders_Automation();
216 }
217 }
218