PluginProbe ʕ •ᴥ•ʔ
CommerceBird – AI Command Center, ERP Integrations & B2B for WooCommerce (Zoho, Exact Online). / 2.8.5
CommerceBird – AI Command Center, ERP Integrations & B2B for WooCommerce (Zoho, Exact Online). v2.8.5
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 / commercebird.php
commercebird Last commit date
admin 2 months ago includes 2 months ago languages 1 year ago mu-plugins 5 months ago templates 2 months ago vendor 2 months ago LICENSE 1 year ago commercebird.php 2 months ago composer.json 2 months ago index.php 1 year ago readme.txt 2 months ago wp-dependencies.json 8 months ago
commercebird.php
307 lines
1 <?php
2 /**
3 * Plugin Name: CommerceBird
4 * Plugin URI: https://commercebird.com
5 * Author: CommerceBird
6 * Description: This plugin helps you get the most of CommerceBird AI App and use integrations like Zoho Inventory, Zoho CRM, Exact Online and more. Requires a subscription at CommerceBird.com.
7 * Version: 2.8.5
8 * Requires PHP: 8.2
9 * Requires Plugins: woocommerce
10 * Requires at least: 6.5
11 * Tested up to: 6.9
12 * Text Domain: commercebird
13 * Domain Path: /languages
14 *
15 * License: GNU General Public License v3.0
16 * License URI: http://www.gnu.org/licenses/gpl-3.0.html
17 *
18 * @category Fulfillment
19 * @package CommerceBird
20 * @author Fawad Tiemoerie <info@commercebird.com>
21 * @copyright Copyright (c) 2026, CommerceBird
22 * @license https://www.gnu.org/licenses/gpl-3.0.html GPL-3.0-or-later
23 *
24 * WC requires at least: 10.1.0
25 * WC tested up to: 10.7.0
26 */
27
28 if ( ! defined( 'ABSPATH' ) ) {
29 exit; // Exit if accessed directly.
30 }
31
32 if ( ! defined( 'CMBIRD_VERSION' ) ) {
33 define( 'CMBIRD_VERSION', '2.8.5' );
34 }
35 if ( ! defined( 'CMBIRD_PATH' ) ) {
36 define( 'CMBIRD_PATH', plugin_dir_path( __FILE__ ) );
37 }
38 if ( ! defined( 'CMBIRD_URL' ) ) {
39 define( 'CMBIRD_URL', plugin_dir_url( __FILE__ ) );
40 }
41 if ( ! defined( 'CMBIRD_MENU_SLUG' ) ) {
42 define( 'CMBIRD_MENU_SLUG', 'commercebird-app' );
43 }
44
45 require_once CMBIRD_PATH . 'includes/woo-functions.php';
46 require_once CMBIRD_PATH . 'includes/sync/order-backend.php';
47
48 // Load the Jetpack autoloader instead of vendor/autoload.php.
49 require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload_packages.php';
50
51 use Automattic\WooCommerce\Utilities\FeaturesUtil;
52 use WP\MCP\Core\McpAdapter;
53 use CommerceBird\Admin\Actions\Sync\ExactOnlineSync;
54 use CommerceBird\Admin\Actions\Sync\ZohoCRMSync;
55 use CommerceBird\API\CMBird_APIs;
56 use CommerceBird\API\CreateOrderWebhook;
57 use CommerceBird\API\Exact;
58 use CommerceBird\API\ProductWebhook;
59 use CommerceBird\API\ShippingWebhook;
60 use CommerceBird\API\Zoho;
61 use CommerceBird\CMBIRD_MCP;
62 use CommerceBird\Plugin;
63
64 /*
65 |--------------------------------------------------------------------------
66 | Activation, deactivation and uninstall event.
67 |--------------------------------------------------------------------------
68 */
69
70 register_activation_hook( __FILE__, array( Plugin::class, 'activate' ) );
71 register_deactivation_hook( __FILE__, array( Plugin::class, 'deactivate' ) );
72 register_uninstall_hook( __FILE__, array( Plugin::class, 'uninstall' ) );
73
74 /*
75 |--------------------------------------------------------------------------
76 | Load the plugin translations
77 |--------------------------------------------------------------------------
78 | Note: WordPress.org automatically loads translations for plugins since WP 4.6.
79 | Manual loading not required for plugins hosted on WordPress.org.
80 */
81
82 /** Loading Purchase Order Class
83 *
84 * @since 1.0.0
85 */
86 function cmbird_purchase_order_class() {
87 if ( class_exists( 'WooCommerce' ) ) {
88 new CMBIRD_Purchase_Order();
89 }
90 }
91 add_action( 'woocommerce_init', 'cmbird_purchase_order_class' );
92 add_action( 'init', array( CMBIRD_PO_Admin_Manager::class, 'init' ), 11 );
93
94 /*
95 |--------------------------------------------------------------------------
96 | Start the plugin
97 |--------------------------------------------------------------------------
98 */
99 Plugin::init();
100
101 /**
102 * Declaring compatibility for WooCommerce HPOS
103 */
104 add_action(
105 'before_woocommerce_init',
106 function () {
107 if ( class_exists( FeaturesUtil::class ) ) {
108 FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
109 FeaturesUtil::declare_compatibility( 'product_instance_caching', __FILE__, true );
110 }
111 }
112 );
113
114 /*
115 --------------------------------------------------------------------------
116 | Install required dependencies
117 |--------------------------------------------------------------------------
118 */
119 add_action(
120 'plugins_loaded',
121 static function () {
122 // Initialize Quotes module.
123 CMBIRD_Quotes::init();
124 // Initialize MCP abilities.
125 CMBIRD_MCP::init();
126 // Only if Premium plan is active via transient subscription_details.
127 $subscription = get_transient( 'subscription_details' );
128 // return if no subscription found.
129 if ( empty( $subscription ) ) {
130 return;
131 }
132 if ( 'active' === $subscription['status'] ) {
133 if ( in_array( $subscription['plan'], array( 'premium', 'Premium' ), true ) ) {
134 if ( class_exists( 'ACF' ) ) {
135 return;
136 }
137 WP_Dependency_Installer::instance( __DIR__ )->run();
138 }
139 }
140 }
141 );
142
143 /**
144 * Hooks for WC Action Scheduler to import or export products
145 */
146 $cmbird_import_products = new CMBIRD_Products_ZI();
147 $cmbird_import_pricelist = new CMBIRD_Pricelist_ZI();
148 $cmbird_product_class = new CMBIRD_Products_ZI_Export();
149 $cmbird_common_class = new CMBIRD_Common_Functions();
150 $cmbird_contact_class = new CMBIRD_Contact_ZI();
151 $cmbird_category_class = new CMBIRD_Categories_ZI();
152 $cmbird_import_pricelist->wc_b2b_groups();
153 add_action( 'import_group_items_cron', array( $cmbird_import_products, 'sync_groupitem_recursively' ), 10, 2 );
154 add_action( 'import_simple_items_cron', array( $cmbird_import_products, 'sync_items_batch' ), 10, 2 );
155 add_action( 'import_variable_product_cron', array( $cmbird_import_products, 'import_variable_product_variations' ), 10, 2 );
156 add_action( 'sync_zi_product_cron', array( $cmbird_product_class, 'cmbird_zi_products_prepare_sync' ), 10, 2 );
157 add_action( 'sync_zi_pricelist', array( $cmbird_import_pricelist, 'zi_get_pricelist' ), 10, 2 );
158 add_action( 'sync_zi_order', array( $cmbird_common_class, 'cmbird_orders_prepare_sync' ), 10, 2 );
159 add_action( 'sync_zi_import_contacts', array( $cmbird_contact_class, 'cmbird_get_zoho_contacts' ), 10, 2 );
160 // add action to set the zoho rate limit option exceeded to false.
161 add_action( 'cmbird_common', array( CMBIRD_Common_Functions::class, 'set_zoho_rate_limit_option' ) );
162 // Zoho CRM Hooks.
163 add_action( 'sync_zcrm_order', array( $cmbird_common_class, 'cmbird_orders_prepare_sync' ) );
164 add_action( 'sync_zcrm_contact', array( ZohoCRMSync::class, 'cmbird_zcrm_contact_sync' ) );
165 // Exact Online Hooks.
166 add_action( 'cmbird_sync_eo', array( ExactOnlineSync::class, 'sync' ), 10, 3 );
167 add_action( 'cmbird_exact_online_sync_orders', array( ExactOnlineSync::class, 'sync_orders_via_cron' ) );
168 add_action( 'cmbird_payment_status', array( ExactOnlineSync::class, 'cmbird_payment_status' ), 10, 1 );
169 add_action( 'cmbird_eo_get_payment_statuses', array( ExactOnlineSync::class, 'get_payment_status_via_cron' ) );
170 // Callback functions for scheduled action to process product or customer chunk.
171 add_action(
172 'cmbird_process_product_chunk',
173 function ( $args ) {
174 if ( ! is_array( $args ) || empty( $args['transient_key'] ) ) {
175 return;
176 }
177 $transient_key = $args['transient_key'];
178 $import_products = $args['import_products'] ?? false;
179 $chunked_products = get_transient( $transient_key );
180 if ( $chunked_products ) {
181 $sync = new ExactOnlineSync();
182 $sync->sync( 'product', $chunked_products, (bool) $import_products );
183 // Remove transient after processing.
184 delete_transient( $transient_key );
185 }
186 },
187 10,
188 1
189 );
190 add_action(
191 'cmbird_process_customer_chunk',
192 function ( $args ) {
193 if ( ! is_array( $args ) || empty( $args['transient_key'] ) ) {
194 return;
195 }
196 $transient_key = $args['transient_key'];
197 $import_customers = $args['import_customers'] ?? false;
198 $chunked_customers = get_transient( $transient_key );
199 if ( $chunked_customers ) {
200 $sync = new ExactOnlineSync();
201 $sync->sync( 'customer', $chunked_customers, (bool) $import_customers );
202 // Remove transient after processing.
203 delete_transient( $transient_key );
204 }
205 },
206 10,
207 1
208 );
209 // Zoho CRM Hooks.
210 add_action( 'init', array( ZohoCRMSync::class, 'refresh_token' ) );
211 // Zoho Inventory Cron Hook for importing items.
212 add_action( 'zi_execute_import_sync', array( Plugin::class, 'dispatch_import_simple_items' ) );
213
214 // add classes to REST API.
215 add_action(
216 'rest_api_init',
217 function () {
218 new Zoho();
219 new Exact();
220 new ProductWebhook();
221 new ShippingWebhook();
222 new CreateOrderWebhook();
223 new CMBird_APIs();
224 $po_controller = new CMBIRD_REST_Shop_Purchase_Controller();
225 $po_controller->register_routes();
226 }
227 );
228
229 add_action(
230 'save_post',
231 function ( $post_id, $post ) {
232 if ( 'wcb2b_group' === $post->post_type ) {
233 delete_transient( 'wc_b2b_groups' );
234 }
235 },
236 10,
237 2
238 );
239
240 /**
241 * Perform actions when the plugin is updated
242 *
243 * @param string $upgrader_object
244 * @param array $options
245 * @return void
246 */
247 add_action( 'upgrader_process_complete', 'cmbird_update_plugin_tasks', 10, 2 );
248
249 /**
250 * Perform tasks when the plugin is updated.
251 *
252 * @param \WP_Upgrader $upgrader_object - Upgrader object.
253 * @param array $options - Options array.
254 *
255 * @see https://developer.wordpress.org/reference/hooks/upgrader_process_complete/
256 */
257 function cmbird_update_plugin_tasks( $upgrader_object, $options ) {
258 $this_plugin = plugin_basename( __FILE__ );
259
260 if ( ! is_array( $options ) ) {
261 return;
262 }
263
264 if ( ! isset( $options['action'], $options['type'], $options['plugins'] ) || ! is_array( $options['plugins'] ) ) {
265 return;
266 }
267
268 if ( 'update' === $options['action'] && 'plugin' === $options['type'] ) {
269 foreach ( $options['plugins'] as $plugin ) {
270 if ( $plugin === $this_plugin ) {
271 // Perform tasks when the plugin is updated.
272 // Updating meta key from '_cost_price' to '_cogs_total_value'.
273 global $wpdb;
274 $table_name = $wpdb->prefix . 'postmeta';
275 $wpdb->query(
276 $wpdb->prepare(
277 "UPDATE {$table_name} SET meta_key = %s WHERE meta_key = %s",
278 '_cogs_total_value',
279 '_cost_price'
280 )
281 );
282 // Enable MCP WooCommerce integration. Remove this when enabled in Woo core.
283 update_option( 'woocommerce_feature_mcp_integration_enabled', 'yes' );
284 // One-time cleanup for old per-minute Zoho API rate limit counters.
285 $wpdb->query(
286 $wpdb->prepare(
287 "DELETE FROM {$wpdb->options} WHERE option_name LIKE %s",
288 $wpdb->esc_like( 'cmbird_zoho_api_calls_' ) . '%'
289 )
290 );
291 break;
292 }
293 }
294 }
295 }
296
297 /**
298 * Instantiate the MCP adapter. Remove this when its included in Woo core.
299 */
300 // 1. Check if MCP Adapter is available
301 if ( ! class_exists( McpAdapter::class ) ) {
302 // Handle missing dependency (show admin notice, etc.).
303 return;
304 }
305 // 2. Initialize the adapter
306 McpAdapter::instance();
307