wp/wp-admin/includes/translation-install.php
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
equal deleted inserted replaced
8:c7c34916027a 9:177826044cd9
    18  */
    18  */
    19 function translations_api( $type, $args = null ) {
    19 function translations_api( $type, $args = null ) {
    20 	include( ABSPATH . WPINC . '/version.php' ); // include an unmodified $wp_version
    20 	include( ABSPATH . WPINC . '/version.php' ); // include an unmodified $wp_version
    21 
    21 
    22 	if ( ! in_array( $type, array( 'plugins', 'themes', 'core' ) ) ) {
    22 	if ( ! in_array( $type, array( 'plugins', 'themes', 'core' ) ) ) {
    23 		return	new WP_Error( 'invalid_type', __( 'Invalid translation type.' ) );
    23 		return  new WP_Error( 'invalid_type', __( 'Invalid translation type.' ) );
    24 	}
    24 	}
    25 
    25 
    26 	/**
    26 	/**
    27 	 * Allows a plugin to override the WordPress.org Translation Installation API entirely.
    27 	 * Allows a plugin to override the WordPress.org Translation Installation API entirely.
    28 	 *
    28 	 *
    40 			$url = set_url_scheme( $url, 'https' );
    40 			$url = set_url_scheme( $url, 'https' );
    41 		}
    41 		}
    42 
    42 
    43 		$options = array(
    43 		$options = array(
    44 			'timeout' => 3,
    44 			'timeout' => 3,
    45 			'body' => array(
    45 			'body'    => array(
    46 				'wp_version' => $wp_version,
    46 				'wp_version' => $wp_version,
    47 				'locale'     => get_locale(),
    47 				'locale'     => get_locale(),
    48 				'version'    => $args['version'], // Version of plugin, theme or core
    48 				'version'    => $args['version'], // Version of plugin, theme or core
    49 			),
    49 			),
    50 		);
    50 		);
    67 
    67 
    68 			$request = wp_remote_post( $http_url, $options );
    68 			$request = wp_remote_post( $http_url, $options );
    69 		}
    69 		}
    70 
    70 
    71 		if ( is_wp_error( $request ) ) {
    71 		if ( is_wp_error( $request ) ) {
    72 			$res = new WP_Error( 'translations_api_failed',
    72 			$res = new WP_Error(
       
    73 				'translations_api_failed',
    73 				sprintf(
    74 				sprintf(
    74 					/* translators: %s: support forums URL */
    75 					/* translators: %s: support forums URL */
    75 					__( '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>.' ),
    76 					__( '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>.' ),
    76 					__( 'https://wordpress.org/support/' )
    77 					__( 'https://wordpress.org/support/' )
    77 				),
    78 				),
    78 				$request->get_error_message()
    79 				$request->get_error_message()
    79 			);
    80 			);
    80 		} else {
    81 		} else {
    81 			$res = json_decode( wp_remote_retrieve_body( $request ), true );
    82 			$res = json_decode( wp_remote_retrieve_body( $request ), true );
    82 			if ( ! is_object( $res ) && ! is_array( $res ) ) {
    83 			if ( ! is_object( $res ) && ! is_array( $res ) ) {
    83 				$res = new WP_Error( 'translations_api_failed',
    84 				$res = new WP_Error(
       
    85 					'translations_api_failed',
    84 					sprintf(
    86 					sprintf(
    85 						/* translators: %s: support forums URL */
    87 						/* translators: %s: support forums URL */
    86 						__( '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>.' ),
    88 						__( '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>.' ),
    87 						__( 'https://wordpress.org/support/' )
    89 						__( 'https://wordpress.org/support/' )
    88 					),
    90 					),
   160 	echo "\n";
   162 	echo "\n";
   161 
   163 
   162 	if ( ! empty( $wp_local_package ) && isset( $languages[ $wp_local_package ] ) ) {
   164 	if ( ! empty( $wp_local_package ) && isset( $languages[ $wp_local_package ] ) ) {
   163 		if ( isset( $languages[ $wp_local_package ] ) ) {
   165 		if ( isset( $languages[ $wp_local_package ] ) ) {
   164 			$language = $languages[ $wp_local_package ];
   166 			$language = $languages[ $wp_local_package ];
   165 			printf( '<option value="%s" lang="%s" data-continue="%s"%s>%s</option>' . "\n",
   167 			printf(
       
   168 				'<option value="%s" lang="%s" data-continue="%s"%s>%s</option>' . "\n",
   166 				esc_attr( $language['language'] ),
   169 				esc_attr( $language['language'] ),
   167 				esc_attr( current( $language['iso'] ) ),
   170 				esc_attr( current( $language['iso'] ) ),
   168 				esc_attr( $language['strings']['continue'] ),
   171 				esc_attr( $language['strings']['continue'] ),
   169 				in_array( $language['language'], $installed_languages ) ? ' data-installed="1"' : '',
   172 				in_array( $language['language'], $installed_languages ) ? ' data-installed="1"' : '',
   170 				esc_html( $language['native_name'] ) );
   173 				esc_html( $language['native_name'] )
       
   174 			);
   171 
   175 
   172 			unset( $languages[ $wp_local_package ] );
   176 			unset( $languages[ $wp_local_package ] );
   173 		}
   177 		}
   174 	}
   178 	}
   175 
   179 
   176 	foreach ( $languages as $language ) {
   180 	foreach ( $languages as $language ) {
   177 		printf( '<option value="%s" lang="%s" data-continue="%s"%s>%s</option>' . "\n",
   181 		printf(
       
   182 			'<option value="%s" lang="%s" data-continue="%s"%s>%s</option>' . "\n",
   178 			esc_attr( $language['language'] ),
   183 			esc_attr( $language['language'] ),
   179 			esc_attr( current( $language['iso'] ) ),
   184 			esc_attr( current( $language['iso'] ) ),
   180 			esc_attr( $language['strings']['continue'] ),
   185 			esc_attr( $language['strings']['continue'] ),
   181 			in_array( $language['language'], $installed_languages ) ? ' data-installed="1"' : '',
   186 			in_array( $language['language'], $installed_languages ) ? ' data-installed="1"' : '',
   182 			esc_html( $language['native_name'] ) );
   187 			esc_html( $language['native_name'] )
       
   188 		);
   183 	}
   189 	}
   184 	echo "</select>\n";
   190 	echo "</select>\n";
   185 	echo '<p class="step"><span class="spinner"></span><input id="language-continue" type="submit" class="button button-primary button-large" value="Continue" /></p>';
   191 	echo '<p class="step"><span class="spinner"></span><input id="language-continue" type="submit" class="button button-primary button-large" value="Continue" /></p>';
   186 }
   192 }
   187 
   193 
   222 		return false;
   228 		return false;
   223 	}
   229 	}
   224 	$translation = (object) $translation;
   230 	$translation = (object) $translation;
   225 
   231 
   226 	require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
   232 	require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
   227 	$skin = new Automatic_Upgrader_Skin;
   233 	$skin              = new Automatic_Upgrader_Skin;
   228 	$upgrader = new Language_Pack_Upgrader( $skin );
   234 	$upgrader          = new Language_Pack_Upgrader( $skin );
   229 	$translation->type = 'core';
   235 	$translation->type = 'core';
   230 	$result = $upgrader->upgrade( $translation, array( 'clear_update_cache' => false ) );
   236 	$result            = $upgrader->upgrade( $translation, array( 'clear_update_cache' => false ) );
   231 
   237 
   232 	if ( ! $result || is_wp_error( $result ) ) {
   238 	if ( ! $result || is_wp_error( $result ) ) {
   233 		return false;
   239 		return false;
   234 	}
   240 	}
   235 
   241 
   248 	if ( ! wp_is_file_mod_allowed( 'can_install_language_pack' ) ) {
   254 	if ( ! wp_is_file_mod_allowed( 'can_install_language_pack' ) ) {
   249 		return false;
   255 		return false;
   250 	}
   256 	}
   251 
   257 
   252 	require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
   258 	require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
   253 	$skin = new Automatic_Upgrader_Skin;
   259 	$skin     = new Automatic_Upgrader_Skin;
   254 	$upgrader = new Language_Pack_Upgrader( $skin );
   260 	$upgrader = new Language_Pack_Upgrader( $skin );
   255 	$upgrader->init();
   261 	$upgrader->init();
   256 
   262 
   257 	$check = $upgrader->fs_connect( array( WP_CONTENT_DIR, WP_LANG_DIR ) );
   263 	$check = $upgrader->fs_connect( array( WP_CONTENT_DIR, WP_LANG_DIR ) );
   258 
   264