From de59e21b6209012efbdb24cbed22aaa25a70d6bf Mon Sep 17 00:00:00 2001 From: Dominik Schilling Date: Wed, 3 Sep 2014 10:38:17 +0000 Subject: [PATCH] Language Pack Upgrader: Allow to disable asynchronously translation updates. * Don't touch VCS installs. * Use the `async_update_translation` filter (which corresponds exactly to `auto_update_translation`) to entirely disable it, or based on the update offer. props nacin, ocean90. fixes #28571. Built from https://develop.svn.wordpress.org/trunk@29694 git-svn-id: http://core.svn.wordpress.org/trunk@29469 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/class-wp-upgrader.php | 37 +++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/wp-admin/includes/class-wp-upgrader.php b/wp-admin/includes/class-wp-upgrader.php index 8953accc8e..2bef3eaa6e 100644 --- a/wp-admin/includes/class-wp-upgrader.php +++ b/wp-admin/includes/class-wp-upgrader.php @@ -1196,20 +1196,51 @@ class Language_Pack_Upgrader extends WP_Upgrader { public static function async_upgrade( $upgrader = false ) { // Avoid recursion. - if ( $upgrader && $upgrader instanceof Language_Pack_Upgrader ) + if ( $upgrader && $upgrader instanceof Language_Pack_Upgrader ) { return; + } // Nothing to do? $language_updates = wp_get_translation_updates(); - if ( ! $language_updates ) + if ( ! $language_updates ) { return; + } + + // Avoid messing with VCS installs, at least for now. + // Noted: this is not the ideal way to accomplish this. + $check_vcs = new WP_Automatic_Updater; + if ( $check_vcs->is_vcs_checkout( WP_CONTENT_DIR ) ) { + return; + } + + foreach ( $language_updates as $key => $language_update ) { + $update = ! empty( $language_update->autoupdate ); + + /** + * Filter whether to asynchronously update translation for core, a plugin, or a theme. + * + * @since 4.0.0 + * + * @param bool $update Whether to update. + * @param object $language_update The update offer. + */ + $update = apply_filters( 'async_update_translation', $update, $language_update ); + + if ( ! $update ) { + unset( $language_updates[ $key ] ); + } + } + + if ( empty( $language_updates ) ) { + return; + } $skin = new Language_Pack_Upgrader_Skin( array( 'skip_header_footer' => true, ) ); $lp_upgrader = new Language_Pack_Upgrader( $skin ); - $lp_upgrader->upgrade(); + $lp_upgrader->bulk_upgrade( $language_updates ); } public function upgrade_strings() {