wp_download_language_pack

函式
wp_download_language_pack ( $download )
引數
  • (string) $download Language code to download.
    Required:
返回值
  • (string|false) Returns the language code if successfully downloaded (or already installed), or false on failure.
相關
  • wp_get_available_translations()
定義位置
相關方法
wp_dropdown_languageswp_can_install_language_packwp_install_language_formmu_dropdown_languageswp_load_image
引入
4.0.0
棄用
-

wp_download_language_pack: 這個函式用來下載和安裝一個特定WordPress語言的語言包。語言包用於將WordPress翻譯成不同的語言,這個函式可以用來自動下載和安裝一個新的語言包的過程。

下載一個語言包。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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;
}
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; }
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;
}

常見問題

FAQs
檢視更多 >