Skip to content

Commit

Permalink
Better error handling of wp_filesystem issue brainstormforce#19
Browse files Browse the repository at this point in the history
- Check if WP_Filesystem is generating some errors
- Print error generated by WP_Filesystem
  • Loading branch information
MilenaBimbasic committed Apr 16, 2021
1 parent badb188 commit 74820cb
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions inc/classes/class-astra-import-export-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,19 @@ public static function import() {
require_once ABSPATH . '/wp-admin/includes/file.php';
WP_Filesystem();
}

//Check if there are some errors and print them
if ( is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) {
$error_messages = $wp_filesystem->errors->get_error_messages();
$print_messages = '';

foreach ( $error_messages as $message ) {
$print_messages .= $message . ' ';
}

wp_die( esc_html__( $print_messages, 'astra-import-export' ) );
}

// Retrieve the settings from the file and convert the json object to an array.
$file_contants = $wp_filesystem->get_contents( $import_file );
$settings = json_decode( $file_contants, 1 );
Expand Down

0 comments on commit 74820cb

Please sign in to comment.