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. Built from https://develop.svn.wordpress.org/trunk@29856 git-svn-id: http://core.svn.wordpress.org/trunk@29619 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
5f17e0952d
commit
57c41263d7
|
@ -797,29 +797,50 @@ function delete_plugins( $plugins, $deprecated = '' ) {
|
|||
if ( is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code() )
|
||||
return new WP_Error('fs_error', __('Filesystem error.'), $wp_filesystem->errors);
|
||||
|
||||
//Get the base plugin folder
|
||||
// Get the base plugin folder.
|
||||
$plugins_dir = $wp_filesystem->wp_plugins_dir();
|
||||
if ( empty($plugins_dir) )
|
||||
return new WP_Error('fs_no_plugins_dir', __('Unable to locate WordPress Plugin directory.'));
|
||||
if ( empty( $plugins_dir ) ) {
|
||||
return new WP_Error( 'fs_no_plugins_dir', __( 'Unable to locate WordPress Plugin directory.' ) );
|
||||
}
|
||||
|
||||
$plugins_dir = trailingslashit( $plugins_dir );
|
||||
|
||||
$translations_dir = $wp_filesystem->wp_lang_dir();
|
||||
$translations_dir = trailingslashit( $translations_dir );
|
||||
|
||||
$plugin_translations = wp_get_installed_translations( 'plugins' );
|
||||
|
||||
$errors = array();
|
||||
|
||||
foreach( $plugins as $plugin_file ) {
|
||||
// Run Uninstall hook
|
||||
if ( is_uninstallable_plugin( $plugin_file ) )
|
||||
// Run Uninstall hook.
|
||||
if ( is_uninstallable_plugin( $plugin_file ) ) {
|
||||
uninstall_plugin($plugin_file);
|
||||
}
|
||||
|
||||
$this_plugin_dir = trailingslashit( dirname($plugins_dir . $plugin_file) );
|
||||
$this_plugin_dir = trailingslashit( dirname( $plugins_dir . $plugin_file ) );
|
||||
// If plugin is in its own directory, recursively delete the directory.
|
||||
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
|
||||
$deleted = $wp_filesystem->delete($this_plugin_dir, true);
|
||||
else
|
||||
$deleted = $wp_filesystem->delete($plugins_dir . $plugin_file);
|
||||
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
|
||||
$deleted = $wp_filesystem->delete( $this_plugin_dir, true );
|
||||
} else {
|
||||
$deleted = $wp_filesystem->delete( $plugins_dir . $plugin_file );
|
||||
}
|
||||
|
||||
if ( ! $deleted )
|
||||
if ( ! $deleted ) {
|
||||
$errors[] = $plugin_file;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Remove language files, silently.
|
||||
$plugin_slug = dirname( $plugin_file );
|
||||
if ( '.' !== $plugin_slug && ! empty( $plugin_translations[ $plugin_slug ] ) ) {
|
||||
$translations = $plugin_translations[ $plugin_slug ];
|
||||
|
||||
foreach ( $translations as $translation => $data ) {
|
||||
$wp_filesystem->delete( WP_LANG_DIR . '/plugins/' . $plugin_slug . '-' . $translation . '.po' );
|
||||
$wp_filesystem->delete( WP_LANG_DIR . '/plugins/' . $plugin_slug . '-' . $translation . '.mo' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Remove deleted plugins from the plugin updates list.
|
||||
|
|
|
@ -55,20 +55,37 @@ function delete_theme($stylesheet, $redirect = '') {
|
|||
if ( is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code() )
|
||||
return new WP_Error('fs_error', __('Filesystem error.'), $wp_filesystem->errors);
|
||||
|
||||
//Get the base plugin folder
|
||||
// Get the base plugin folder.
|
||||
$themes_dir = $wp_filesystem->wp_themes_dir();
|
||||
if ( empty($themes_dir) )
|
||||
return new WP_Error('fs_no_themes_dir', __('Unable to locate WordPress theme directory.'));
|
||||
if ( empty( $themes_dir ) ) {
|
||||
return new WP_Error( 'fs_no_themes_dir', __( 'Unable to locate WordPress theme directory.' ) );
|
||||
}
|
||||
|
||||
$themes_dir = trailingslashit( $themes_dir );
|
||||
$theme_dir = trailingslashit($themes_dir . $stylesheet);
|
||||
$deleted = $wp_filesystem->delete($theme_dir, true);
|
||||
$theme_dir = trailingslashit( $themes_dir . $stylesheet );
|
||||
$deleted = $wp_filesystem->delete( $theme_dir, true );
|
||||
|
||||
if ( ! $deleted )
|
||||
return new WP_Error('could_not_remove_theme', sprintf(__('Could not fully remove the theme %s.'), $stylesheet) );
|
||||
if ( ! $deleted ) {
|
||||
return new WP_Error( 'could_not_remove_theme', sprintf( __( 'Could not fully remove the theme %s.' ), $stylesheet ) );
|
||||
}
|
||||
|
||||
// Force refresh of theme update information
|
||||
delete_site_transient('update_themes');
|
||||
$translations_dir = $wp_filesystem->wp_lang_dir();
|
||||
$translations_dir = trailingslashit( $translations_dir );
|
||||
|
||||
$theme_translations = wp_get_installed_translations( 'themes' );
|
||||
|
||||
// Remove language files, silently.
|
||||
if ( ! empty( $theme_translations[ $stylesheet ] ) ) {
|
||||
$translations = $theme_translations[ $stylesheet ];
|
||||
|
||||
foreach ( $translations as $translation => $data ) {
|
||||
$wp_filesystem->delete( WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '.po' );
|
||||
$wp_filesystem->delete( WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '.mo' );
|
||||
}
|
||||
}
|
||||
|
||||
// Force refresh of theme update information.
|
||||
delete_site_transient( 'update_themes' );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -96,8 +96,10 @@ if ( $action ) {
|
|||
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();
|
||||
|
@ -115,9 +117,26 @@ if ( $action ) {
|
|||
}
|
||||
|
||||
$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 );
|
||||
$files_to_delete = array_merge( $files_to_delete, list_files( $theme_info[ $theme ]->get_stylesheet_directory() ) );
|
||||
|
||||
// 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');
|
||||
|
@ -136,16 +155,21 @@ if ( $action ) {
|
|||
<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 ); ?>
|
||||
|
@ -158,8 +182,9 @@ if ( $action ) {
|
|||
<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>
|
||||
|
|
|
@ -207,8 +207,9 @@ if ( $action ) {
|
|||
exit;
|
||||
|
||||
case 'delete-selected':
|
||||
if ( ! current_user_can('delete_plugins') )
|
||||
if ( ! current_user_can('delete_plugins') ) {
|
||||
wp_die(__('You do not have sufficient permissions to delete plugins for this site.'));
|
||||
}
|
||||
|
||||
check_admin_referer('bulk-plugins');
|
||||
|
||||
|
@ -237,31 +238,47 @@ if ( $action ) {
|
|||
<?php
|
||||
$files_to_delete = $plugin_info = array();
|
||||
$have_non_network_plugins = false;
|
||||
$plugin_translations = wp_get_installed_translations( 'plugins' );
|
||||
foreach ( (array) $plugins as $plugin ) {
|
||||
if ( '.' == dirname($plugin) ) {
|
||||
$plugin_slug = dirname( $plugin );
|
||||
|
||||
if ( '.' == $plugin_slug ) {
|
||||
$files_to_delete[] = WP_PLUGIN_DIR . '/' . $plugin;
|
||||
if( $data = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin) ) {
|
||||
if ( $data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin ) ) {
|
||||
$plugin_info[ $plugin ] = $data;
|
||||
$plugin_info[ $plugin ]['is_uninstallable'] = is_uninstallable_plugin( $plugin );
|
||||
if ( ! $plugin_info[ $plugin ]['Network'] )
|
||||
if ( ! $plugin_info[ $plugin ]['Network'] ) {
|
||||
$have_non_network_plugins = true;
|
||||
}
|
||||
} else {
|
||||
// Locate all the files in that folder
|
||||
$files = list_files( WP_PLUGIN_DIR . '/' . dirname($plugin) );
|
||||
if ( $files ) {
|
||||
$files_to_delete = array_merge($files_to_delete, $files);
|
||||
}
|
||||
// Get plugins list from that folder
|
||||
if ( $folder_plugins = get_plugins( '/' . dirname($plugin)) ) {
|
||||
} else {
|
||||
// Locate all the files in that folder.
|
||||
$files = list_files( WP_PLUGIN_DIR . '/' . $plugin_slug );
|
||||
if ( $files ) {
|
||||
$files_to_delete = array_merge( $files_to_delete, $files );
|
||||
}
|
||||
|
||||
// Get plugins list from that folder.
|
||||
if ( $folder_plugins = get_plugins( '/' . $plugin_slug ) ) {
|
||||
foreach( $folder_plugins as $plugin_file => $data ) {
|
||||
$plugin_info[ $plugin_file ] = _get_plugin_data_markup_translate( $plugin_file, $data );
|
||||
$plugin_info[ $plugin_file ]['is_uninstallable'] = is_uninstallable_plugin( $plugin );
|
||||
if ( ! $plugin_info[ $plugin_file ]['Network'] )
|
||||
if ( ! $plugin_info[ $plugin_file ]['Network'] ) {
|
||||
$have_non_network_plugins = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add translation files.
|
||||
if ( ! empty( $plugin_translations[ $plugin_slug ] ) ) {
|
||||
$translations = $plugin_translations[ $plugin_slug ];
|
||||
|
||||
foreach ( $translations as $translation => $data ) {
|
||||
$files_to_delete[] = $plugin_slug . '-' . $translation . '.po';
|
||||
$files_to_delete[] = $plugin_slug . '-' . $translation . '.mo';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$plugins_to_delete = count( $plugin_info );
|
||||
echo '<h2>' . _n( 'Delete Plugin', 'Delete Plugins', $plugins_to_delete ) . '</h2>';
|
||||
|
@ -295,8 +312,9 @@ if ( $action ) {
|
|||
<input type="hidden" name="verify-delete" value="1" />
|
||||
<input type="hidden" name="action" value="delete-selected" />
|
||||
<?php
|
||||
foreach ( (array) $plugins as $plugin )
|
||||
echo '<input type="hidden" name="checked[]" value="' . esc_attr($plugin) . '" />';
|
||||
foreach ( (array) $plugins as $plugin ) {
|
||||
echo '<input type="hidden" name="checked[]" value="' . esc_attr( $plugin ) . '" />';
|
||||
}
|
||||
?>
|
||||
<?php wp_nonce_field('bulk-plugins') ?>
|
||||
<?php submit_button( $data_to_delete ? __( 'Yes, Delete these files and data' ) : __( 'Yes, Delete these files' ), 'button', 'submit', false ); ?>
|
||||
|
@ -309,8 +327,9 @@ if ( $action ) {
|
|||
<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_PLUGIN_DIR, '', $file)) . '</li>';
|
||||
foreach ( (array) $files_to_delete as $file ) {
|
||||
echo '<li>' . esc_html( str_replace( WP_PLUGIN_DIR, '', $file ) ) . '</li>';
|
||||
}
|
||||
?>
|
||||
</ul>
|
||||
</div>
|
||||
|
|
|
@ -797,16 +797,23 @@ function wp_get_installed_translations( $type ) {
|
|||
$language_data = array();
|
||||
|
||||
foreach ( $files as $file ) {
|
||||
if ( '.' === $file[0] || is_dir( $file ) )
|
||||
if ( '.' === $file[0] || is_dir( $file ) ) {
|
||||
continue;
|
||||
if ( substr( $file, -3 ) !== '.po' )
|
||||
}
|
||||
if ( substr( $file, -3 ) !== '.po' ) {
|
||||
continue;
|
||||
if ( ! preg_match( '/(?:(.+)-)?([A-Za-z_]{2,6}).po/', $file, $match ) )
|
||||
}
|
||||
if ( ! preg_match( '/(?:(.+)-)?([A-Za-z_]{2,6}).po/', $file, $match ) ) {
|
||||
continue;
|
||||
}
|
||||
if ( ! in_array( substr( $file, 0, -3 ) . '.mo', $files ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
list( , $textdomain, $language ) = $match;
|
||||
if ( '' === $textdomain )
|
||||
if ( '' === $textdomain ) {
|
||||
$textdomain = 'default';
|
||||
}
|
||||
$language_data[ $textdomain ][ $language ] = wp_get_pomo_file_data( WP_LANG_DIR . "$dir/$file" );
|
||||
}
|
||||
return $language_data;
|
||||
|
|
Loading…
Reference in New Issue