wp_delete_file_from_directory()
Deletes a file if its path is within the given directory.
Uses: wp_delete_file()
Used By: wp_delete_attachment_files()
No Hooks.
Return
true|false
. True on success, false on failure.
Usage
wp_delete_file_from_directory( $file, $directory );
- $file(string) (required)
- Absolute path to the file to delete.
- $directory(string) (required)
- Absolute path to a directory.
Examples
#1 Delete the file test.html from the uploads directory
$upldir_info = wp_get_upload_dir(); $uploads_dir = $upldir_info['basedir']; // uploads path wp_delete_file_from_directory( "$uploads_dir/test.html", $uploads_dir ); // true or false
Changelog
Since 4.9.7 | Introduced. |