Skip to content

Commit 098833b

Browse files
replace only basedir
1 parent ea2e4cc commit 098833b

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

src/class-tiny-plugin.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -945,14 +945,12 @@ public function backup_original_image( $attachment_id ) {
945945

946946
$file_path = $original_image->filename;
947947
$upload_dir = wp_upload_dir();
948-
if ( Tiny_Helpers::str_starts_with( $file_path, $upload_dir['basedir'] ) ) {
949-
$replacements = 1;
950-
$file_path = str_replace( $upload_dir['basedir'], '', $original_image->filename, $replacements );
951-
$file_path = ltrim( $file_path, '/' );
948+
$basedir = trailingslashit( $upload_dir['basedir'] );
949+
if ( Tiny_Helpers::str_starts_with( $file_path, $basedir ) ) {
950+
$file_path = substr( $file_path, strlen( $basedir ) );
952951
}
953952

954-
$upload_base = trailingslashit( $upload_dir['basedir'] );
955-
$backup_file = $upload_base . 'tinify_backup/' . $file_path;
953+
$backup_file = $basedir . 'tinify_backup/' . $file_path;
956954

957955
$wp_filesystem = Tiny_Helpers::get_wp_filesystem();
958956

0 commit comments

Comments
 (0)