mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-22 17:18:32 +01:00
Filesystem API: Add a return value for wp_delete_file()
.
This addresses a discrepancy where using `unlink()` allows for checking if it was successful via the return value, but `wp_delete_file()` did not have a return value, making it impossible to verify the result without doing overhead checks if the file still exists. This also brings more consistency with the other `wp_delete_*()` functions, specifically: * `wp_delete_file_from_directory()` * `wp_delete_post()` * `wp_delete_post_revision()` * `wp_delete_attachment()` * `wp_delete_attachment_files()` * `wp_delete_comment()` * `wp_delete_nav_menu()` * `wp_delete_term()` * `wp_delete_site()` * `wp_delete_user()` Includes adding basic unit tests for `wp_delete_file()`. Follow-up to [31575]. Props bedas, debarghyabanerjee, mukesh27, SergeyBiryukov. Fixes #61590. Built from https://develop.svn.wordpress.org/trunk@58715 git-svn-id: http://core.svn.wordpress.org/trunk@58117 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
4f85cc258c
commit
667521c97f
@ -7644,8 +7644,10 @@ function wp_validate_boolean( $value ) {
|
||||
* Deletes a file.
|
||||
*
|
||||
* @since 4.2.0
|
||||
* @since 6.7.0 A return value was added.
|
||||
*
|
||||
* @param string $file The path to the file to delete.
|
||||
* @return bool True on success, false on failure.
|
||||
*/
|
||||
function wp_delete_file( $file ) {
|
||||
/**
|
||||
@ -7656,9 +7658,12 @@ function wp_delete_file( $file ) {
|
||||
* @param string $file Path to the file to delete.
|
||||
*/
|
||||
$delete = apply_filters( 'wp_delete_file', $file );
|
||||
|
||||
if ( ! empty( $delete ) ) {
|
||||
@unlink( $delete );
|
||||
return @unlink( $delete );
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -7691,9 +7696,7 @@ function wp_delete_file_from_directory( $file, $directory ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
wp_delete_file( $file );
|
||||
|
||||
return true;
|
||||
return wp_delete_file( $file );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -16,7 +16,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '6.7-alpha-58714';
|
||||
$wp_version = '6.7-alpha-58715';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
Loading…
Reference in New Issue
Block a user