From 1c128d8ebdc8c59ab1c4ee778ecba437a163c1eb Mon Sep 17 00:00:00 2001 From: claudiosmweb Date: Wed, 4 Jun 2014 13:01:38 -0300 Subject: [PATCH] added a notice to display messages about available translation upgrades --- includes/admin/class-wc-admin-notices.php | 17 +++++++++++++- .../views/html-notice-translation-upgrade.php | 12 ++++++++++ includes/class-wc-language-pack-upgrader.php | 22 +++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 includes/admin/views/html-notice-translation-upgrade.php diff --git a/includes/admin/class-wc-admin-notices.php b/includes/admin/class-wc-admin-notices.php index 0f0fd615889..107dc979c24 100644 --- a/includes/admin/class-wc-admin-notices.php +++ b/includes/admin/class-wc-admin-notices.php @@ -67,6 +67,10 @@ class WC_Admin_Notices { wp_enqueue_style( 'woocommerce-activation', plugins_url( '/assets/css/activation.css', WC_PLUGIN_FILE ) ); add_action( 'admin_notices', array( $this, 'template_file_check_notice' ) ); } + + if ( in_array( 'translation_upgrade', $notices ) ) { + add_action( 'admin_notices', array( $this, 'translation_upgrade_notice' ) ); + } } /** @@ -91,6 +95,17 @@ class WC_Admin_Notices { include( 'views/html-notice-theme-support.php' ); } + /** + * Show the translation upgrade notice + */ + public function translation_upgrade_notice() { + $screen = get_current_screen(); + + if ( 'update-core' !== $screen->id ) { + include( 'views/html-notice-translation-upgrade.php' ); + } + } + /** * Show a notice highlighting bad template files */ @@ -133,4 +148,4 @@ class WC_Admin_Notices { endif; -return new WC_Admin_Notices(); \ No newline at end of file +return new WC_Admin_Notices(); diff --git a/includes/admin/views/html-notice-translation-upgrade.php b/includes/admin/views/html-notice-translation-upgrade.php new file mode 100644 index 00000000000..df3aa5e3d73 --- /dev/null +++ b/includes/admin/views/html-notice-translation-upgrade.php @@ -0,0 +1,12 @@ + +
+

WooCommerce Translation Available – do the upgrade / installation of your translations.', 'woocommerce' ); ?>

+
+ +

+
+
diff --git a/includes/class-wc-language-pack-upgrader.php b/includes/class-wc-language-pack-upgrader.php index cd2c28c4906..fc3e668c16d 100644 --- a/includes/class-wc-language-pack-upgrader.php +++ b/includes/class-wc-language-pack-upgrader.php @@ -87,6 +87,8 @@ class WC_Language_Pack_Upgrader { if ( version_compare( $version, WC_VERSION, '<' ) && 'en' !== $this->get_language() ) { if ( $this->check_if_language_pack_exists() ) { + $this->configure_woocommerce_upgrade_notice(); + return true; } else { // Updated the woocommerce_language_pack_version to avoid searching translations for this release again @@ -97,6 +99,20 @@ class WC_Language_Pack_Upgrader { return false; } + /** + * Configure the WooCommerce translation upgrade notice + * + * @return void + */ + public function configure_woocommerce_upgrade_notice() { + $notices = get_option( 'woocommerce_admin_notices', array() ); + if ( false === array_search( 'translation_upgrade', $notices ) ) { + $notices[] = 'translation_upgrade'; + + update_option( 'woocommerce_admin_notices', $notices ); + } + } + /** * Check if language pack exists * @@ -126,7 +142,13 @@ class WC_Language_Pack_Upgrader { ( isset( $hook_extra['language_update_type'] ) && 'plugin' == $hook_extra['language_update_type'] ) && ( isset( $hook_extra['language_update']->slug ) && 'woocommerce' == $hook_extra['language_update']->slug ) ) { + // Update the language pack version update_option( 'woocommerce_language_pack_version', WC_VERSION ); + + // Remove the translation upgrade notice + $notices = get_option( 'woocommerce_admin_notices', array() ); + $notices = array_diff( $notices, array( 'translation_upgrade' ) ); + update_option( 'woocommerce_admin_notices', $notices ); } }