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/network/themes.php

    r29839 r29856  
    9797            exit;
    9898        case 'delete-selected':
    99             if ( ! current_user_can( 'delete_themes' ) )
     99            if ( ! current_user_can( 'delete_themes' ) ) {
    100100                wp_die( __('You do not have sufficient permissions to delete themes for this site.') );
     101            }
     102
    101103            check_admin_referer( 'bulk-themes' );
    102104
     
    116118
    117119            $files_to_delete = $theme_info = array();
     120            $theme_translations = wp_get_installed_translations( 'themes' );
    118121            foreach ( $themes as $key => $theme ) {
    119122                $theme_info[ $theme ] = wp_get_theme( $theme );
    120                 $files_to_delete = array_merge( $files_to_delete, list_files( $theme_info[ $theme ]->get_stylesheet_directory() ) );
     123
     124                // Locate all the files in that folder.
     125                $files = list_files( $theme_info[ $theme ]->get_stylesheet_directory() );
     126                if ( $files ) {
     127                    $files_to_delete = array_merge( $files_to_delete, $files );
     128                }
     129
     130                // Add translation files.
     131                $theme_slug = $theme_info[ $theme ]->get_stylesheet();
     132                if ( ! empty( $theme_translations[ $theme_slug ] ) ) {
     133                    $translations = $theme_translations[ $theme_slug ];
     134
     135                    foreach ( $translations as $translation => $data ) {
     136                        $files_to_delete[] = $theme_slug . '-' . $translation . '.po';
     137                        $files_to_delete[] = $theme_slug . '-' . $translation . '.mo';
     138                    }
     139                }
    121140            }
    122141
     
    137156                <p><?php echo _n( 'You are about to remove the following theme:', 'You are about to remove the following themes:', $themes_to_delete ); ?></p>
    138157                    <ul class="ul-disc">
    139                         <?php foreach ( $theme_info as $theme )
    140                             echo '<li>', sprintf( __('<strong>%1$s</strong> by <em>%2$s</em>' ), $theme->display('Name'), $theme->display('Author') ), '</li>'; /* translators: 1: theme name, 2: theme author */ ?>
     158                    <?php
     159                        foreach ( $theme_info as $theme ) {
     160                            /* translators: 1: theme name, 2: theme author */
     161                            echo '<li>', sprintf( __('<strong>%1$s</strong> by <em>%2$s</em>' ), $theme->display('Name'), $theme->display('Author') ), '</li>';
     162                        }
     163                    ?>
    141164                    </ul>
    142165                <p><?php _e('Are you sure you wish to delete these themes?'); ?></p>
     
    145168                    <input type="hidden" name="action" value="delete-selected" />
    146169                    <?php
    147                         foreach ( (array) $themes as $theme )
     170                        foreach ( (array) $themes as $theme ) {
    148171                            echo '<input type="hidden" name="checked[]" value="' . esc_attr($theme) . '" />';
     172                        }
    149173                    ?>
    150174                    <?php wp_nonce_field('bulk-themes') ?>
     
    159183                    <ul class="code">
    160184                    <?php
    161                         foreach ( (array) $files_to_delete as $file )
    162                             echo '<li>' . esc_html( str_replace( WP_CONTENT_DIR . "/themes", '', $file) ) . '</li>';
     185                        foreach ( (array) $files_to_delete as $file ) {
     186                            echo '<li>' . esc_html( str_replace( WP_CONTENT_DIR . '/themes', '', $file ) ) . '</li>';
     187                        }
    163188                    ?>
    164189                    </ul>
Note: See TracChangeset for help on using the changeset viewer.