| @@ -1,15 +1,16 @@ | ||
| 1 | 1 | <?php |
| 2 | + | |
| 2 | 3 | /** |
| 3 | 4 | * @link https://makecommerce.net/ |
| 4 | - * @since 4.0.0 | |
| 5 | - * @package Makecommerce | |
| 5 | + * @since 3.0.0 | |
| 6 | + * @package Makecommerce | |
| 6 | 7 | * |
| 7 | 8 | * @wordpress-plugin |
| 8 | 9 | * Plugin Name: MakeCommerce |
| 9 | 10 | * Plugin URI: https://makecommerce.net/ |
| 10 | - * Description: Adds MakeCommerce payment gateway and shipping methods to WooCommerce checkout | |
| 11 | - * Version: 4.1.0 | |
| 11 | + * Description: Adds MakeCommerce payment gateway and Itella/Omniva/DPD parcel machine shipping methods to WooCommerce checkout | |
| 12 | + * Version: 3.3.1 | |
| 12 | 13 | * Author: Maksekeskus AS |
| 13 | 14 | * Author URI: https://makecommerce.net/ |
| 14 | 15 | * License: GPL-2.0+ |
| 15 | 16 | * License URI: http://www.gnu.org/licenses/gpl-2.0.txt |
| @@ -14,33 +15,187 @@ | ||
| 14 | 15 | * License: GPL-2.0+ |
| 15 | 16 | * License URI: http://www.gnu.org/licenses/gpl-2.0.txt |
| 16 | 17 | * Text Domain: makecommerce |
| 17 | 18 | * Domain Path: /languages |
| 18 | - * Requires Plugins: woocommerce | |
| 19 | - * Requires at least: 6.8.1 | |
| 20 | - * Requires PHP: 8.1 | |
| 21 | - * WC requires at least: 9.9.3 | |
| 22 | - * WC tested up to: 11.0.1 | |
| 23 | - * WC HPOS compatibility: yes | |
| 24 | - * WC Legacy Order Table Compatibility: yes | |
| 19 | + * Requires at least: 5.6.1 | |
| 20 | + * Requires PHP: 7.4 | |
| 21 | + * WC requires at least: 5.0.0 | |
| 22 | + * WC tested up to: 8.2.1 | |
| 25 | 23 | */ |
| 26 | 24 | |
| 27 | -function mc_table_exists(string $table): bool { | |
| 28 | - global $wpdb; | |
| 29 | - $table_name = $wpdb->prefix . $table; | |
| 30 | - return $wpdb->get_var($wpdb->prepare("SHOW TABLES LIKE %s", $table_name)) === $table_name; | |
| 25 | +// If this file is called directly, abort. | |
| 26 | +if ( ! defined( 'WPINC' ) ) { | |
| 27 | + die; | |
| 31 | 28 | } |
| 32 | 29 | |
| 30 | +/** | |
| 31 | + * Currently plugin version. | |
| 32 | + * Start at version 3.0.0 and use SemVer - https://semver.org | |
| 33 | + */ | |
| 34 | +define( 'MAKECOMMERCE_VERSION', '3.3.1' ); | |
| 35 | +define( 'MAKECOMMERCE_PLUGIN_ID', 'makecommerce' ); | |
| 33 | 36 | |
| 34 | -if ( | |
| 35 | - ( | |
| 36 | - get_option('mc_version') !== false || | |
| 37 | - get_option('wc_mc_version') !== false || | |
| 38 | - mc_table_exists('mc_banklinks') | |
| 39 | - ) && | |
| 40 | - !filter_var(get_option('mc_shipping_plus'), FILTER_VALIDATE_BOOLEAN) | |
| 41 | -) { | |
| 42 | - require_once plugin_dir_path(__FILE__) . 'config.php'; | |
| 43 | -} else { | |
| 44 | - require_once plugin_dir_path(__FILE__) . 'makecommerce/makecommerce.php'; | |
| 37 | +//table name for banklinks | |
| 38 | +define( 'MAKECOMMERCE_TABLENAME', 'mc_banklinks' ); | |
| 39 | + | |
| 40 | +//WC makecommerce version | |
| 41 | +define( 'WC_MC_VERSION', 2.0 ); | |
| 42 | + | |
| 43 | +//Tracking service link | |
| 44 | +define( 'MC_TRACKING_SERVICE_URL', 'https://tracking.makecommerce.net/' ); | |
| 45 | + | |
| 46 | +register_activation_hook( __FILE__, 'activate_makecommerce' ); | |
| 47 | +register_deactivation_hook( __FILE__, 'deactivate_makecommerce' ); | |
| 48 | + | |
| 49 | +/** | |
| 50 | + * Check if we are ok to continue (if namesoace and class doesn't already exist) | |
| 51 | + */ | |
| 52 | +if ( class_exists( 'MakeCommerce' ) || namespaceExists( 'MakeCommerce' ) ) { | |
| 53 | + | |
| 54 | + add_action( 'admin_notices', 'namespace_or_class_already_in_use' ); | |
| 55 | + | |
| 56 | + deactivate_plugins( plugin_dir_path( __FILE__ ) . '/makecommerce.php' ); | |
| 57 | + | |
| 58 | + return false; | |
| 45 | 59 | } |
| 46 | 60 | |
| 61 | +/** | |
| 62 | + * Check if a namespace already exists | |
| 63 | + * | |
| 64 | + * @since 3.0.0 | |
| 65 | + */ | |
| 66 | +function namespaceExists( $namespace ) { | |
| 67 | + | |
| 68 | + $namespace .= "\\"; | |
| 69 | + | |
| 70 | + foreach ( get_declared_classes() as $name ) { | |
| 71 | + | |
| 72 | + if ( strpos( $name, $namespace ) === 0 ) { | |
| 73 | + return true; | |
| 74 | + } | |
| 75 | + } | |
| 76 | + | |
| 77 | + return false; | |
| 78 | +} | |
| 79 | + | |
| 80 | +/** | |
| 81 | + * Shows error in admin that we cannot continue | |
| 82 | + * | |
| 83 | + * @since 3.0.0 | |
| 84 | + */ | |
| 85 | +function namespace_or_class_already_in_use() { | |
| 86 | + | |
| 87 | + ?> | |
| 88 | + <div class="error notice"> | |
| 89 | + <p><?php _e( 'Cannot initiate MakeCommerce, a class and/or namespace called "MakeCommerce" is already in use somewhere else...', 'wc_makecommerce_domain' ); ?></p> | |
| 90 | + </div> | |
| 91 | + <?php | |
| 92 | +} | |
| 93 | + | |
| 94 | +/** | |
| 95 | + * Check if WooCommerce exists and is active. Can't do much without it | |
| 96 | + */ | |
| 97 | +if ( !in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { | |
| 98 | + | |
| 99 | + if ( is_multisite() ) { | |
| 100 | + | |
| 101 | + include_once( ABSPATH . "wp-admin/includes/plugin.php" ); | |
| 102 | + if ( !is_plugin_active_for_network( "woocommerce/woocommerce.php" ) ) { | |
| 103 | + woocommerce_not_found_or_active(); | |
| 104 | + | |
| 105 | + return false; | |
| 106 | + } | |
| 107 | + } else { | |
| 108 | + woocommerce_not_found_or_active(); | |
| 109 | + | |
| 110 | + return false; | |
| 111 | + } | |
| 112 | +} | |
| 113 | + | |
| 114 | +/** | |
| 115 | + * If no WooCommerce is found | |
| 116 | + * | |
| 117 | + * @since 3.0.3 | |
| 118 | + */ | |
| 119 | +function woocommerce_not_found_or_active() { | |
| 120 | + | |
| 121 | + add_action( 'admin_notices', 'no_woocommerce_found' ); | |
| 122 | + | |
| 123 | + deactivate_makecommerce(); | |
| 124 | +} | |
| 125 | + | |
| 126 | +/** | |
| 127 | + * Shows error in admin that we cannot continue | |
| 128 | + * | |
| 129 | + * @since 3.0.0 | |
| 130 | + */ | |
| 131 | +function no_woocommerce_found() { | |
| 132 | + | |
| 133 | + ?> | |
| 134 | + <div class="error notice"> | |
| 135 | + <p><?php _e( 'Cannot initiate MakeCommerce, there seems to be no WooCommerce present or active...', 'wc_makecommerce_domain' ); ?></p> | |
| 136 | + </div> | |
| 137 | + <?php | |
| 138 | +} | |
| 139 | + | |
| 140 | +/** | |
| 141 | + * Disable automatic updates for MakeCommerce plugin | |
| 142 | + * | |
| 143 | + * @since 3.0.1 | |
| 144 | + */ | |
| 145 | +function disable_makecommerce_automatic_updates( $should_update, $plugin ) { | |
| 146 | + | |
| 147 | + if ( ! isset( $plugin->plugin, $plugin->new_version ) ) { | |
| 148 | + return $should_update; | |
| 149 | + } | |
| 150 | + | |
| 151 | + if ( 'makecommerce/makecommerce.php' !== $plugin->plugin ) { | |
| 152 | + return $should_update; | |
| 153 | + } | |
| 154 | + | |
| 155 | + return false; | |
| 156 | +} | |
| 157 | + | |
| 158 | +add_filter( 'auto_update_plugin', 'disable_makecommerce_automatic_updates', 99, 2 ); | |
| 159 | + | |
| 160 | +/** | |
| 161 | + * The code that runs during plugin activation. | |
| 162 | + * This action is documented in includes/class-makecommerce-activator.php | |
| 163 | + * | |
| 164 | + * @since 3.0.1 | |
| 165 | + */ | |
| 166 | +function activate_makecommerce() { | |
| 167 | + | |
| 168 | + require_once plugin_dir_path( __FILE__ ) . 'includes/activator.php'; | |
| 169 | + MakeCommerce\Activator::activate(); | |
| 170 | +} | |
| 171 | + | |
| 172 | +/** | |
| 173 | + * The code that runs during plugin deactivation. | |
| 174 | + * This action is documented in includes/class-makecommerce-deactivator.php | |
| 175 | + * | |
| 176 | + * @since 3.0.1 | |
| 177 | + */ | |
| 178 | +function deactivate_makecommerce() { | |
| 179 | + | |
| 180 | + require_once plugin_dir_path( __FILE__ ) . 'includes/deactivator.php'; | |
| 181 | + MakeCommerce\Deactivator::deactivate(); | |
| 182 | +} | |
| 183 | + | |
| 184 | +/** | |
| 185 | + * The core plugin class that is used to define internationalization, | |
| 186 | + * payment-specific hooks, and shipping-specific site hooks. | |
| 187 | + */ | |
| 188 | +require plugin_dir_path( __FILE__ ) . 'includes/makecommerce.php'; | |
| 189 | + | |
| 190 | +/** | |
| 191 | + * Begins execution of the plugin. | |
| 192 | + * | |
| 193 | + * @since 3.0.0 | |
| 194 | + */ | |
| 195 | +function run_makecommerce() { | |
| 196 | + | |
| 197 | + $makeCommerce = new MakeCommerce(); | |
| 198 | + $makeCommerce->run(); | |
| 199 | +} | |
| 200 | + | |
| 201 | +run_makecommerce(); | |