Merge pull request #5618 from claudiosmweb/feature-translation-update-notice
Add a notice about available translation upgrades
This commit is contained in:
commit
2916c64370
|
@ -67,6 +67,10 @@ class WC_Admin_Notices {
|
||||||
wp_enqueue_style( 'woocommerce-activation', plugins_url( '/assets/css/activation.css', WC_PLUGIN_FILE ) );
|
wp_enqueue_style( 'woocommerce-activation', plugins_url( '/assets/css/activation.css', WC_PLUGIN_FILE ) );
|
||||||
add_action( 'admin_notices', array( $this, 'template_file_check_notice' ) );
|
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' );
|
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
|
* Show a notice highlighting bad template files
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -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> – 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>
|
|
@ -87,6 +87,8 @@ class WC_Language_Pack_Upgrader {
|
||||||
if ( version_compare( $version, WC_VERSION, '<' ) && 'en' !== $this->get_language() ) {
|
if ( version_compare( $version, WC_VERSION, '<' ) && 'en' !== $this->get_language() ) {
|
||||||
|
|
||||||
if ( $this->check_if_language_pack_exists() ) {
|
if ( $this->check_if_language_pack_exists() ) {
|
||||||
|
$this->configure_woocommerce_upgrade_notice();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
// Updated the woocommerce_language_pack_version to avoid searching translations for this release again
|
// 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;
|
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
|
* 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_type'] ) && 'plugin' == $hook_extra['language_update_type'] )
|
||||||
&& ( isset( $hook_extra['language_update']->slug ) && 'woocommerce' == $hook_extra['language_update']->slug )
|
&& ( 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 );
|
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 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue