Language_Pack_Upgrader::check_package() WordPress Method

The Language_Pack_Upgrader::check_package() method is used to check if a language package is valid. This is done by checking if the package is a valid ZIP file and if it contains the required files.

Language_Pack_Upgrader::check_package( string|WP_Error $source, string $remote_source ) #

Checks that the package source contains .mo and .po files.


Description

Hooked to the ‘upgrader_source_selection’ filter by Language_Pack_Upgrader::bulk_upgrade().


Top ↑

Parameters

$source

(string|WP_Error)(Required)The path to the downloaded package source.

$remote_source

(string)(Required)Remote file source location.


Top ↑

Return

(string|WP_Error) The source as passed, or a WP_Error object on failure.


Top ↑

Source

File: wp-admin/includes/class-language-pack-upgrader.php

	public function check_package( $source, $remote_source ) {
		global $wp_filesystem;

		if ( is_wp_error( $source ) ) {
			return $source;
		}

		// Check that the folder contains a valid language.
		$files = $wp_filesystem->dirlist( $remote_source );

		// Check to see if a .po and .mo exist in the folder.
		$po = false;
		$mo = false;
		foreach ( (array) $files as $file => $filedata ) {
			if ( '.po' === substr( $file, -3 ) ) {
				$po = true;
			} elseif ( '.mo' === substr( $file, -3 ) ) {
				$mo = true;
			}
		}

		if ( ! $mo || ! $po ) {
			return new WP_Error(
				'incompatible_archive_pomo',
				$this->strings['incompatible_archive'],
				sprintf(
					/* translators: 1: .po, 2: .mo */
					__( 'The language pack is missing either the %1$s or %2$s files.' ),
					'<code>.po</code>',
					'<code>.mo</code>'
				)
			);
		}

		return $source;
	}


Top ↑

Changelog

Changelog
VersionDescription
3.7.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.