added a notice to display messages about available translation upgrades

This commit is contained in:
claudiosmweb 2014-06-04 13:01:38 -03:00
parent 09c4e1c07a
commit 1c128d8ebd
3 changed files with 50 additions and 1 deletions

View File

@ -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();
return new WC_Admin_Notices();

View File

@ -0,0 +1,12 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
?>
<div id="message" class="updated woocommerce-message wc-connect">
<p><?php _e( '<strong>WooCommerce Translation Available</strong> &#8211; do the upgrade / installation of your translations.', 'woocommerce' ); ?></p>
<form method="post" action="<?php echo add_query_arg( array( 'action' => 'do-translation-upgrade' ), admin_url( 'update-core.php' ) ); ?>" class="upgrade">
<?php wp_nonce_field( 'upgrade-translations' ); ?>
<p class="submit"><input class="button-primary" type="submit" value="<?php esc_attr_e( 'Update Translations', 'woocommerce' ); ?>" name="upgrade" /></p>
</form>
</div>

View File

@ -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 );
}
}