| @@ -6,10 +6,10 @@ | ||
| 6 | 6 | * Author: PayPlug |
| 7 | 7 | * Author URI: https://www.payplug.com/ |
| 8 | 8 | * Text Domain: payplug |
| 9 | 9 | * Domain Path: /languages |
| 10 | - * Version: 1.2.3 | |
| 11 | - * WC tested up to: 5.1.0 | |
| 10 | + * Version: 2.10.0 | |
| 11 | + * WC tested up to: 9.3.3 | |
| 12 | 12 | * License: GPLv3 or later |
| 13 | 13 | * License URI: https://www.gnu.org/licenses/gpl-3.0.html |
| 14 | 14 | */ |
| 15 | 15 | |
| @@ -19,9 +19,11 @@ | ||
| 19 | 19 | // Exit if accessed directly |
| 20 | 20 | if ( ! defined( 'ABSPATH' ) ) { |
| 21 | 21 | exit; |
| 22 | 22 | } |
| 23 | -define( 'PAYPLUG_GATEWAY_VERSION', '1.2.3' ); | |
| 23 | + | |
| 24 | + | |
| 25 | +define( 'PAYPLUG_GATEWAY_VERSION', '2.10.0' ); | |
| 24 | 26 | define( 'PAYPLUG_GATEWAY_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); |
| 25 | 27 | define( 'PAYPLUG_GATEWAY_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); |
| 26 | 28 | define( 'PAYPLUG_GATEWAY_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); |
| 27 | 29 | |
| @@ -27,8 +29,17 @@ | ||
| 27 | 29 | |
| 28 | 30 | /** |
| 29 | 31 | * Plugin bootstrap function. |
| 30 | 32 | */ |
| 33 | + | |
| 34 | +/** | |
| 35 | + * $mo is the Mo object used to parse the English translations | |
| 36 | + * | |
| 37 | + * @var \MO | |
| 38 | + */ | |
| 39 | +global $mo; | |
| 40 | +$mo = new \MO(); | |
| 41 | + | |
| 31 | 42 | function init() { |
| 32 | 43 | if ( file_exists( plugin_dir_path( __FILE__ ) . '/vendor/autoload.php' ) ) { |
| 33 | 44 | require_once plugin_dir_path( __FILE__ ) . '/vendor/autoload.php'; |
| 34 | 45 | } |
| @@ -33,6 +44,51 @@ | ||
| 33 | 44 | require_once plugin_dir_path( __FILE__ ) . '/vendor/autoload.php'; |
| 34 | 45 | } |
| 35 | 46 | PayplugWoocommerceHelper::load_plugin_textdomain( plugin_basename( dirname( __FILE__ ) ) . '/languages' ); |
| 36 | 47 | PayplugWoocommerce::get_instance(); |
| 48 | + | |
| 49 | + // parse the English translation file | |
| 50 | + $path = WP_PLUGIN_DIR . '/' . plugin_basename( dirname( __FILE__ ) ) . '/languages/payplug-en_US.mo'; | |
| 51 | + $GLOBALS["mo"]->import_from_file($path); | |
| 37 | 52 | } |
| 53 | + | |
| 54 | +function create_lock_table(){ | |
| 55 | + init(); | |
| 56 | + \Payplug\PayplugWoocommerce\Model\Lock::create_lock_table(); | |
| 57 | +} | |
| 58 | + | |
| 59 | +add_action( 'upgrader_process_complete', __NAMESPACE__ . '\\create_lock_table', 10, 2 ); | |
| 60 | +add_action( 'activated_plugin', __NAMESPACE__ . '\\create_lock_table', 10, 2 ); | |
| 38 | 61 | add_action( 'plugins_loaded', __NAMESPACE__ . '\\init' ); |
| 62 | + | |
| 63 | +add_action( 'before_woocommerce_init', function() { | |
| 64 | + if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) { | |
| 65 | + \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true ); | |
| 66 | + } | |
| 67 | +} ); | |
| 68 | + | |
| 69 | +register_deactivation_hook( __FILE__, __NAMESPACE__ .'\\PayplugWoocommerceHelper::plugin_deactivation' ); | |
| 70 | + | |
| 71 | +/** | |
| 72 | + * A fail-safe in case a transltion does not exist shows the default translation (English) | |
| 73 | + * | |
| 74 | + * @param $msgstr string Translated text (Usually starts with "payplug_") | |
| 75 | + * @param $msgid string Text to translate (irrelevant because it is equal to $msgstr in this case) | |
| 76 | + * @param $domain string the domain is always = "payplug" (filter "gettext_payplug" is only for payplug translation domain) | |
| 77 | + * | |
| 78 | + * @return string | |
| 79 | + */ | |
| 80 | +function wpdocs_translate_text($msgstr, $msgid, $domain) | |
| 81 | +{ | |
| 82 | + $pattern = '/^payplug_.+/'; | |
| 83 | + | |
| 84 | + if (preg_match($pattern, $msgstr) === 1) { | |
| 85 | + if(isset($GLOBALS["mo"]->entries[$msgstr])) | |
| 86 | + return $GLOBALS["mo"]->entries[$msgstr]->translations[0]; | |
| 87 | + } | |
| 88 | + | |
| 89 | + return $msgstr; | |
| 90 | +} | |
| 91 | +add_filter('gettext_payplug', __NAMESPACE__ . '\\wpdocs_translate_text', 10, 3); | |
| 92 | + | |
| 93 | + | |
| 94 | + | |