Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/wpforms-.../src/Integrat.../WPorg
File: Translations.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace WPForms\Integrations\WPorg;
[2] Fix | Delete
[3] Fix | Delete
use Language_Pack_Upgrader;
[4] Fix | Delete
use Automatic_Upgrader_Skin;
[5] Fix | Delete
use WPForms\Integrations\IntegrationInterface;
[6] Fix | Delete
[7] Fix | Delete
/**
[8] Fix | Delete
* Load translations from WordPress.org for the Lite version.
[9] Fix | Delete
*
[10] Fix | Delete
* @since 1.6.9
[11] Fix | Delete
*/
[12] Fix | Delete
class Translations implements IntegrationInterface {
[13] Fix | Delete
[14] Fix | Delete
/**
[15] Fix | Delete
* Full wp.org API URL for the plugin.
[16] Fix | Delete
*
[17] Fix | Delete
* @since 1.6.9
[18] Fix | Delete
*/
[19] Fix | Delete
const API_URL = 'https://api.wordpress.org/plugins/update-check/1.1/';
[20] Fix | Delete
[21] Fix | Delete
/**
[22] Fix | Delete
* Indicate if current integration is allowed to load.
[23] Fix | Delete
*
[24] Fix | Delete
* @since 1.6.9
[25] Fix | Delete
*
[26] Fix | Delete
* @return bool
[27] Fix | Delete
*/
[28] Fix | Delete
public function allow_load() {
[29] Fix | Delete
[30] Fix | Delete
if ( ! is_admin() ) {
[31] Fix | Delete
return false;
[32] Fix | Delete
}
[33] Fix | Delete
[34] Fix | Delete
// For WordPress versions 4.9.0-4.9.4 this file must be included before the current_user_can() check.
[35] Fix | Delete
require_once ABSPATH . 'wp-admin/includes/template.php';
[36] Fix | Delete
[37] Fix | Delete
if ( ! current_user_can( 'install_languages' ) ) {
[38] Fix | Delete
return false;
[39] Fix | Delete
}
[40] Fix | Delete
[41] Fix | Delete
require_once ABSPATH . 'wp-admin/includes/file.php';
[42] Fix | Delete
require_once ABSPATH . 'wp-admin/includes/translation-install.php';
[43] Fix | Delete
[44] Fix | Delete
return wp_can_install_language_pack();
[45] Fix | Delete
}
[46] Fix | Delete
[47] Fix | Delete
/**
[48] Fix | Delete
* Load an integration.
[49] Fix | Delete
*
[50] Fix | Delete
* @since 1.6.9
[51] Fix | Delete
*/
[52] Fix | Delete
public function load() {
[53] Fix | Delete
[54] Fix | Delete
// Download translations for all addons when language for the site has been changed.
[55] Fix | Delete
add_action( 'update_option_WPLANG', [ $this, 'download_translations' ] );
[56] Fix | Delete
}
[57] Fix | Delete
[58] Fix | Delete
/**
[59] Fix | Delete
* Get translation packages from the wp.org API.
[60] Fix | Delete
*
[61] Fix | Delete
* @since 1.6.9
[62] Fix | Delete
*
[63] Fix | Delete
* @return array
[64] Fix | Delete
*/
[65] Fix | Delete
private function get_translation_packages() {
[66] Fix | Delete
[67] Fix | Delete
$plugin_data = get_plugin_data( WPFORMS_PLUGIN_FILE );
[68] Fix | Delete
$plugin_data['Name'] = 'WPForms Lite';
[69] Fix | Delete
$plugin_data['Version'] = '9999.0';
[70] Fix | Delete
[71] Fix | Delete
$request = wp_remote_post(
[72] Fix | Delete
self::API_URL,
[73] Fix | Delete
[
[74] Fix | Delete
'body' => [
[75] Fix | Delete
'plugins' => wp_json_encode(
[76] Fix | Delete
[
[77] Fix | Delete
'plugins' => [
[78] Fix | Delete
'wpforms-lite/wpforms.php' => $plugin_data,
[79] Fix | Delete
],
[80] Fix | Delete
'active' => [],
[81] Fix | Delete
]
[82] Fix | Delete
),
[83] Fix | Delete
'locale' => wp_json_encode( get_available_languages() ),
[84] Fix | Delete
],
[85] Fix | Delete
]
[86] Fix | Delete
);
[87] Fix | Delete
[88] Fix | Delete
$code = wp_remote_retrieve_response_code( $request );
[89] Fix | Delete
$body = wp_remote_retrieve_body( $request );
[90] Fix | Delete
[91] Fix | Delete
if ( $code !== 200 || $body === 'error' || is_wp_error( $body ) ) {
[92] Fix | Delete
return [];
[93] Fix | Delete
}
[94] Fix | Delete
[95] Fix | Delete
$body = json_decode( $body, true );
[96] Fix | Delete
[97] Fix | Delete
return ! empty( $body['translations'] ) ? $body['translations'] : [];
[98] Fix | Delete
}
[99] Fix | Delete
[100] Fix | Delete
/**
[101] Fix | Delete
* Download translations for all available languages.
[102] Fix | Delete
*
[103] Fix | Delete
* @since 1.6.9
[104] Fix | Delete
*/
[105] Fix | Delete
public function download_translations() {
[106] Fix | Delete
[107] Fix | Delete
$translations = $this->get_translation_packages();
[108] Fix | Delete
[109] Fix | Delete
if ( empty( $translations ) ) {
[110] Fix | Delete
return;
[111] Fix | Delete
}
[112] Fix | Delete
[113] Fix | Delete
$skin = new Automatic_Upgrader_Skin();
[114] Fix | Delete
$upgrader = new Language_Pack_Upgrader( $skin );
[115] Fix | Delete
[116] Fix | Delete
foreach ( $translations as $language ) {
[117] Fix | Delete
// Sometimes a language can be passed as array.
[118] Fix | Delete
$this->download_package( (object) $language, $upgrader, $skin );
[119] Fix | Delete
}
[120] Fix | Delete
}
[121] Fix | Delete
[122] Fix | Delete
/**
[123] Fix | Delete
* Download translation for the language.
[124] Fix | Delete
*
[125] Fix | Delete
* @since 1.6.9
[126] Fix | Delete
*
[127] Fix | Delete
* @param object $language Language package.
[128] Fix | Delete
* @param Language_Pack_Upgrader $upgrader The instance of the core class used for updating/installing language packs (translations).
[129] Fix | Delete
* @param Automatic_Upgrader_Skin $skin Upgrader Skin for Automatic WordPress Upgrades.
[130] Fix | Delete
*/
[131] Fix | Delete
private function download_package( $language, Language_Pack_Upgrader $upgrader, Automatic_Upgrader_Skin $skin ) {
[132] Fix | Delete
[133] Fix | Delete
if ( ! property_exists( $language, 'package' ) || empty( $language->package ) ) {
[134] Fix | Delete
return;
[135] Fix | Delete
}
[136] Fix | Delete
[137] Fix | Delete
$skin->language_update = $language;
[138] Fix | Delete
[139] Fix | Delete
$upgrader->run(
[140] Fix | Delete
[
[141] Fix | Delete
'package' => $language->package,
[142] Fix | Delete
'destination' => WP_LANG_DIR . '/plugins',
[143] Fix | Delete
'abort_if_destination_exists' => false,
[144] Fix | Delete
'is_multi' => true,
[145] Fix | Delete
'hook_extra' => [
[146] Fix | Delete
'language_update_type' => $language->type,
[147] Fix | Delete
'language_update' => $language,
[148] Fix | Delete
],
[149] Fix | Delete
]
[150] Fix | Delete
);
[151] Fix | Delete
}
[152] Fix | Delete
}
[153] Fix | Delete
[154] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function