wp_delete_file_from_directory( string $file, string $directory )
Deletes a file if its path is within the given directory.
Parameters
- $file
-
(Required) Absolute path to the file to delete.
- $directory
-
(Required) Absolute path to a directory.
Return
(bool) True on success, false on failure.
Source
File: wp-includes/functions.php
function wp_delete_file_from_directory( $file, $directory ) {
$real_file = realpath( wp_normalize_path( $file ) );
$real_directory = realpath( wp_normalize_path( $directory ) );
if ( false === $real_file || false === $real_directory || strpos( wp_normalize_path( $real_file ), trailingslashit( wp_normalize_path( $real_directory ) ) ) !== 0 ) {
return false;
}
wp_delete_file( $file );
return true;
}
Changelog
Version | Description |
---|---|
WP-4.9.7 | Introduced. |