Language_Pack_Upgrader::check_package()
Checks that the package source contains .mo and .po files.
Hooked to the upgrader_source_selection filter by Language_Pack_Upgrader::bulk_upgrade().
Method of the class: Language_Pack_Upgrader{}
No Hooks.
Return
String|WP_Error
. The source as passed, or a WP_Error object on failure.
Usage
$Language_Pack_Upgrader = new Language_Pack_Upgrader(); $Language_Pack_Upgrader->check_package( $source, $remote_source );
- $source(string|WP_Error) (required)
- The path to the downloaded package source.
- $remote_source(string) (required)
- Remote file source location.
Notes
- Global. WP_Filesystem_Base. $wp_filesystem WordPress filesystem subclass.
Changelog
Since 3.7.0 | Introduced. |
Language_Pack_Upgrader::check_package() Language Pack Upgrader::check package code WP 6.7.1
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 the expected files exist in the folder. $po = false; $mo = false; $php = false; foreach ( (array) $files as $file => $filedata ) { if ( str_ends_with( $file, '.po' ) ) { $po = true; } elseif ( str_ends_with( $file, '.mo' ) ) { $mo = true; } elseif ( str_ends_with( $file, '.l10n.php' ) ) { $php = true; } } if ( $php ) { return $source; } if ( ! $mo || ! $po ) { return new WP_Error( 'incompatible_archive_pomo', $this->strings['incompatible_archive'], sprintf( /* translators: 1: .po, 2: .mo, 3: .l10n.php */ __( 'The language pack is missing either the %1$s, %2$s, or %3$s files.' ), '<code>.po</code>', '<code>.mo</code>', '<code>.l10n.php</code>' ) ); } return $source; }