wp_delete_file()
delete
wp_delete_file( string $file ): bool
Xóa một tập tin.
function wp_delete_file( $file ) {
/**
* Filters the path of the file to delete.
*
* @since 2.1.0
*
* @param string $file Path to the file to delete.
*/
$delete = apply_filters( 'wp_delete_file', $file );
if ( ! empty( $delete ) ) {
return @unlink( $delete );
}
return false;
}
Ví dụ 1: Xóa file
$file_path = "/home/public_html/wp-content/uploads/2020/04/photo_img_1-8.png" // path of the file which need to be deleted.
wp_delete_file( $file_path ); //delete file here.
true or false