From 160c6a7134c3dbeedb96b3b22dca92de55c4c987 Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Tue, 1 Oct 2024 14:15:32 +0200 Subject: [PATCH] Remove translations on update and flag --- inc/utils.php | 9 +++++++++ src/Activation/ActivationModule.php | 8 +++++++- src/Shared/SharedDataDictionary.php | 1 + 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/inc/utils.php b/inc/utils.php index 36103924..fae2c40c 100644 --- a/inc/utils.php +++ b/inc/utils.php @@ -190,8 +190,17 @@ function mollieWooCommerceFormatCurrencyValue($value, $currency) return number_format($value, 2, '.', ''); } +function mollieUpdateCompleted( $upgrader_object, $options ) { + //whenever something gets updated they update the languages, we need to delete them + mollieDeleteWPTranslationFiles(); +} + + function mollieDeleteWPTranslationFiles() { + if ( ! function_exists( 'WP_Filesystem' ) ) { + require_once ABSPATH . '/wp-admin/includes/file.php'; + } WP_Filesystem(); global $wp_filesystem; if (!$wp_filesystem) { diff --git a/src/Activation/ActivationModule.php b/src/Activation/ActivationModule.php index ef82ea30..598bcef2 100644 --- a/src/Activation/ActivationModule.php +++ b/src/Activation/ActivationModule.php @@ -82,7 +82,13 @@ public function initDb() */ public function handleTranslations(): void { - add_action('core_upgrade_preamble', 'mollieDeleteWPTranslationFiles'); + add_action('upgrader_process_complete', 'mollieUpdateCompleted', 10, 2); + // we need to handle this version specifically, we can remove this on the next + $translationFlag = get_option('mollie_plugin_update_translation'); + if ($translationFlag !== 'yes') { + mollieDeleteWPTranslationFiles(); + update_option('mollie_plugin_update_translation', 'yes'); + } } /** diff --git a/src/Shared/SharedDataDictionary.php b/src/Shared/SharedDataDictionary.php index e33282c2..ff7ec60b 100644 --- a/src/Shared/SharedDataDictionary.php +++ b/src/Shared/SharedDataDictionary.php @@ -88,6 +88,7 @@ class SharedDataDictionary '_transient_mollie-wc-giftcard_issuers_test', '_transient_timeout_mollie-wc-giftcard_issuers_live', '_transient_mollie-wc-giftcard_issuers_live', + 'mollie_plugin_update_translation' ]; public const DB_VERSION_PARAM_NAME = 'mollie-db-version'; public const PLUGIN_VERSION_PARAM_NAME = 'mollie-plugin-version';