fixed the language pack upgrader to works well with WP 4.0, closes #6183

This commit is contained in:
claudiosmweb 2014-09-08 12:07:47 -03:00
parent 7ecd0009d0
commit 8f4e28b0be
1 changed files with 16 additions and 17 deletions

View File

@ -28,7 +28,7 @@ class WC_Language_Pack_Upgrader {
*/ */
public function __construct() { public function __construct() {
add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_for_update' ) ); add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_for_update' ) );
add_filter( 'upgrader_post_install', array( $this, 'version_update' ), 999, 2 ); add_filter( 'upgrader_pre_download', array( $this, 'version_update' ), 10, 2 );
add_action( 'woocommerce_language_pack_updater_check', array( $this, 'has_available_update' ) ); add_action( 'woocommerce_language_pack_updater_check', array( $this, 'has_available_update' ) );
} }
@ -117,28 +117,27 @@ class WC_Language_Pack_Upgrader {
/** /**
* Update the language version in database * Update the language version in database
* *
* @param bool $response Install response (true = success, false = fail) * Take advance it while downloads the package and updates the database
* @param array $hook_extra Extra arguments passed to hooked filters * This ensures not generate a loop download
* If installation fails you can redo it in: WooCommerce > Sistem Status > Tools > Force Translation Upgrade
*
* @param bool $reply Whether to bail without returning the package (default: false)
* @param string $package Package URL
* *
* @return bool * @return bool
*/ */
public function version_update( $response, $hook_extra ) { public function version_update( $reply, $package ) {
if ( $response ) { if ( $package === $this->get_language_package_uri() ) {
if ( // Update the language pack version
( isset( $hook_extra['language_update_type'] ) && 'plugin' == $hook_extra['language_update_type'] ) update_option( 'woocommerce_language_pack_version', array( WC_VERSION , get_locale() ) );
&& ( isset( $hook_extra['language_update']->slug ) && 'woocommerce' == $hook_extra['language_update']->slug )
) {
// Update the language pack version
update_option( 'woocommerce_language_pack_version', array( WC_VERSION , get_locale() ) );
// Remove the translation upgrade notice // Remove the translation upgrade notice
$notices = get_option( 'woocommerce_admin_notices', array() ); $notices = get_option( 'woocommerce_admin_notices', array() );
$notices = array_diff( $notices, array( 'translation_upgrade' ) ); $notices = array_diff( $notices, array( 'translation_upgrade' ) );
update_option( 'woocommerce_admin_notices', $notices ); update_option( 'woocommerce_admin_notices', $notices );
}
} }
return $response; return $reply;
} }
} }