I was in the process checking some of my existing plugins for any unsafe filesystem accesses, when I ran across WP_Image_Editor’s save
function, which calls _save
, which finally calls make_image
(below). WP_Image_Editor was released in WP 3.5
, while the Filesystem API
has been around since WP 2.6
, so I would presume that the reasoning is related to the specifics of the use-case rather than just not being changed to meet new standards.
protected function make_image( $filename, $function, $arguments ) {
if ( $stream = wp_is_stream( $filename ) ) {
ob_start();
} else {
// The directory containing the original file may no longer exist when using a replication plugin.
wp_mkdir_p( dirname( $filename ) );
}
$result = call_user_func_array( $function, $arguments );
if ( $result && $stream ) {
$contents = ob_get_contents();
$fp = fopen( $filename, 'w' );
if ( ! $fp )
return false;
fwrite( $fp, $contents );
fclose( $fp );
}
if ( $stream ) {
ob_end_clean();
}
return $result;
}
My question is, what are the reasons for this? According to Otto, directly accessing the filesystem is evil, so what are the exceptions that make it alright in this instance? I want my plugins to behave in the best way possible, but this makes best practices a little difficult to discern.