Skip to content

Commit

Permalink
Merge pull request #7732 from Automattic/update/replace-unlink-with-w…
Browse files Browse the repository at this point in the history
…p_delete_file

Replace `unlink` with `wp_delete_file`
  • Loading branch information
donnapep authored Jan 14, 2025
2 parents 1984ab6 + d57cfa0 commit cd4e022
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 4 additions & 0 deletions changelog/update-replace-unlink-with-wp_delete_file
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Replace `unlink` with `wp_delete_file`
4 changes: 2 additions & 2 deletions includes/data-port/class-sensei-data-port-job.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public function get_results() {
public function get_logs() {
usort(
$this->logs,
function( $first_log, $second_log ) {
function ( $first_log, $second_log ) {

// Get the type ordering and compare the two logs based on that.
$log_order = $this->get_log_type_order();
Expand Down Expand Up @@ -514,7 +514,7 @@ public function save_file( $file_key, $tmp_file, $file_name ) {
$move_new_file = @copy( $tmp_file, $file_save_path );

if ( 0 === strpos( $tmp_file, sys_get_temp_dir() ) ) {
unlink( $tmp_file );
wp_delete_file( $tmp_file );
}

if ( ! $move_new_file || ! file_exists( $file_save_path ) ) {
Expand Down
5 changes: 3 additions & 2 deletions includes/data-port/export-tasks/class-sensei-export-task.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,11 @@ public function add_file_to_job( $tmp_file ) {
$type = $this->get_content_type();
$date = gmdate( 'Y-m-d' );
$filename = sanitize_file_name( get_bloginfo( 'name' ) . '-' . ucwords( $type ) . 's-' . $date . '.csv' );

$this->get_job()->save_file( $type, $tmp_file, $filename );

if ( file_exists( $tmp_file ) ) {
unlink( $tmp_file );
wp_delete_file( $tmp_file );
}
}

}

0 comments on commit cd4e022

Please sign in to comment.