PluginProbe
CommerceBird – AI Command Center, ERP Integrations & B2B for WooCommerce (Zoho, Exact Online). / 2.5.2
CommerceBird – AI Command Center, ERP Integrations & B2B for WooCommerce (Zoho, Exact Online). v2.5.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 All 65 releases
← All changes | includes/classes/class-plugin.php +21 -130 trunk2.5.2 View file →
@@ -14,11 +14,8 @@
14 14 use CommerceBird\Admin\Actions\Ajax\AcfAjax;
15 15 use CommerceBird\Admin\Actions\Ajax\SettingsAjax;
16 16 use CommerceBird\Admin\Template;
17 17 use CommerceBird\Admin\Cmbird_Acf;
18 -use CommerceBird\CMBIRD_AI_Product_Blocks_Block;
19 -use CommerceBird\CMBIRD_AI_Product_Blocks_Cron;
20 -use CommerceBird\CMBIRD_AI_Product_Blocks_Display;
21 18 use CommerceBird\Cmbird_WC_API;
22 19 use CMBIRD_Purchase_Orders_Automation;
23 20
24 21 /**
@@ -42,74 +39,37 @@
42 39 add_action( 'admin_init', array( $this, 'init' ) );
43 40 }
44 41
45 42 /**
46 - * Plugin activation handler.
47 - *
48 - * - Installs the MU CLI helper.
49 - * - Ensures the "vendor" role exists.
50 - * - Creates {$wpdb->prefix}cmbird_zi_category_map via dbDelta (idempotent).
51 - *
52 - * @since 1.0.0
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)
53 51 */
54 52 public static function activate() {
55 - CMBIRD_AI_Product_Blocks_Cron::activate();
56 - // Create the "vendor" role — must run at activation, not on every init.
57 - if ( ! get_role( 'vendor' ) ) {
58 - add_role(
59 - 'vendor',
60 - __( 'Vendor', 'commercebird' ),
61 - array( 'read' => true )
62 - );
63 - }
64 -
65 - self::ensure_zi_category_map_table();
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 );
66 59 }
67 60
68 61 /**
69 - * Ensure the Zoho category mapping table exists.
70 - *
71 - * Uses dbDelta so it is safe to call repeatedly on activation and upgrades.
72 - *
73 - * @since 2.9.2
74 - * @return void
75 - */
76 - public static function ensure_zi_category_map_table() {
77 - global $wpdb;
78 - $charset_collate = $wpdb->get_charset_collate();
79 - $table = $wpdb->prefix . 'cmbird_zi_category_map';
80 - $sql = "CREATE TABLE {$table} (
81 - id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
82 - wc_term_id BIGINT UNSIGNED NOT NULL,
83 - zoho_category_id VARCHAR(64) NOT NULL,
84 - source ENUM('auto','manual') NOT NULL DEFAULT 'auto',
85 - status ENUM('active','orphan','review') NOT NULL DEFAULT 'active',
86 - review_reason VARCHAR(64) NULL,
87 - created_at DATETIME NOT NULL,
88 - updated_at DATETIME NOT NULL,
89 - last_verified_at DATETIME NULL,
90 - PRIMARY KEY (id),
91 - UNIQUE KEY uniq_wc_term_active (wc_term_id, status),
92 - UNIQUE KEY uniq_zoho_id_active (zoho_category_id, status),
93 - KEY status_idx (status)
94 - ) $charset_collate;";
95 - dbDelta( $sql );
96 - }
97 -
98 - /**
99 62 * Clear all the scheduled actions when the plugin is deactivated.
100 63 *
101 64 * @since 1.0.0
102 65 */
103 66 public static function deactivate() {
104 - CMBIRD_AI_Product_Blocks_Cron::deactivate();
105 67 wp_clear_scheduled_hook( 'zi_execute_import_sync' );
106 68 wp_clear_scheduled_hook( 'cmbird_eo_get_payment_statuses' );
107 69 wp_clear_scheduled_hook( 'cmbird_exact_online_sync_orders' );
108 - wp_clear_scheduled_hook( 'cmbird_eo_product_mapping_daily' );
109 70 wp_clear_scheduled_hook( 'cmbird_zoho_sync_category_cron' );
110 71 wp_clear_scheduled_hook( 'cmbird_zoho_contact_sync' );
111 - wp_clear_scheduled_hook( 'cmbird_zi_salesorder_cron_daily' );
112 72 }
113 73
114 74 /**
115 75 * Deletes all the options and post/user meta set by the plugin.
@@ -170,9 +130,8 @@
170 130 'cmbird_zoho_inventory_url',
171 131 'cmbird_zoho_inventory_cid',
172 132 'cmbird_zoho_inventory_cs',
173 133 'cmbird_zoho_inventory_domain',
174 - 'cmbird_zoho_service',
175 134 'cmbird_authorization_redirect_uri',
176 135 'cmbird_zoho_crm_auth_code',
177 136 'cmbird_zoho_crm_access_token',
178 137 'cmbird_zoho_crm_refresh_token',
@@ -177,13 +136,8 @@
177 136 'cmbird_zoho_crm_access_token',
178 137 'cmbird_zoho_crm_refresh_token',
179 138 'cmbird_zoho_crm_timestamp',
180 139 'cmbird_location_data',
181 - 'cmbird_ai_review_summary_enabled',
182 - 'cmbird_ai_review_summary_prompt',
183 - 'cmbird_ai_content_writer_enabled',
184 - 'cmbird_ai_shopping_experience_enabled',
185 - 'cmbird_eo_product_cron_enabled',
186 140 );
187 141
188 142 foreach ( $zi_option_keys as $zi_option ) {
189 143 delete_option( $zi_option );
@@ -202,28 +156,18 @@
202 156 foreach ( $user_meta_keys as $user_key ) {
203 157 delete_user_meta( $user_id, $user_key );
204 158 }
205 159 }
206 - // Drop the category mapping table.
160 + // deleting mapped categories.
207 161 global $wpdb;
208 - $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}cmbird_zi_category_map" ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
209 -
210 - // Clean up any legacy mapping options (covers installs that never ran the migration).
211 - $wpdb->query(
212 - "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'cmbird_zoho_id_for_term_id_%'" // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
213 - );
214 -
215 - // And the migration flags.
216 - delete_option( 'cmbird_zi_category_map_migrated' );
217 - delete_option( 'cmbird_zi_category_map_legacy_purged' );
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 + }
218 168 // clear scheduled zcrm_refresh_token.
219 169 wp_clear_scheduled_hook( 'zcrm_refresh_token' );
220 -
221 - // Remove the mu-plugin file.
222 - $mu_plugin_file = WP_CONTENT_DIR . '/mu-plugins/cmbird-media-cleanup-cli.php';
223 - if ( file_exists( $mu_plugin_file ) ) {
224 - wp_delete_file( $mu_plugin_file );
225 - }
226 170 }
227 171
228 172 /**
229 173 * Initializes the plugin.
@@ -235,12 +179,8 @@
235 179 *
236 180 * @since 1.0.0
237 181 */
238 182 public static function init() {
239 - new CMBIRD_AI_Product_Blocks_Cron();
240 - new CMBIRD_AI_Product_Blocks_Display();
241 - new CMBIRD_AI_Product_Blocks_Block();
242 -
243 183 if ( is_admin() ) {
244 184 $zoho_inventory_access_token = get_option( 'cmbird_zoho_inventory_access_token' );
245 185 // remove option zoho_inventory_access_token if it contains only one character.
246 186 if ( $zoho_inventory_access_token && strlen( $zoho_inventory_access_token ) === 1 ) {
@@ -267,60 +207,11 @@
267 207 AcfAjax::instance();
268 208 SettingsAjax::instance();
269 209 ExactOnlineAjax::instance();
270 210 if ( class_exists( 'ACF' ) ) {
271 - AcfAjax::instance();
272 211 Cmbird_Acf::instance();
273 212 }
274 213 }
275 214 new Cmbird_WC_API();
276 215 new CMBIRD_Purchase_Orders_Automation();
277 - }
278 -
279 - /**
280 - * Cron callback for zoho import sync interval.
281 - *
282 - * When the WP cron fires this hook we simply forward the request to the
283 - * existing `import_simple_items_cron` action. That action is already
284 - * registered in the main plugin bootstrapping script and handles batch
285 - * scheduling via Action Scheduler. Passing along the arguments allows for
286 - * backwards compatibility if anybody ever runs the hook manually with
287 - * parameters.
288 - *
289 - * @since 2.7.7
290 - * @param mixed ...$args Optional arguments supplied by do_action.
291 - * @return void
292 - */
293 - public static function dispatch_import_simple_items( ...$args ) {
294 - // if the event was fired with explicit arguments we simply forward them.
295 - // to the existing hook (primarily useful for manual/testing purposes).
296 - if ( ! empty( $args ) ) {
297 - do_action( 'import_simple_items_cron', ...$args );
298 - return;
299 - }
300 - $zi_common_class = new \CMBIRD_Common_Functions();
301 - $zi_common_class->clear_orphan_data();
302 -
303 - // categories are stored as serialized zoho ids; convert them to WC terms.
304 - $zoho_item_category = get_option( 'cmbird_zoho_item_category' );
305 - if ( $zoho_item_category ) {
306 - // convert serialized string to array.
307 - $categories = maybe_unserialize( $zoho_item_category );
308 - if ( ! is_array( $categories ) ) {
309 - return; // invalid format -> nothing to do.
310 - }
311 - } else {
312 - return; // no categories configured -> nothing to do.
313 - }
314 - foreach ( $categories as $category_id ) {
315 - $data = array(
316 - 'page' => 1,
317 - 'category' => $category_id,
318 - );
319 - if ( function_exists( 'as_has_scheduled_action' )
320 - && ! as_has_scheduled_action( 'import_simple_items_cron', $data, 'commercebird' )
321 - ) {
322 - as_schedule_single_action( time(), 'import_simple_items_cron', $data, 'commercebird' );
323 - }
324 - }
325 216 }
326 217 }