Make WordPress Core


Ignore:
Timestamp:
10/08/2014 07:04:05 PM (10 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/plugin.php

    r29818 r29856  
    798798        return new WP_Error('fs_error', __('Filesystem error.'), $wp_filesystem->errors);
    799799
    800     //Get the base plugin folder
     800    // Get the base plugin folder.
    801801    $plugins_dir = $wp_filesystem->wp_plugins_dir();
    802     if ( empty($plugins_dir) )
    803         return new WP_Error('fs_no_plugins_dir', __('Unable to locate WordPress Plugin directory.'));
     802    if ( empty( $plugins_dir ) ) {
     803        return new WP_Error( 'fs_no_plugins_dir', __( 'Unable to locate WordPress Plugin directory.' ) );
     804    }
    804805
    805806    $plugins_dir = trailingslashit( $plugins_dir );
    806807
     808    $translations_dir = $wp_filesystem->wp_lang_dir();
     809    $translations_dir = trailingslashit( $translations_dir );
     810
     811    $plugin_translations = wp_get_installed_translations( 'plugins' );
     812
    807813    $errors = array();
    808814
    809815    foreach( $plugins as $plugin_file ) {
    810         // Run Uninstall hook
    811         if ( is_uninstallable_plugin( $plugin_file ) )
     816        // Run Uninstall hook.
     817        if ( is_uninstallable_plugin( $plugin_file ) ) {
    812818            uninstall_plugin($plugin_file);
    813 
    814         $this_plugin_dir = trailingslashit( dirname($plugins_dir . $plugin_file) );
     819        }
     820
     821        $this_plugin_dir = trailingslashit( dirname( $plugins_dir . $plugin_file ) );
    815822        // If plugin is in its own directory, recursively delete the directory.
    816         if ( strpos($plugin_file, '/') && $this_plugin_dir != $plugins_dir ) //base check on if plugin includes directory separator AND that it's not the root plugin folder
    817             $deleted = $wp_filesystem->delete($this_plugin_dir, true);
    818         else
    819             $deleted = $wp_filesystem->delete($plugins_dir . $plugin_file);
    820 
    821         if ( ! $deleted )
     823        if ( strpos( $plugin_file, '/' ) && $this_plugin_dir != $plugins_dir ) { //base check on if plugin includes directory separator AND that it's not the root plugin folder
     824            $deleted = $wp_filesystem->delete( $this_plugin_dir, true );
     825        } else {
     826            $deleted = $wp_filesystem->delete( $plugins_dir . $plugin_file );
     827        }
     828
     829        if ( ! $deleted ) {
    822830            $errors[] = $plugin_file;
     831            continue;
     832        }
     833
     834        // Remove language files, silently.
     835        $plugin_slug = dirname( $plugin_file );
     836        if ( '.' !== $plugin_slug && ! empty( $plugin_translations[ $plugin_slug ] ) ) {
     837            $translations = $plugin_translations[ $plugin_slug ];
     838
     839            foreach ( $translations as $translation => $data ) {
     840                $wp_filesystem->delete( WP_LANG_DIR . '/plugins/' . $plugin_slug . '-' . $translation . '.po' );
     841                $wp_filesystem->delete( WP_LANG_DIR . '/plugins/' . $plugin_slug . '-' . $translation . '.mo' );
     842            }
     843        }
    823844    }
    824845
Note: See TracChangeset for help on using the changeset viewer.