Language packs: Remove translations when deleting a theme or a plugin.

This is for translation files in WP_LANG_DIR which are installed through a language pack.
Change `wp_get_installed_translations()` to only return a translation if the .mo file also exists.

fixes #29860.

git-svn-id: https://develop.svn.wordpress.org/trunk@29856 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Dominik Schilling (ocean90)
2014-10-08 19:04:05 +00:00
parent 061fe13c9f
commit e9be4237ba
5 changed files with 134 additions and 45 deletions

View File

@@ -55,20 +55,37 @@ function delete_theme($stylesheet, $redirect = '') {
if ( is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code() )
return new WP_Error('fs_error', __('Filesystem error.'), $wp_filesystem->errors);
//Get the base plugin folder
// Get the base plugin folder.
$themes_dir = $wp_filesystem->wp_themes_dir();
if ( empty($themes_dir) )
return new WP_Error('fs_no_themes_dir', __('Unable to locate WordPress theme directory.'));
if ( empty( $themes_dir ) ) {
return new WP_Error( 'fs_no_themes_dir', __( 'Unable to locate WordPress theme directory.' ) );
}
$themes_dir = trailingslashit( $themes_dir );
$theme_dir = trailingslashit($themes_dir . $stylesheet);
$deleted = $wp_filesystem->delete($theme_dir, true);
$theme_dir = trailingslashit( $themes_dir . $stylesheet );
$deleted = $wp_filesystem->delete( $theme_dir, true );
if ( ! $deleted )
return new WP_Error('could_not_remove_theme', sprintf(__('Could not fully remove the theme %s.'), $stylesheet) );
if ( ! $deleted ) {
return new WP_Error( 'could_not_remove_theme', sprintf( __( 'Could not fully remove the theme %s.' ), $stylesheet ) );
}
// Force refresh of theme update information
delete_site_transient('update_themes');
$translations_dir = $wp_filesystem->wp_lang_dir();
$translations_dir = trailingslashit( $translations_dir );
$theme_translations = wp_get_installed_translations( 'themes' );
// Remove language files, silently.
if ( ! empty( $theme_translations[ $stylesheet ] ) ) {
$translations = $theme_translations[ $stylesheet ];
foreach ( $translations as $translation => $data ) {
$wp_filesystem->delete( WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '.po' );
$wp_filesystem->delete( WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '.mo' );
}
}
// Force refresh of theme update information.
delete_site_transient( 'update_themes' );
return true;
}