WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/08/2014 07:04:05 PM (7 years ago)
Author:
ocean90
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/theme.php

    r29479 r29856  
    5656        return new WP_Error('fs_error', __('Filesystem error.'), $wp_filesystem->errors);
    5757
    58     //Get the base plugin folder
     58    // Get the base plugin folder.
    5959    $themes_dir = $wp_filesystem->wp_themes_dir();
    60     if ( empty($themes_dir) )
    61         return new WP_Error('fs_no_themes_dir', __('Unable to locate WordPress theme directory.'));
     60    if ( empty( $themes_dir ) ) {
     61        return new WP_Error( 'fs_no_themes_dir', __( 'Unable to locate WordPress theme directory.' ) );
     62    }
    6263
    6364    $themes_dir = trailingslashit( $themes_dir );
    64     $theme_dir = trailingslashit($themes_dir . $stylesheet);
    65     $deleted = $wp_filesystem->delete($theme_dir, true);
    66 
    67     if ( ! $deleted )
    68         return new WP_Error('could_not_remove_theme', sprintf(__('Could not fully remove the theme %s.'), $stylesheet) );
    69 
    70     // Force refresh of theme update information
    71     delete_site_transient('update_themes');
     65    $theme_dir = trailingslashit( $themes_dir . $stylesheet );
     66    $deleted = $wp_filesystem->delete( $theme_dir, true );
     67
     68    if ( ! $deleted ) {
     69        return new WP_Error( 'could_not_remove_theme', sprintf( __( 'Could not fully remove the theme %s.' ), $stylesheet ) );
     70    }
     71
     72    $translations_dir = $wp_filesystem->wp_lang_dir();
     73    $translations_dir = trailingslashit( $translations_dir );
     74
     75    $theme_translations = wp_get_installed_translations( 'themes' );
     76
     77    // Remove language files, silently.
     78    if ( ! empty( $theme_translations[ $stylesheet ] ) ) {
     79        $translations = $theme_translations[ $stylesheet ];
     80
     81        foreach ( $translations as $translation => $data ) {
     82            $wp_filesystem->delete( WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '.po' );
     83            $wp_filesystem->delete( WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '.mo' );
     84        }
     85    }
     86
     87    // Force refresh of theme update information.
     88    delete_site_transient( 'update_themes' );
    7289
    7390    return true;
Note: See TracChangeset for help on using the changeset viewer.