require_once(ABSPATH . 'wp-admin/admin-footer.php');
exit;
case 'delete-selected':
- if ( ! current_user_can( 'delete_themes' ) )
+ if ( ! current_user_can( 'delete_themes' ) ) {
wp_die( __('You do not have sufficient permissions to delete themes for this site.') );
+ }
+
check_admin_referer( 'bulk-themes' );
$themes = isset( $_REQUEST['checked'] ) ? (array) $_REQUEST['checked'] : array();
- unset( $themes[ get_option( 'stylesheet' ) ], $themes[ get_option( 'template' ) ] );
-
if ( empty( $themes ) ) {
wp_safe_redirect( add_query_arg( 'error', 'none', $referer ) );
exit;
}
- $files_to_delete = $theme_info = array();
- foreach ( $themes as $key => $theme ) {
- $theme_info[ $theme ] = wp_get_theme( $theme );
- $files_to_delete = array_merge( $files_to_delete, list_files( $theme_info[ $theme ]->get_stylesheet_directory() ) );
- }
+ $themes = array_diff( $themes, array( get_option( 'stylesheet' ), get_option( 'template' ) ) );
if ( empty( $themes ) ) {
wp_safe_redirect( add_query_arg( 'error', 'main', $referer ) );
exit;
}
+ $files_to_delete = $theme_info = array();
+ $theme_translations = wp_get_installed_translations( 'themes' );
+ foreach ( $themes as $key => $theme ) {
+ $theme_info[ $theme ] = wp_get_theme( $theme );
+
+ // Locate all the files in that folder.
+ $files = list_files( $theme_info[ $theme ]->get_stylesheet_directory() );
+ if ( $files ) {
+ $files_to_delete = array_merge( $files_to_delete, $files );
+ }
+
+ // Add translation files.
+ $theme_slug = $theme_info[ $theme ]->get_stylesheet();
+ if ( ! empty( $theme_translations[ $theme_slug ] ) ) {
+ $translations = $theme_translations[ $theme_slug ];
+
+ foreach ( $translations as $translation => $data ) {
+ $files_to_delete[] = $theme_slug . '-' . $translation . '.po';
+ $files_to_delete[] = $theme_slug . '-' . $translation . '.mo';
+ }
+ }
+ }
+
include(ABSPATH . 'wp-admin/update.php');
$parent_file = 'themes.php';
<div class="error"><p><strong><?php _e( 'Caution:' ); ?></strong> <?php echo _n( 'This theme may be active on other sites in the network.', 'These themes may be active on other sites in the network.', $themes_to_delete ); ?></p></div>
<p><?php echo _n( 'You are about to remove the following theme:', 'You are about to remove the following themes:', $themes_to_delete ); ?></p>
<ul class="ul-disc">
- <?php foreach ( $theme_info as $theme )
- 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 */ ?>
+ <?php
+ foreach ( $theme_info as $theme ) {
+ /* translators: 1: theme name, 2: theme author */
+ echo '<li>', sprintf( __('<strong>%1$s</strong> by <em>%2$s</em>' ), $theme->display('Name'), $theme->display('Author') ), '</li>';
+ }
+ ?>
</ul>
<p><?php _e('Are you sure you wish to delete these themes?'); ?></p>
<form method="post" action="<?php echo esc_url($_SERVER['REQUEST_URI']); ?>" style="display:inline;">
<input type="hidden" name="verify-delete" value="1" />
<input type="hidden" name="action" value="delete-selected" />
<?php
- foreach ( (array) $themes as $theme )
+ foreach ( (array) $themes as $theme ) {
echo '<input type="hidden" name="checked[]" value="' . esc_attr($theme) . '" />';
+ }
?>
<?php wp_nonce_field('bulk-themes') ?>
<?php submit_button( _n( 'Yes, Delete this theme', 'Yes, Delete these themes', $themes_to_delete ), 'button', 'submit', false ); ?>
<div id="files-list" style="display:none;">
<ul class="code">
<?php
- foreach ( (array) $files_to_delete as $file )
- echo '<li>' . esc_html( str_replace( WP_CONTENT_DIR . "/themes", '', $file) ) . '</li>';
+ foreach ( (array) $files_to_delete as $file ) {
+ echo '<li>' . esc_html( str_replace( WP_CONTENT_DIR . '/themes', '', $file ) ) . '</li>';
+ }
?>
</ul>
</div>