repo . '/' . WC_VERSION . '/' . $this->get_language() . '.zip'; } /** * Check for language updates * * @param object $data Transient update data * * @return object */ public function check_for_update( $data ) { if ( $this->has_available_update() ) { $data->translations[] = array( 'type' => 'plugin', 'slug' => 'woocommerce', 'language' => $this->get_language(), 'version' => WC_VERSION, 'updated' => date( 'Y-m-d H:i:s' ), 'package' => $this->get_language_package_uri(), 'autoupdate' => 1 ); } return $data; } /** * Check if has available translation update * * @return bool */ public function has_available_update() { $version = get_option( 'woocommerce_language_pack_version', '0' ); if ( version_compare( $version, WC_VERSION, '<' ) && 'en' !== $this->get_language() ) { if ( $this->check_if_language_pack_exists() ) { return true; } else { // Updated the woocommerce_language_pack_version to avoid searching translations for this release again update_option( 'woocommerce_language_pack_version', WC_VERSION ); } } return false; } /** * Check if language pack exists * * @return bool */ public function check_if_language_pack_exists() { $response = wp_remote_get( $this->get_language_package_uri(), array( 'sslverify' => false, 'timeout' => 60 ) ); if ( ! is_wp_error( $response ) && $response['response']['code'] >= 200 && $response['response']['code'] < 300 ) { return true; } else { return false; } } /** * Update the language version in database * * @param bool $response Install response (true = success, false = fail) * @param array $hook_extra Extra arguments passed to hooked filters * * @return bool */ public function version_update( $response, $hook_extra ) { if ( $response ) { if ( ( 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_option( 'woocommerce_language_pack_version', WC_VERSION ); } } return $response; } } new WC_Language_Pack_Upgrader();