PHP 8.0.30
Preview: translation-install.php Size: 8.68 KB
/home/certprox/public_html/wpinst/wordpress/wp-admin/includes/translation-install.php

<?php
/**
 * WordPress Translation Installation Administration API
 *
 * @package WordPress
 * @subpackage Administration
 */


/**
 * Retrieve translations from WordPress Translation API.
 *
 * @since 4.0.0
 *
 * @param string       $type Type of translations. Accepts 'plugins', 'themes', 'core'.
 * @param array|object $args Translation API arguments. Optional.
 * @return array|WP_Error On success an associative array of translations, WP_Error on failure.
 */
function translations_api( $type, $args = null ) {
	// Include an unmodified $wp_version.
	require ABSPATH . WPINC . '/version.php';

	if ( ! in_array( $type, array( 'plugins', 'themes', 'core' ), true ) ) {
		return new WP_Error( 'invalid_type', __( 'Invalid translation type.' ) );
	}

	/**
	 * Allows a plugin to override the WordPress.org Translation Installation API entirely.
	 *
	 * @since 4.0.0
	 *
	 * @param false|array $result The result array. Default false.
	 * @param string      $type   The type of translations being requested.
	 * @param object      $args   Translation API arguments.
	 */
	$res = apply_filters( 'translations_api', false, $type, $args );

	if ( false === $res ) {
		$url      = 'http://api.wordpress.org/translations/' . $type . '/1.0/';
		$http_url = $url;
		$ssl      = wp_http_supports( array( 'ssl' ) );
		if ( $ssl ) {
			$url = set_url_scheme( $url, 'https' );
		}

		$options = array(
			'timeout' => 3,
			'body'    => array(
				'wp_version' => $wp_version,
				'locale'     => get_locale(),
				'version'    => $args['version'], // Version of plugin, theme or core.
			),
		);

		if ( 'core' !== $type ) {
			$options['body']['slug'] = $args['slug']; // Plugin or theme slug.
		}

		$request = wp_remote_post( $url, $options );

		if ( $ssl && is_wp_error( $request ) ) {
			trigger_error(
				sprintf(
					/* translators: %s: Support forums URL. */
					__( '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>.' ),
					__( 'https://wordpress.org/support/forums/' )
				) . ' ' . __( '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)' ),
				headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE
			);

			$request = wp_remote_post( $http_url, $options );
		}

		if ( is_wp_error( $request ) ) {
			$res = new WP_Error(
				'translations_api_failed',
				sprintf(
					/* translators: %s: Support forums URL. */
					__( '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>.' ),
					__( 'https://wordpress.org/support/forums/' )
				),
				$request->get_error_message()
			);
		} else {
			$res = json_decode( wp_remote_retrieve_body( $request ), true );
			if ( ! is_object( $res ) && ! is_array( $res ) ) {
				$res = new WP_Error(
					'translations_api_failed',
					sprintf(
						/* translators: %s: Support forums URL. */
						__( '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>.' ),
						__( 'https://wordpress.org/support/forums/' )
					),
					wp_remote_retrieve_body( $request )
				);
			}
		}
	}

	/**
	 * Filters the Translation Installation API response results.
	 *
	 * @since 4.0.0
	 *
	 * @param array|WP_Error $res  Response as an associative array or WP_Error.
	 * @param string         $type The type of translations being requested.
	 * @param object         $args Translation API arguments.
	 */
	return apply_filters( 'translations_api_result', $res, $type, $args );
}

/**
 * Get available translations from the WordPress.org API.
 *
 * @since 4.0.0
 *
 * @see translations_api()
 *
 * @return array[] Array of translations, each an array of data, keyed by the language. If the API response results
 *                 in an error, an empty array will be returned.
 */
function wp_get_available_translations() {
	if ( ! wp_installing() ) {
		$translations = get_site_transient( 'available_translations' );
		if ( false !== $translations ) {
			return $translations;
		}
	}

	// Include an unmodified $wp_version.
	require ABSPATH . WPINC . '/version.php';

	$api = translations_api( 'core', array( 'version' => $wp_version ) );

	if ( is_wp_error( $api ) || empty( $api['translations'] ) ) {
		return array();
	}

	$translations = array();
	// Key the array with the language code for now.
	foreach ( $api['translations'] as $translation ) {
		$translations[ $translation['language'] ] = $translation;
	}

	if ( ! defined( 'WP_INSTALLING' ) ) {
		set_site_transient( 'available_translations', $translations, 3 * HOUR_IN_SECONDS );
	}

	return $translations;
}

