PluginProbe ʕ •ᴥ•ʔ
CommerceBird – AI Command Center, ERP Integrations & B2B for WooCommerce (Zoho, Exact Online). / 2.2.17
CommerceBird – AI Command Center, ERP Integrations & B2B for WooCommerce (Zoho, Exact Online). v2.2.17
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 1 year ago includes 1 year ago languages 1 year ago vendor 1 year ago LICENSE 1 year ago changelog.txt 1 year ago commercebird.php 1 year ago composer.json 1 year ago data-sync.php 1 year ago index.php 1 year ago readme.txt 1 year ago
commercebird.php
233 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 by allowing you to upload product images, use integrations like Zoho Inventory, Zoho CRM, Exact Online and more. Requires a subscription at CommerceBird.com.
7 * Version: 2.2.17
8 * Requires PHP: 7.4
9 * Requires Plugins: woocommerce
10 * Requires at least: 6.5
11 * Tested up to: 6.7.1
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) 2024, CommerceBird
22 * @license https://www.gnu.org/licenses/gpl-3.0.html GPL-3.0-or-later
23 *
24 * WC requires at least: 9.4.0
25 * WC tested up to: 9.6.1
26 */
27
28 if ( ! defined( 'ABSPATH' ) ) {
29 exit; // Exit if accessed directly
30 }
31
32 if ( ! defined( 'CMBIRD_VERSION' ) ) {
33 define( 'CMBIRD_VERSION', '2.2.17' );
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 require_once CMBIRD_PATH . 'data-sync.php';
48
49 require __DIR__ . '/vendor/autoload.php';
50
51 use Automattic\WooCommerce\Utilities\FeaturesUtil;
52 use CommerceBird\Plugin;
53 use CommerceBird\Admin\Actions\Sync\ExactOnlineSync;
54 use CommerceBird\Admin\Actions\Sync\ZohoCRMSync;
55 use CommerceBird\API\ProductWebhook;
56 use CommerceBird\API\CreateOrderWebhook;
57 use CommerceBird\API\ShippingWebhook;
58 use CommerceBird\API\Zoho;
59 use CommerceBird\API\Exact;
60
61 /*
62 |--------------------------------------------------------------------------
63 | Activation, deactivation and uninstall event.
64 |--------------------------------------------------------------------------
65 */
66 register_activation_hook( __FILE__, array( Plugin::class, 'activate' ) );
67 register_deactivation_hook( __FILE__, array( Plugin::class, 'deactivate' ) );
68 register_uninstall_hook( __FILE__, array( Plugin::class, 'uninstall' ) );
69
70 /*
71 |--------------------------------------------------------------------------
72 | Load the plugin translations
73 |--------------------------------------------------------------------------
74 */
75 add_action( 'init', 'cmbird_load_textdomain' );
76 function cmbird_load_textdomain() {
77 load_plugin_textdomain( 'commercebird', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
78 }
79
80 /** Loading Purchase Order Class
81 * @since 1.0.0
82 */
83 function cmbird_purchase_order_class() {
84 if ( class_exists( 'WooCommerce' ) ) {
85 new CMBIRD_Purchase_Order();
86 }
87 }
88 add_action( 'woocommerce_init', 'cmbird_purchase_order_class' );
89 add_action( 'init', array( CMBIRD_PO_Admin_Manager::class, 'init' ), 11 );
90
91 /*
92 |--------------------------------------------------------------------------
93 | Start the plugin
94 |--------------------------------------------------------------------------
95 */
96 Plugin::init();
97
98 /**
99 * Declaring compatibility for WooCommerce HPOS
100 */
101 add_action(
102 'before_woocommerce_init',
103 function () {
104 if ( class_exists( FeaturesUtil::class) ) {
105 FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
106 }
107 }
108 );
109
110 /**
111 * Hooks for WC Action Scheduler to import or export products
112 */
113 $import_products = new CMBIRD_Products_ZI();
114 $import_pricelist = new CMBIRD_Pricelist_ZI();
115 $product_class = new CMBIRD_Products_ZI_Export();
116 $order_class = new CMBIRD_Order_Sync_ZI();
117 $contact_class = new CMBIRD_Contact_ZI();
118 $category_class = new CMBIRD_Categories_ZI();
119 $import_pricelist->wc_b2b_groups();
120 add_action( 'import_group_items_cron', array( $import_products, 'sync_groupitem_recursively' ), 10, 2 );
121 add_action( 'import_simple_items_cron', array( $import_products, 'sync_item_recursively' ), 10, 2 );
122 add_action( 'import_variable_product_cron', array( $import_products, 'import_variable_product_variations' ), 10, 2 );
123 add_action( 'sync_zi_product_cron', array( $product_class, 'cmbird_zi_products_prepare_sync' ), 10, 2 );
124 add_action( 'sync_zi_pricelist', array( $import_pricelist, 'zi_get_pricelist' ), 10, 2 );
125 add_action( 'sync_zi_order', array( $order_class, 'zi_orders_prepare_sync' ), 10, 2 );
126 add_action( 'sync_zi_import_contacts', array( $contact_class, 'cmbird_get_zoho_contacts' ), 10, 2 );
127 add_action( 'cmbird_zi_category_cron', array( $category_class, 'cmbird_zi_category_sync_call' ), 10 );
128 // add action to set the zoho rate limit option exceeded to false
129 add_action( 'cmbird_common', array( CMBIRD_Common_Functions::class, 'set_zoho_rate_limit_option' ) );
130 // Exact Online Hooks
131 add_action( 'cmbird_sync_eo', array( ExactOnlineSync::class, 'sync' ), 10, 3 );
132 add_action( 'cmbird_payment_status', array( ExactOnlineSync::class, 'cmbird_payment_status' ), 10, 1 );
133 add_action( 'cmbird_eo_get_payment_statuses', array( ExactOnlineSync::class, 'get_payment_status_via_cron' ) );
134 // Callback functions for scheduled action to process product or customer chunk
135 add_action( 'cmbird_process_product_chunk', function ($args) {
136 if ( ! is_array( $args ) || empty( $args['transient_key'] ) ) {
137 return;
138 }
139
140 $transient_key = $args['transient_key'];
141 $import_products = $args['import_products'] ?? false;
142
143 $chunked_products = get_transient( $transient_key );
144
145 if ( $chunked_products ) {
146 $sync = new ExactOnlineSync();
147 $sync->sync( 'product', $chunked_products, (bool) $import_products );
148
149 // Remove transient after processing
150 delete_transient( $transient_key );
151 }
152 }, 10, 1 );
153 add_action( 'cmbird_process_customer_chunk', function ($args) {
154 if ( ! is_array( $args ) || empty( $args['transient_key'] ) ) {
155 return;
156 }
157 $transient_key = $args['transient_key'];
158 $import_customers = $args['import_customers'] ?? false;
159
160 $chunked_customers = get_transient( $transient_key );
161
162 if ( $chunked_customers ) {
163 $sync = new ExactOnlineSync();
164 $sync->sync( 'customer', $chunked_customers, (bool) $import_customers );
165
166 // Remove transient after processing
167 delete_transient( $transient_key );
168 }
169 }, 10, 1 );
170 // Zoho CRM Hooks
171 add_action( 'init', array( ZohoCRMSync::class, 'refresh_token' ) );
172
173 // add classes to REST API
174 add_action(
175 'rest_api_init',
176 function () {
177 new Zoho();
178 new Exact();
179 new ProductWebhook();
180 new ShippingWebhook();
181 new CreateOrderWebhook();
182 $po_controller = new CMBIRD_REST_Shop_Purchase_Controller();
183 $po_controller->register_routes();
184 }
185 );
186
187 add_action(
188 'save_post',
189 function ($post_id, $post) {
190 if ( $post->post_type === 'wcb2b_group' ) {
191 delete_transient( 'wc_b2b_groups' );
192 }
193 },
194 10,
195 2
196 );
197
198 /**
199 * Perform actions when the plugin is updated
200 * @param string $upgrader_object
201 * @param array $options
202 * @return void
203 */
204 add_action( 'upgrader_process_complete', 'cmbird_update_plugin_tasks', 10, 2 );
205
206 function cmbird_update_plugin_tasks( $upgrader_object, $options ) {
207 $this_plugin = plugin_basename( __FILE__ );
208
209 if ( $options['action'] === 'update' && $options['type'] === 'plugin' ) {
210 foreach ( $options['plugins'] as $plugin ) {
211 if ( $plugin === $this_plugin ) {
212 // Perform tasks when the plugin is updated
213 $zoho_inventory_url = get_option( 'cmbird_zoho_inventory_url' );
214 if ( $zoho_inventory_url ) {
215 $new_zoho_inventory_url = str_replace( 'inventory.zoho', 'www.zohoapis', $zoho_inventory_url );
216 update_option( 'cmbird_zoho_inventory_url', $new_zoho_inventory_url );
217 }
218 // change the post meta key name from "cost_price" to "_cost_price" using wpdb query
219 global $wpdb;
220 $wpdb->query( "UPDATE $wpdb->postmeta SET meta_key = '_cost_price' WHERE meta_key = 'cost_price'" );
221 // add 'cmbird_' to every option key name that starts with 'zoho_' using wpdb query
222 $zoho_options = $wpdb->get_results( "SELECT option_name FROM $wpdb->options WHERE option_name LIKE 'zoho_%' OR option_name LIKE 'zi_%'" );
223 foreach ( $zoho_options as $zoho_option ) {
224 if ( strpos( $zoho_option->option_name, 'cmbird_' ) !== 0 ) {
225 $new_option_name = 'cmbird_' . $zoho_option->option_name;
226 $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->options SET option_name = %s WHERE option_name = %s", $new_option_name, $zoho_option->option_name ) );
227 }
228 }
229 }
230 }
231 }
232 }
233