PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 6.3.0
Defender Security – Malware Scanner, Login Security & Firewall v6.3.0
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
← All changes | src/traits/file-operations.php +22 -6 5.4.1 → 6.3.0 View file →
@@ -7,8 +7,9 @@
7 7
8 8 namespace WP_Defender\Traits;
9 9
10 10 use WP_Error;
11 +use WP_Filesystem_Base;
11 12 use WP_Defender\Model\Scan;
12 13 use WP_Defender\Component\Error_Code;
13 14
14 15 trait File_Operations {
@@ -20,15 +21,27 @@
20 21 *
21 22 * @return bool Returns true if the file was successfully deleted, false otherwise.
22 23 */
23 24 public function delete_infected_file( string $file ): bool {
25 + $wp_filesystem = $this->get_wp_filesystem();
26 +
27 + return file_exists( $file ) && $wp_filesystem->is_writable( $file ) && $wp_filesystem->delete( $file );
28 + }
29 +
30 + /**
31 + * Get the WordPress filesystem instance.
32 + *
33 + * @return WP_Filesystem_Base The WordPress filesystem instance.
34 + */
35 + public function get_wp_filesystem(): WP_Filesystem_Base {
24 36 global $wp_filesystem;
25 - // Initialize the WP filesystem, no more using 'file-put-contents' function.
26 - if ( empty( $wp_filesystem ) ) {
37 +
38 + if ( ! $wp_filesystem instanceof WP_Filesystem_Base ) {
27 39 require_once ABSPATH . '/wp-admin/includes/file.php';
28 40 WP_Filesystem();
29 41 }
30 - return file_exists( $file ) && $wp_filesystem->is_writable( $file ) && $wp_filesystem->delete( $file );
42 +
43 + return $wp_filesystem;
31 44 }
32 45
33 46 /**
34 47 * Handle actions after deleting a file or folder.
@@ -55,8 +68,10 @@
55 68 *
56 69 * @return WP_Error The WP_Error object with the error code and the basename of the file.
57 70 */
58 71 public function get_permission_error( string $file ): WP_Error {
72 + $this->log( sprintf( 'ISSUE: %s is not writeable', $file ), \WP_Defender\Controller\Scan::SCAN_LOG );
73 +
59 74 return new WP_Error( Error_Code::NOT_WRITEABLE, wp_basename( $file ) );
60 75 }
61 76
62 77 /**
@@ -62,20 +77,21 @@
62 77 /**
63 78 * Get file meta details: created_at, size, and deleted flag.
64 79 *
65 80 * @param string $file The path to the file.
81 + *
66 82 * @return array An array containing the file's created_at date, size, and a deleted flag.
67 83 */
68 84 private function get_file_meta( string $file ): array {
69 85 if ( ! file_exists( $file ) || ! is_readable( $file ) ) {
70 - return array( 'n/a', 'n/a', true );
86 + return array( null, null, true );
71 87 }
72 88
73 89 $file_created_at = filemtime( $file );
74 - $file_created_at = $file_created_at ? $this->format_date_time( $file_created_at ) : 'n/a';
90 + $file_created_at = $file_created_at ? wp_date( 'M j, Y', $file_created_at ) : null;
75 91
76 92 $file_size = filesize( $file );
77 - $file_size = $file_size ? $this->format_bytes_into_readable( $file_size ) : 'n/a';
93 + $file_size = $file_size ? $this->format_bytes_into_readable( $file_size ) : null;
78 94
79 95 return array( $file_created_at, $file_size, false );
80 96 }
81 97 }