Make WordPress Core

Changeset 48641


Ignore:
Timestamp:
07/27/2020 06:29:43 PM (4 years ago)
Author:
whyisjake
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php

    r48627 r48641  
    286286                'slug'   => $slug,
    287287                'fields' => array(
    288                     'sections' => false,
     288                    'sections'       => false,
     289                    'language_packs' => true,
    289290                ),
    290291            )
     
    354355                return $changed_status;
    355356            }
     357        }
     358
     359        // Install translations.
     360        $installed_locales = array_values( get_available_languages() );
     361        /** This filter is documented in wp-includes/update.php */
     362        $installed_locales = apply_filters( 'plugins_update_check_locales', $installed_locales );
     363
     364        $language_packs = array_map(
     365            function( $item ) {
     366                return (object) $item;
     367            },
     368            $api->language_packs
     369        );
     370
     371        $language_packs = array_filter(
     372            $language_packs,
     373            function( $pack ) use ( $installed_locales ) {
     374                return in_array( $pack->language, $installed_locales, true );
     375            }
     376        );
     377
     378        if ( $language_packs ) {
     379            $lp_upgrader = new Language_Pack_Upgrader( $skin );
     380
     381            // Install all applicable language packs for the plugin.
     382            $lp_upgrader->bulk_upgrade( $language_packs );
    356383        }
    357384
Note: See TracChangeset for help on using the changeset viewer.