/**
 * Output the select form for the language selection on the installation screen.
 *
 * @since 4.0.0
 *
 * @global string $wp_local_package Locale code of the package.
 *
 * @param array[] $languages Array of available languages (populated via the Translation API).
 */
function wp_install_language_form( $languages ) {
	global $wp_local_package;

	$installed_languages = get_available_languages();

	echo "<label class='screen-reader-text' for='language'>Select a default language</label>\n";
	echo "<select size='14' name='language' id='language'>\n";
	echo '<option value="" lang="en" selected="selected" data-continue="Continue" data-installed="1">English (United States)</option>';
	echo "\n";

	if ( ! empty( $wp_local_package ) && isset( $languages[ $wp_local_package ] ) ) {
		if ( isset( $languages[ $wp_local_package ] ) ) {
			$language = $languages[ $wp_local_package ];
			printf(
				'<option value="%s" lang="%s" data-continue="%s"%s>%s</option>' . "\n",
				esc_attr( $language['language'] ),
				esc_attr( current( $language['iso'] ) ),
				esc_attr( $language['strings']['continue'] ? $language['strings']['continue'] : 'Continue' ),
				in_array( $language['language'], $installed_languages, true ) ? ' data-installed="1"' : '',
				esc_html( $language['native_name'] )
			);

			unset( $languages[ $wp_local_package ] );
		}
	}

	foreach ( $languages as $language ) {
		printf(
			'<option value="%s" lang="%s" data-continue="%s"%s>%s</option>' . "\n",
			esc_attr( $language['language'] ),
			esc_attr( current( $language['iso'] ) ),
			esc_attr( $language['strings']['continue'] ? $language['strings']['continue'] : 'Continue' ),
			in_array( $language['language'], $installed_languages, true ) ? ' data-installed="1"' : '',
			esc_html( $language['native_name'] )
		);
	}
	echo "</select>\n";
	echo '<p class="step"><span class="spinner"></span><input id="language-continue" type="submit" class="button button-primary button-large" value="Continue" /></p>';
}

/**
 * Download a language pack.
 *
 * @since 4.0.0
 *
 * @see wp_get_available_translations()
 *
 * @param string $download Language code to download.
 * @return string|false Returns the language code if successfully downloaded
 *                      (or already installed), or false on failure.
 */
function wp_download_language_pack( $download ) {
	// Check if the translation is already installed.
	if ( in_array( $download, get_available_languages(), true ) ) {
		return $download;
	}

	if ( ! wp_is_file_mod_allowed( 'download_language_pack' ) ) {
		return false;
	}

	// Confirm the translation is one we can download.
	$translations = wp_get_available_translations();
	if ( ! $translations ) {
		return false;
	}
	foreach ( $translations as $translation ) {
		if ( $translation['language'] === $download ) {
			$translation_to_load = true;
			break;
		}
	}

	if ( empty( $translation_to_load ) ) {
		return false;
	}
	$translation = (object) $translation;

	require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
	$skin              = new Automatic_Upgrader_Skin;
	$upgrader          = new Language_Pack_Upgrader( $skin );
	$translation->type = 'core';
	$result            = $upgrader->upgrade( $translation, array( 'clear_update_cache' => false ) );

	if ( ! $result || is_wp_error( $result ) ) {
		return false;
	}

	return $translation->language;
}

/**
 * Check if WordPress has access to the filesystem without asking for
 * credentials.
 *
 * @since 4.0.0
 *
 * @return bool Returns true on success, false on failure.
 */
function wp_can_install_language_pack() {
	if ( ! wp_is_file_mod_allowed( 'can_install_language_pack' ) ) {
		return false;
	}

	require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
	$skin     = new Automatic_Upgrader_Skin;
	$upgrader = new Language_Pack_Upgrader( $skin );
	$upgrader->init();

	$check = $upgrader->fs_connect( array( WP_CONTENT_DIR, WP_LANG_DIR ) );

	if ( ! $check || is_wp_error( $check ) ) {
		return false;
	}

	return true;
}

Directory Contents

Dirs: 0 × Files: 106

