| 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 | } |