diff --git a/src/wp-admin/includes/file.php b/src/wp-admin/includes/file.php index 13f04f05d4..44d1b8d080 100644 --- a/src/wp-admin/includes/file.php +++ b/src/wp-admin/includes/file.php @@ -1971,19 +1971,16 @@ function move_dir( $from, $to, $overwrite = false ) { global $wp_filesystem; if ( trailingslashit( strtolower( $from ) ) === trailingslashit( strtolower( $to ) ) ) { - return new WP_Error( - 'source_destination_same_move_dir', - __( 'The source and destination are the same.' ) - ); + return new WP_Error( 'source_destination_same_move_dir', __( 'The source and destination are the same.' ) ); } - if ( ! $overwrite && $wp_filesystem->exists( $to ) ) { - return new WP_Error( 'destination_already_exists_move_dir', __( 'The destination folder already exists.' ), $to ); - } - - if ( $overwrite && $wp_filesystem->exists( $to ) && ! $wp_filesystem->delete( $to, true ) ) { - // Can't overwrite if the destination couldn't be deleted. - return WP_Error( 'destination_not_deleted_move_dir', __( 'The destination directory already exists and could not be removed.' ) ); + if ( $wp_filesystem->exists( $to ) ) { + if ( ! $overwrite ) { + return new WP_Error( 'destination_already_exists_move_dir', __( 'The destination folder already exists.' ), $to ); + } elseif ( ! $wp_filesystem->delete( $to, true ) ) { + // Can't overwrite if the destination couldn't be deleted. + return WP_Error( 'destination_not_deleted_move_dir', __( 'The destination directory already exists and could not be removed.' ) ); + } } if ( $wp_filesystem->move( $from, $to ) ) {