From de5533e56b10d6b520fbe729221143447cc0036d Mon Sep 17 00:00:00 2001 From: whyisjake Date: Mon, 27 Jul 2020 18:31:06 +0000 Subject: [PATCH] REST API: Install plugin translations after the plugin install. This only installs for the plugin in question, not all plugins. Support for retrieving the langauge pack alongside the install API request was added in https://meta.trac.wordpress.org/changeset/10091 to avoid having to make a plugin update check during the REST API check. Fixes #50732. Props dd32, ocean90, ryelle, swissspidy, tellyworth, whyisjake, TimothyBlynJacobs. Built from https://develop.svn.wordpress.org/trunk@48641 git-svn-id: http://core.svn.wordpress.org/trunk@48403 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../class-wp-rest-plugins-controller.php | 29 ++++++++++++++++++- wp-includes/version.php | 2 +- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php index 28b51d7612..4eca50b549 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php @@ -285,7 +285,8 @@ class WP_REST_Plugins_Controller extends WP_REST_Controller { array( 'slug' => $slug, 'fields' => array( - 'sections' => false, + 'sections' => false, + 'language_packs' => true, ), ) ); @@ -355,6 +356,32 @@ class WP_REST_Plugins_Controller extends WP_REST_Controller { } } + // Install translations. + $installed_locales = array_values( get_available_languages() ); + /** This filter is documented in wp-includes/update.php */ + $installed_locales = apply_filters( 'plugins_update_check_locales', $installed_locales ); + + $language_packs = array_map( + function( $item ) { + return (object) $item; + }, + $api->language_packs + ); + + $language_packs = array_filter( + $language_packs, + function( $pack ) use ( $installed_locales ) { + return in_array( $pack->language, $installed_locales, true ); + } + ); + + if ( $language_packs ) { + $lp_upgrader = new Language_Pack_Upgrader( $skin ); + + // Install all applicable language packs for the plugin. + $lp_upgrader->bulk_upgrade( $language_packs ); + } + $path = WP_PLUGIN_DIR . '/' . $file; $data = get_plugin_data( $path, false, false ); $data['_file'] = $file; diff --git a/wp-includes/version.php b/wp-includes/version.php index a5cb0a13a0..3de17a4911 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.5-beta3-48640'; +$wp_version = '5.5-beta3-48641'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.