| @@ -7,8 +7,9 @@ | ||
| 7 | 7 | |
| 8 | 8 | namespace WP_Defender\Helper; |
| 9 | 9 | |
| 10 | 10 | use WP_Error; |
| 11 | +use WP_Filesystem_Base; | |
| 11 | 12 | |
| 12 | 13 | /** |
| 13 | 14 | * Handles file related tasks. |
| 14 | 15 | */ |
| @@ -50,9 +51,9 @@ | ||
| 50 | 51 | */ |
| 51 | 52 | public function maybe_dir_access_deny( string $directory ) { |
| 52 | 53 | global $wp_filesystem; |
| 53 | 54 | // Initialize the WP filesystem, no more using 'file-put-contents' function. |
| 54 | - if ( empty( $wp_filesystem ) ) { | |
| 55 | + if ( ! $wp_filesystem instanceof WP_Filesystem_Base ) { | |
| 55 | 56 | require_once ABSPATH . '/wp-admin/includes/file.php'; |
| 56 | 57 | WP_Filesystem(); |
| 57 | 58 | } |
| 58 | 59 | $files = array( |
| @@ -69,9 +70,9 @@ | ||
| 69 | 70 | ); |
| 70 | 71 | |
| 71 | 72 | foreach ( $files as $file ) { |
| 72 | 73 | $file_path = trailingslashit( $file['base'] ) . $file['file']; |
| 73 | - if ( ! is_null( $file_path ) && ! file_exists( $file_path ) ) { | |
| 74 | + if ( ! file_exists( $file_path ) ) { | |
| 74 | 75 | $wp_filesystem->put_contents( $file_path, $file['content'] ); |
| 75 | 76 | } |
| 76 | 77 | } |
| 77 | 78 | } |