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