Make WordPress Core

Ticket #49132: 49132.diff

File 49132.diff, 1.7 KB (added by audrasjb, 5 years ago)

First, let's do that for plugins. If the plugin doesn’t exists anymore, silently remove the related language files

  • src/wp-admin/includes/plugin.php

    diff --git a/src/wp-admin/includes/plugin.php b/src/wp-admin/includes/plugin.php
    index b3b150a0de..b7e7c86fab 100644
    a b function validate_active_plugins() { 
    10581058                if ( is_wp_error( $result ) ) {
    10591059                        $invalid[ $plugin ] = $result;
    10601060                        deactivate_plugins( $plugin, true );
     1061
     1062                        // If the plugin doesn’t exists anymore, remove the related language files, silently.
     1063                        $error_code = $result->get_error_codes();
     1064                        if ( 'plugin_not_found' === $error_code[0] ) {
     1065                                global $wp_filesystem;
     1066                                require_once( ABSPATH . '/wp-admin/includes/file.php' );
     1067                                WP_Filesystem();
     1068
     1069                                $plugins_dir = $wp_filesystem->wp_plugins_dir();
     1070                                if ( empty( $plugins_dir ) ) {
     1071                                        return new WP_Error( 'fs_no_plugins_dir', __( 'Unable to locate WordPress plugin directory.' ) );
     1072                                }
     1073
     1074                                $plugins_dir = trailingslashit( $plugins_dir );
     1075                                $plugin_translations = wp_get_installed_translations( 'plugins' );
     1076                                $plugin_slug = dirname( $plugin );     
     1077                                if ( '.' !== $plugin_slug && ! empty( $plugin_translations[ $plugin_slug ] ) ) {
     1078                                        $translations = $plugin_translations[ $plugin_slug ];
     1079                                        foreach ( $translations as $translation => $data ) {
     1080                                                $wp_filesystem->delete( WP_LANG_DIR . '/plugins/' . $plugin_slug . '-' . $translation . '.po' );
     1081                                                $wp_filesystem->delete( WP_LANG_DIR . '/plugins/' . $plugin_slug . '-' . $translation . '.mo' );
     1082                                                $json_translation_files = glob( WP_LANG_DIR . '/plugins/' . $plugin_slug . '-' . $translation . '-*.json' );
     1083                                                if ( $json_translation_files ) {
     1084                                                        array_map( array( $wp_filesystem, 'delete' ), $json_translation_files );
     1085                                                }
     1086                                        }
     1087                                }
     1088                        }
    10611089                }
    10621090        }
    10631091        return $invalid;