PluginProbe
Image Optimizer – Compress Images and Convert to WebP or AVIF / 1.7.7
Image Optimizer – Compress Images and Convert to WebP or AVIF v1.7.7
1.7.7 1.7.6 1.7.5 1.7.4 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.3.0 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 All 33 releases
← All changes | classes/file-system/file-system.php +11 -7 1.1.01.7.7 View file →
@@ -31,9 +31,9 @@
31 31
32 32 $result = $wp_filesystem->put_contents( $file, $contents, $mode );
33 33
34 34 if ( ! $result ) {
35 - throw new File_System_Operation_Error( 'Error while writing ' . $file );
35 + throw new File_System_Operation_Error( esc_html( "Error while writing $file" ) );
36 36 }
37 37
38 38 return true;
39 39 }
@@ -54,9 +54,9 @@
54 54
55 55 $result = $wp_filesystem->delete( $file, $recursive, $type );
56 56
57 57 if ( ! $result ) {
58 - throw new File_System_Operation_Error( 'Error while deleting ' . $file );
58 + throw new File_System_Operation_Error( esc_html( "Error while deleting $file" ) );
59 59 }
60 60
61 61 return true;
62 62 }
@@ -75,9 +75,9 @@
75 75
76 76 $result = $wp_filesystem->move( $source, $destination, $overwrite );
77 77
78 78 if ( ! $result ) {
79 - throw new File_System_Operation_Error( "Error while moving {$source} to {$destination}" );
79 + throw new File_System_Operation_Error( esc_html( "Error while moving $source to $destination" ) );
80 80 }
81 81
82 82 return true;
83 83 }
@@ -99,9 +99,9 @@
99 99
100 100 $result = $wp_filesystem->copy( $source, $destination, $overwrite, $mode );
101 101
102 102 if ( ! $result ) {
103 - throw new File_System_Operation_Error( "Error while copying {$source} to {$destination}" );
103 + throw new File_System_Operation_Error( esc_html( "Error while copying $source to $destination" ) );
104 104 }
105 105
106 106 return true;
107 107 }
@@ -121,21 +121,25 @@
121 121
122 122 /**
123 123 * Gets the file size (in bytes).
124 124 *
125 - * @param string $path Path to file.
125 + * @param ?string $path Path to file.
126 126 *
127 127 * @return int Size of the file in bytes on success, false on failure.
128 128 *
129 129 * @throws File_System_Operation_Error
130 130 */
131 - public static function size( string $path ): int {
131 + public static function size( ?string $path ): int {
132 132 global $wp_filesystem;
133 133
134 + if ( is_null( $path ) ) {
135 + throw new File_System_Operation_Error( 'Null file path provided' );
136 + }
137 +
134 138 $size = $wp_filesystem->size( $path );
135 139
136 140 if ( ! $size ) {
137 - throw new File_System_Operation_Error( "Unable to calculate file size for $path" );
141 + throw new File_System_Operation_Error( esc_html( "Unable to calculate file size for $path" ) );
138 142 }
139 143
140 144 return $size;
141 145 }