Name Size Perms Modified Actions
7.58 KB lrw-r--r-- 2022-09-11 20:46:10
Edit Download
3.54 KB lrw-r--r-- 2022-11-10 19:44:13
Edit Download
146.62 KB lrw-r--r-- 2022-10-17 11:19:11
Edit Download
11.40 KB lrw-r--r-- 2022-04-04 18:26:06
Edit Download
3.58 KB lrw-r--r-- 2021-09-09 13:48:56
Edit Download
2.20 KB lrw-r--r-- 2022-08-29 12:46:10
Edit Download
2.27 KB lrw-r--r-- 2022-08-29 12:46:10
Edit Download
5.44 KB lrw-r--r-- 2021-09-09 13:59:56
Edit Download
14.65 KB lrw-r--r-- 2022-04-11 11:50:01
Edit Download
20.38 KB lrw-r--r-- 2022-09-12 15:47:14
Edit Download
47.18 KB lrw-r--r-- 2022-09-12 15:47:14
Edit Download
3.34 KB lrw-r--r-- 2022-09-12 15:47:14
Edit Download
5.30 KB lrw-r--r-- 2019-11-01 14:57:02
Edit Download
8.28 KB lrw-r--r-- 2022-03-22 16:25:03
Edit Download
26.67 KB lrw-r--r-- 2022-03-26 15:28:08
Edit Download
2.42 KB lrw-r--r-- 2021-09-09 13:59:56
Edit Download
14.57 KB lrw-r--r-- 2022-04-11 11:42:04
Edit Download
192.11 KB lrw-r--r-- 2021-08-29 01:33:58
Edit Download
11.58 KB lrw-r--r-- 2022-05-20 17:38:14
Edit Download
3.20 KB lrw-r--r-- 2020-11-09 10:53:10
Edit Download
21.14 KB lrw-r--r-- 2022-05-20 17:38:14
Edit Download
12.20 KB lrw-r--r-- 2022-05-20 17:38:14
Edit Download
3.99 KB lrw-r--r-- 2020-11-09 10:53:10
Edit Download
24.53 KB lrw-r--r-- 2022-05-20 17:38:14
Edit Download
4.76 KB lrw-r--r-- 2021-09-09 13:03:55
Edit Download
5.50 KB lrw-r--r-- 2021-09-09 12:39:59
Edit Download
12.89 KB lrw-r--r-- 2022-07-05 08:06:17
Edit Download
4.10 KB lrw-r--r-- 2022-08-29 12:46:10
Edit Download
6.67 KB lrw-r--r-- 2022-10-04 03:47:15
Edit Download
50.33 KB lrw-r--r-- 2022-09-19 20:28:11
Edit Download
30.13 KB lrw-r--r-- 2022-10-04 03:47:15
Edit Download
18.33 KB lrw-r--r-- 2022-09-27 18:57:13
Edit Download
58.53 KB lrw-r--r-- 2022-09-20 02:24:12
Edit Download
22.86 KB lrw-r--r-- 2022-09-12 15:47:14
Edit Download
16.25 KB lrw-r--r-- 2022-08-09 11:33:10
Edit Download
19.73 KB lrw-r--r-- 2022-11-11 16:04:12
Edit Download
16.49 KB lrw-r--r-- 2022-11-11 16:04:12
Edit Download
21.51 KB lrw-r--r-- 2022-08-09 11:33:10
Edit Download
7.26 KB lrw-r--r-- 2022-09-12 15:47:14
Edit Download
4.47 KB lrw-r--r-- 2022-09-12 15:47:14
Edit Download
8.23 KB lrw-r--r-- 2022-10-04 03:47:15
Edit Download
1.46 KB lrw-r--r-- 2020-11-14 16:54:08
Edit Download
42.69 KB lrw-r--r-- 2022-10-04 03:47:15
Edit Download
24.74 KB lrw-r--r-- 2022-10-04 03:47:15
Edit Download
20.32 KB lrw-r--r-- 2022-10-04 03:47:15
Edit Download
27.04 KB lrw-r--r-- 2022-10-04 03:47:15
Edit Download
14.35 KB lrw-r--r-- 2022-10-04 03:47:15
Edit Download
23.69 KB lrw-r--r-- 2022-10-04 03:47:15
Edit Download
48.37 KB lrw-r--r-- 2022-10-04 03:47:15
Edit Download
1.42 KB lrw-r--r-- 2022-10-04 03:47:15
Edit Download
60.38 KB lrw-r--r-- 2022-10-04 03:47:15
Edit Download
5.43 KB lrw-r--r-- 2022-03-10 19:22:01
Edit Download
5.56 KB lrw-r--r-- 2020-10-20 21:20:07
Edit Download
31.55 KB lrw-r--r-- 2022-09-12 15:47:14
Edit Download
13.31 KB lrw-r--r-- 2022-09-19 21:08:10
Edit Download
36.36 KB lrw-r--r-- 2022-10-07 14:25:14
Edit Download
13.19 KB lrw-r--r-- 2022-09-27 10:18:12
Edit Download
111.22 KB lrw-r--r-- 2022-10-12 13:43:15
Edit Download
6.14 KB lrw-r--r-- 2022-09-12 15:47:14
Edit Download
19.05 KB lrw-r--r-- 2022-10-04 03:47:15
Edit Download
15.31 KB lrw-r--r-- 2022-10-04 03:47:15
Edit Download
9.99 KB lrw-r--r-- 2022-10-04 03:47:15
Edit Download
6.34 KB lrw-r--r-- 2022-09-12 15:47:14
Edit Download
1.44 KB lrw-r--r-- 2019-10-08 17:19:04
Edit Download
35.90 KB lrw-r--r-- 2022-10-11 15:28:13
Edit Download
18.25 KB lrw-r--r-- 2022-10-04 03:47:15
Edit Download
5.98 KB lrw-r--r-- 2022-07-20 22:15:10
Edit Download
20.06 KB lrw-r--r-- 2022-09-19 23:24:11
Edit Download
5.80 KB lrw-r--r-- 2021-10-19 23:09:00
Edit Download
67.32 KB lrw-r--r-- 2022-10-18 18:35:13
Edit Download
40.61 KB lrw-r--r-- 2022-04-20 08:13:10
Edit Download
1.44 KB lrw-r--r-- 2021-12-07 12:20:02
Edit Download
23.50 KB lrw-r--r-- 2022-07-29 08:14:12
Edit Download
87.15 KB lrw-r--r-- 2022-10-10 12:48:14
Edit Download
37.55 KB lrw-r--r-- 2022-09-19 22:53:10
Edit Download
37.91 KB lrw-r--r-- 2022-09-19 22:53:10
Edit Download
6.52 KB lrw-r--r-- 2022-07-29 09:22:10
Edit Download
3.71 KB lrw-r--r-- 2022-10-04 03:47:15
Edit Download
114.68 KB lrw-r--r-- 2022-09-20 04:02:10
Edit Download
9.44 KB lrw-r--r-- 2022-04-17 14:44:07
Edit Download
63.20 KB lrw-r--r-- 2022-08-05 13:39:11
Edit Download
44.53 KB lrw-r--r-- 2022-09-14 22:19:14
Edit Download
1.27 KB lrw-r--r-- 2022-09-20 02:51:09
Edit Download
3.68 KB lrw-r--r-- 2022-09-20 02:51:09
Edit Download
32.61 KB lrw-r--r-- 2022-09-20 02:51:09
Edit Download
45.74 KB lrw-r--r-- 2022-04-19 15:59:10
Edit Download
26.03 KB lrw-r--r-- 2022-07-21 09:04:14
Edit Download
1.06 KB lrw-r--r-- 2019-09-20 20:46:56
Edit Download
4.03 KB lrw-r--r-- 2021-11-30 17:18:01
Edit Download
33.90 KB lrw-r--r-- 2022-08-05 06:12:10
Edit Download
87.70 KB lrw-r--r-- 2022-08-11 13:55:08
Edit Download
75.54 KB lrw-r--r-- 2022-10-17 11:19:11
Edit Download
32.68 KB lrw-r--r-- 2022-06-01 18:14:10
Edit Download
15.76 KB lrw-r--r-- 2022-07-25 19:30:09
Edit Download
41.77 KB lrw-r--r-- 2022-09-20 14:26:10
Edit Download
6.21 KB lrw-r--r-- 2021-05-09 20:27:02
Edit Download
8.22 KB lrw-r--r-- 2022-06-16 23:39:08
Edit Download
93.45 KB lrw-r--r-- 2022-09-20 20:32:09
Edit Download
6.50 KB lrw-r--r-- 2022-08-05 06:00:09
Edit Download
45.31 KB lrw-r--r-- 2022-11-10 16:23:14
Edit Download
8.68 KB lrw-r--r-- 2022-01-27 21:15:03
Edit Download
61.18 KB lrw-r--r-- 2022-11-14 18:33:12
Edit Download
34.53 KB lrw-r--r-- 2022-10-11 10:05:16
Edit Download
108.02 KB lrw-r--r-- 2022-09-20 02:51:09
Edit Download
20.17 KB lrw-r--r-- 2022-06-02 15:05:13
Edit Download
10.54 KB lrw-r--r-- 2021-12-13 10:21:07
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).