Make WordPress Core


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

    r28646 r29856  
    208208
    209209        case 'delete-selected':
    210             if ( ! current_user_can('delete_plugins') )
     210            if ( ! current_user_can('delete_plugins') ) {
    211211                wp_die(__('You do not have sufficient permissions to delete plugins for this site.'));
     212            }
    212213
    213214            check_admin_referer('bulk-plugins');
     
    238239                    $files_to_delete = $plugin_info = array();
    239240                    $have_non_network_plugins = false;
     241                    $plugin_translations = wp_get_installed_translations( 'plugins' );
    240242                    foreach ( (array) $plugins as $plugin ) {
    241                         if ( '.' == dirname($plugin) ) {
     243                        $plugin_slug = dirname( $plugin );
     244
     245                        if ( '.' == $plugin_slug ) {
    242246                            $files_to_delete[] = WP_PLUGIN_DIR . '/' . $plugin;
    243                             if( $data = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin) ) {
     247                            if ( $data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin ) ) {
    244248                                $plugin_info[ $plugin ] = $data;
    245249                                $plugin_info[ $plugin ]['is_uninstallable'] = is_uninstallable_plugin( $plugin );
    246                                 if ( ! $plugin_info[ $plugin ]['Network'] )
     250                                if ( ! $plugin_info[ $plugin ]['Network'] ) {
    247251                                    $have_non_network_plugins = true;
     252                                }
    248253                            }
    249254                        } else {
    250                             // Locate all the files in that folder
    251                             $files = list_files( WP_PLUGIN_DIR . '/' . dirname($plugin) );
     255                            // Locate all the files in that folder.
     256                            $files = list_files( WP_PLUGIN_DIR . '/' . $plugin_slug );
    252257                            if ( $files ) {
    253                                 $files_to_delete = array_merge($files_to_delete, $files);
     258                                $files_to_delete = array_merge( $files_to_delete, $files );
    254259                            }
    255                             // Get plugins list from that folder
    256                             if ( $folder_plugins = get_plugins( '/' . dirname($plugin)) ) {
     260
     261                            // Get plugins list from that folder.
     262                            if ( $folder_plugins = get_plugins( '/' . $plugin_slug ) ) {
    257263                                foreach( $folder_plugins as $plugin_file => $data ) {
    258264                                    $plugin_info[ $plugin_file ] = _get_plugin_data_markup_translate( $plugin_file, $data );
    259265                                    $plugin_info[ $plugin_file ]['is_uninstallable'] = is_uninstallable_plugin( $plugin );
    260                                     if ( ! $plugin_info[ $plugin_file ]['Network'] )
     266                                    if ( ! $plugin_info[ $plugin_file ]['Network'] ) {
    261267                                        $have_non_network_plugins = true;
     268                                    }
     269                                }
     270                            }
     271
     272                            // Add translation files.
     273                            if ( ! empty( $plugin_translations[ $plugin_slug ] ) ) {
     274                                $translations = $plugin_translations[ $plugin_slug ];
     275
     276                                foreach ( $translations as $translation => $data ) {
     277                                    $files_to_delete[] = $plugin_slug . '-' . $translation . '.po';
     278                                    $files_to_delete[] = $plugin_slug . '-' . $translation . '.mo';
    262279                                }
    263280                            }
     
    296313                    <input type="hidden" name="action" value="delete-selected" />
    297314                    <?php
    298                         foreach ( (array) $plugins as $plugin )
    299                             echo '<input type="hidden" name="checked[]" value="' . esc_attr($plugin) . '" />';
     315                        foreach ( (array) $plugins as $plugin ) {
     316                            echo '<input type="hidden" name="checked[]" value="' . esc_attr( $plugin ) . '" />';
     317                        }
    300318                    ?>
    301319                    <?php wp_nonce_field('bulk-plugins') ?>
     
    310328                    <ul class="code">
    311329                    <?php
    312                         foreach ( (array)$files_to_delete as $file )
    313                             echo '<li>' . esc_html(str_replace(WP_PLUGIN_DIR, '', $file)) . '</li>';
     330                        foreach ( (array) $files_to_delete as $file ) {
     331                            echo '<li>' . esc_html( str_replace( WP_PLUGIN_DIR, '', $file ) ) . '</li>';
     332                        }
    314333                    ?>
    315334                    </ul>
Note: See TracChangeset for help on using the changeset viewer.