Edit File by line
/home/barbar84/public_h.../wp-admin/includes
File: translation-install.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* WordPress Translation Installation Administration API
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @subpackage Administration
[5] Fix | Delete
*/
[6] Fix | Delete
[7] Fix | Delete
[8] Fix | Delete
/**
[9] Fix | Delete
* Retrieve translations from WordPress Translation API.
[10] Fix | Delete
*
[11] Fix | Delete
* @since 4.0.0
[12] Fix | Delete
*
[13] Fix | Delete
* @param string $type Type of translations. Accepts 'plugins', 'themes', 'core'.
[14] Fix | Delete
* @param array|object $args Translation API arguments. Optional.
[15] Fix | Delete
* @return object|WP_Error On success an object of translations, WP_Error on failure.
[16] Fix | Delete
*/
[17] Fix | Delete
function translations_api( $type, $args = null ) {
[18] Fix | Delete
// Include an unmodified $wp_version.
[19] Fix | Delete
require ABSPATH . WPINC . '/version.php';
[20] Fix | Delete
[21] Fix | Delete
if ( ! in_array( $type, array( 'plugins', 'themes', 'core' ), true ) ) {
[22] Fix | Delete
return new WP_Error( 'invalid_type', __( 'Invalid translation type.' ) );
[23] Fix | Delete
}
[24] Fix | Delete
[25] Fix | Delete
/**
[26] Fix | Delete
* Allows a plugin to override the WordPress.org Translation Installation API entirely.
[27] Fix | Delete
*
[28] Fix | Delete
* @since 4.0.0
[29] Fix | Delete
*
[30] Fix | Delete
* @param false|object $result The result object. Default false.
[31] Fix | Delete
* @param string $type The type of translations being requested.
[32] Fix | Delete
* @param object $args Translation API arguments.
[33] Fix | Delete
*/
[34] Fix | Delete
$res = apply_filters( 'translations_api', false, $type, $args );
[35] Fix | Delete
[36] Fix | Delete
if ( false === $res ) {
[37] Fix | Delete
$url = 'http://api.wordpress.org/translations/' . $type . '/1.0/';
[38] Fix | Delete
$http_url = $url;
[39] Fix | Delete
$ssl = wp_http_supports( array( 'ssl' ) );
[40] Fix | Delete
if ( $ssl ) {
[41] Fix | Delete
$url = set_url_scheme( $url, 'https' );
[42] Fix | Delete
}
[43] Fix | Delete
[44] Fix | Delete
$options = array(
[45] Fix | Delete
'timeout' => 3,
[46] Fix | Delete
'body' => array(
[47] Fix | Delete
'wp_version' => $wp_version,
[48] Fix | Delete
'locale' => get_locale(),
[49] Fix | Delete
'version' => $args['version'], // Version of plugin, theme or core.
[50] Fix | Delete
),
[51] Fix | Delete
);
[52] Fix | Delete
[53] Fix | Delete
if ( 'core' !== $type ) {
[54] Fix | Delete
$options['body']['slug'] = $args['slug']; // Plugin or theme slug.
[55] Fix | Delete
}
[56] Fix | Delete
[57] Fix | Delete
$request = wp_remote_post( $url, $options );
[58] Fix | Delete
[59] Fix | Delete
if ( $ssl && is_wp_error( $request ) ) {
[60] Fix | Delete
trigger_error(
[61] Fix | Delete
sprintf(
[62] Fix | Delete
/* translators: %s: Support forums URL. */
[63] Fix | Delete
__( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),
[64] Fix | Delete
__( 'https://wordpress.org/support/forums/' )
[65] Fix | Delete
) . ' ' . __( '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)' ),
[66] Fix | Delete
headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE
[67] Fix | Delete
);
[68] Fix | Delete
[69] Fix | Delete
$request = wp_remote_post( $http_url, $options );
[70] Fix | Delete
}
[71] Fix | Delete
[72] Fix | Delete
if ( is_wp_error( $request ) ) {
[73] Fix | Delete
$res = new WP_Error(
[74] Fix | Delete
'translations_api_failed',
[75] Fix | Delete
sprintf(
[76] Fix | Delete
/* translators: %s: Support forums URL. */
[77] Fix | Delete
__( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),
[78] Fix | Delete
__( 'https://wordpress.org/support/forums/' )
[79] Fix | Delete
),
[80] Fix | Delete
$request->get_error_message()
[81] Fix | Delete
);
[82] Fix | Delete
} else {
[83] Fix | Delete
$res = json_decode( wp_remote_retrieve_body( $request ), true );
[84] Fix | Delete
if ( ! is_object( $res ) && ! is_array( $res ) ) {
[85] Fix | Delete
$res = new WP_Error(
[86] Fix | Delete
'translations_api_failed',
[87] Fix | Delete
sprintf(
[88] Fix | Delete
/* translators: %s: Support forums URL. */
[89] Fix | Delete
__( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),
[90] Fix | Delete
__( 'https://wordpress.org/support/forums/' )
[91] Fix | Delete
),
[92] Fix | Delete
wp_remote_retrieve_body( $request )
[93] Fix | Delete
);
[94] Fix | Delete
}
[95] Fix | Delete
}
[96] Fix | Delete
}
[97] Fix | Delete
[98] Fix | Delete
/**
[99] Fix | Delete
* Filters the Translation Installation API response results.
[100] Fix | Delete
*
[101] Fix | Delete
* @since 4.0.0
[102] Fix | Delete
*
[103] Fix | Delete
* @param object|WP_Error $res Response object or WP_Error.
[104] Fix | Delete
* @param string $type The type of translations being requested.
[105] Fix | Delete
* @param object $args Translation API arguments.
[106] Fix | Delete
*/
[107] Fix | Delete
return apply_filters( 'translations_api_result', $res, $type, $args );
[108] Fix | Delete
}
[109] Fix | Delete
[110] Fix | Delete
/**
[111] Fix | Delete
* Get available translations from the WordPress.org API.
[112] Fix | Delete
*
[113] Fix | Delete
* @since 4.0.0
[114] Fix | Delete
*
[115] Fix | Delete
* @see translations_api()
[116] Fix | Delete
*
[117] Fix | Delete
* @return array[] Array of translations, each an array of data, keyed by the language. If the API response results
[118] Fix | Delete
* in an error, an empty array will be returned.
[119] Fix | Delete
*/
[120] Fix | Delete
function wp_get_available_translations() {
[121] Fix | Delete
if ( ! wp_installing() ) {
[122] Fix | Delete
$translations = get_site_transient( 'available_translations' );
[123] Fix | Delete
if ( false !== $translations ) {
[124] Fix | Delete
return $translations;
[125] Fix | Delete
}
[126] Fix | Delete
}
[127] Fix | Delete
[128] Fix | Delete
// Include an unmodified $wp_version.
[129] Fix | Delete
require ABSPATH . WPINC . '/version.php';
[130] Fix | Delete
[131] Fix | Delete
$api = translations_api( 'core', array( 'version' => $wp_version ) );
[132] Fix | Delete
[133] Fix | Delete
if ( is_wp_error( $api ) || empty( $api['translations'] ) ) {
[134] Fix | Delete
return array();
[135] Fix | Delete
}
[136] Fix | Delete
[137] Fix | Delete
$translations = array();
[138] Fix | Delete
// Key the array with the language code for now.
[139] Fix | Delete
foreach ( $api['translations'] as $translation ) {
[140] Fix | Delete
$translations[ $translation['language'] ] = $translation;
[141] Fix | Delete
}
[142] Fix | Delete
[143] Fix | Delete
if ( ! defined( 'WP_INSTALLING' ) ) {
[144] Fix | Delete
set_site_transient( 'available_translations', $translations, 3 * HOUR_IN_SECONDS );
[145] Fix | Delete
}
[146] Fix | Delete
[147] Fix | Delete
return $translations;
[148] Fix | Delete
}
[149] Fix | Delete
[150] Fix | Delete
/**
[151] Fix | Delete
* Output the select form for the language selection on the installation screen.
[152] Fix | Delete
*
[153] Fix | Delete
* @since 4.0.0
[154] Fix | Delete
*
[155] Fix | Delete
* @global string $wp_local_package Locale code of the package.
[156] Fix | Delete
*
[157] Fix | Delete
* @param array[] $languages Array of available languages (populated via the Translation API).
[158] Fix | Delete
*/
[159] Fix | Delete
function wp_install_language_form( $languages ) {
[160] Fix | Delete
global $wp_local_package;
[161] Fix | Delete
[162] Fix | Delete
$installed_languages = get_available_languages();
[163] Fix | Delete
[164] Fix | Delete
echo "<label class='screen-reader-text' for='language'>Select a default language</label>\n";
[165] Fix | Delete
echo "<select size='14' name='language' id='language'>\n";
[166] Fix | Delete
echo '<option value="" lang="en" selected="selected" data-continue="Continue" data-installed="1">English (United States)</option>';
[167] Fix | Delete
echo "\n";
[168] Fix | Delete
[169] Fix | Delete
if ( ! empty( $wp_local_package ) && isset( $languages[ $wp_local_package ] ) ) {
[170] Fix | Delete
if ( isset( $languages[ $wp_local_package ] ) ) {
[171] Fix | Delete
$language = $languages[ $wp_local_package ];
[172] Fix | Delete
printf(
[173] Fix | Delete
'<option value="%s" lang="%s" data-continue="%s"%s>%s</option>' . "\n",
[174] Fix | Delete
esc_attr( $language['language'] ),
[175] Fix | Delete
esc_attr( current( $language['iso'] ) ),
[176] Fix | Delete
esc_attr( $language['strings']['continue'] ? $language['strings']['continue'] : 'Continue' ),
[177] Fix | Delete
in_array( $language['language'], $installed_languages, true ) ? ' data-installed="1"' : '',
[178] Fix | Delete
esc_html( $language['native_name'] )
[179] Fix | Delete
);
[180] Fix | Delete
[181] Fix | Delete
unset( $languages[ $wp_local_package ] );
[182] Fix | Delete
}
[183] Fix | Delete
}
[184] Fix | Delete
[185] Fix | Delete
foreach ( $languages as $language ) {
[186] Fix | Delete
printf(
[187] Fix | Delete
'<option value="%s" lang="%s" data-continue="%s"%s>%s</option>' . "\n",
[188] Fix | Delete
esc_attr( $language['language'] ),
[189] Fix | Delete
esc_attr( current( $language['iso'] ) ),
[190] Fix | Delete
esc_attr( $language['strings']['continue'] ? $language['strings']['continue'] : 'Continue' ),
[191] Fix | Delete
in_array( $language['language'], $installed_languages, true ) ? ' data-installed="1"' : '',
[192] Fix | Delete
esc_html( $language['native_name'] )
[193] Fix | Delete
);
[194] Fix | Delete
}
[195] Fix | Delete
echo "</select>\n";
[196] Fix | Delete
echo '<p class="step"><span class="spinner"></span><input id="language-continue" type="submit" class="button button-primary button-large" value="Continue" /></p>';
[197] Fix | Delete
}
[198] Fix | Delete
[199] Fix | Delete
/**
[200] Fix | Delete
* Download a language pack.
[201] Fix | Delete
*
[202] Fix | Delete
* @since 4.0.0
[203] Fix | Delete
*
[204] Fix | Delete
* @see wp_get_available_translations()
[205] Fix | Delete
*
[206] Fix | Delete
* @param string $download Language code to download.
[207] Fix | Delete
* @return string|false Returns the language code if successfully downloaded
[208] Fix | Delete
* (or already installed), or false on failure.
[209] Fix | Delete
*/
[210] Fix | Delete
function wp_download_language_pack( $download ) {
[211] Fix | Delete
// Check if the translation is already installed.
[212] Fix | Delete
if ( in_array( $download, get_available_languages(), true ) ) {
[213] Fix | Delete
return $download;
[214] Fix | Delete
}
[215] Fix | Delete
[216] Fix | Delete
if ( ! wp_is_file_mod_allowed( 'download_language_pack' ) ) {
[217] Fix | Delete
return false;
[218] Fix | Delete
}
[219] Fix | Delete
[220] Fix | Delete
// Confirm the translation is one we can download.
[221] Fix | Delete
$translations = wp_get_available_translations();
[222] Fix | Delete
if ( ! $translations ) {
[223] Fix | Delete
return false;
[224] Fix | Delete
}
[225] Fix | Delete
foreach ( $translations as $translation ) {
[226] Fix | Delete
if ( $translation['language'] === $download ) {
[227] Fix | Delete
$translation_to_load = true;
[228] Fix | Delete
break;
[229] Fix | Delete
}
[230] Fix | Delete
}
[231] Fix | Delete
[232] Fix | Delete
if ( empty( $translation_to_load ) ) {
[233] Fix | Delete
return false;
[234] Fix | Delete
}
[235] Fix | Delete
$translation = (object) $translation;
[236] Fix | Delete
[237] Fix | Delete
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
[238] Fix | Delete
$skin = new Automatic_Upgrader_Skin;
[239] Fix | Delete
$upgrader = new Language_Pack_Upgrader( $skin );
[240] Fix | Delete
$translation->type = 'core';
[241] Fix | Delete
$result = $upgrader->upgrade( $translation, array( 'clear_update_cache' => false ) );
[242] Fix | Delete
[243] Fix | Delete
if ( ! $result || is_wp_error( $result ) ) {
[244] Fix | Delete
return false;
[245] Fix | Delete
}
[246] Fix | Delete
[247] Fix | Delete
return $translation->language;
[248] Fix | Delete
}
[249] Fix | Delete
[250] Fix | Delete
/**
[251] Fix | Delete
* Check if WordPress has access to the filesystem without asking for
[252] Fix | Delete
* credentials.
[253] Fix | Delete
*
[254] Fix | Delete
* @since 4.0.0
[255] Fix | Delete
*
[256] Fix | Delete
* @return bool Returns true on success, false on failure.
[257] Fix | Delete
*/
[258] Fix | Delete
function wp_can_install_language_pack() {
[259] Fix | Delete
if ( ! wp_is_file_mod_allowed( 'can_install_language_pack' ) ) {
[260] Fix | Delete
return false;
[261] Fix | Delete
}
[262] Fix | Delete
[263] Fix | Delete
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
[264] Fix | Delete
$skin = new Automatic_Upgrader_Skin;
[265] Fix | Delete
$upgrader = new Language_Pack_Upgrader( $skin );
[266] Fix | Delete
$upgrader->init();
[267] Fix | Delete
[268] Fix | Delete
$check = $upgrader->fs_connect( array( WP_CONTENT_DIR, WP_LANG_DIR ) );
[269] Fix | Delete
[270] Fix | Delete
if ( ! $check || is_wp_error( $check ) ) {
[271] Fix | Delete
return false;
[272] Fix | Delete
}
[273] Fix | Delete
[274] Fix | Delete
return true;
[275] Fix | Delete
}
[276] Fix | Delete
[277] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function