| Server IP : 38.190.208.107 / Your IP : 216.73.217.46 Web Server : nginx/1.28.1 System : Linux ht2026040333114 6.1.0-10-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.37-1 (2023-07-03) x86_64 User : root ( 0) PHP Version : 8.2.28 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv,eval,assert,passthru,system,exec,shell_exec,popen,proc_open MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wwwroot/wp.3/wp-content/plugins/wpforms-lite/src/Integrations/WPorg/ |
Upload File : |
<?php
namespace WPForms\Integrations\WPorg;
use Language_Pack_Upgrader;
use Automatic_Upgrader_Skin;
use WPForms\Integrations\IntegrationInterface;
/**
* Load translations from WordPress.org for the Lite version.
*
* @since 1.6.9
*/
class Translations implements IntegrationInterface {
/**
* Full wp.org API URL for the plugin.
*
* @since 1.6.9
*/
const API_URL = 'https://api.wordpress.org/plugins/update-check/1.1/';
/**
* Indicate if current integration is allowed to load.
*
* @since 1.6.9
*
* @return bool
*/
public function allow_load() {
if ( ! is_admin() ) {
return false;
}
// For WordPress versions 4.9.0-4.9.4 this file must be included before the current_user_can() check.
require_once ABSPATH . 'wp-admin/includes/template.php';
if ( ! current_user_can( 'install_languages' ) ) {
return false;
}
require_once ABSPATH . 'wp-admin/includes/file.php';
require_once ABSPATH . 'wp-admin/includes/translation-install.php';
return wp_can_install_language_pack();
}
/**
* Load an integration.
*
* @since 1.6.9
*/
public function load() {
// Download translations for all addons when language for the site has been changed.
add_action( 'update_option_WPLANG', [ $this, 'download_translations' ] );
}
/**
* Get translation packages from the wp.org API.
*
* @since 1.6.9
*
* @return array
*/
private function get_translation_packages() {
$plugin_data = get_plugin_data( WPFORMS_PLUGIN_FILE );
$plugin_data['Name'] = 'WPForms Lite';
$plugin_data['Version'] = '9999.0';
$request = wp_remote_post(
self::API_URL,
[
'body' => [
'plugins' => wp_json_encode(
[
'plugins' => [
'wpforms-lite/wpforms.php' => $plugin_data,
],
'active' => [],
]
),
'locale' => wp_json_encode( get_available_languages() ),
],
]
);
$code = wp_remote_retrieve_response_code( $request );
$body = wp_remote_retrieve_body( $request );
if ( $code !== 200 || $body === 'error' || is_wp_error( $body ) ) {
return [];
}
$body = json_decode( $body, true );
return ! empty( $body['translations'] ) ? $body['translations'] : [];
}
/**
* Download translations for all available languages.
*
* @since 1.6.9
*/
public function download_translations() {
$translations = $this->get_translation_packages();
if ( empty( $translations ) ) {
return;
}
$skin = new Automatic_Upgrader_Skin();
$upgrader = new Language_Pack_Upgrader( $skin );
foreach ( $translations as $language ) {
// Sometimes a language can be passed as array.
$this->download_package( (object) $language, $upgrader, $skin );
}
}
/**
* Download translation for the language.
*
* @since 1.6.9
*
* @param object $language Language package.
* @param Language_Pack_Upgrader $upgrader The instance of the core class used for updating/installing language packs (translations).
* @param Automatic_Upgrader_Skin $skin Upgrader Skin for Automatic WordPress Upgrades.
*/
private function download_package( $language, Language_Pack_Upgrader $upgrader, Automatic_Upgrader_Skin $skin ) {
if ( ! property_exists( $language, 'package' ) || empty( $language->package ) ) {
return;
}
$skin->language_update = $language;
$upgrader->run(
[
'package' => $language->package,
'destination' => WP_LANG_DIR . '/plugins',
'abort_if_destination_exists' => false,
'is_multi' => true,
'hook_extra' => [
'language_update_type' => $language->type,
'language_update' => $language,
],
]
);
}
}