Skip to content

Commit

Permalink
Quality: Fix warning error when exporting theme (#671)
Browse files Browse the repository at this point in the history
  • Loading branch information
t-hamano authored Jun 10, 2024
1 parent ddf7459 commit 58fed31
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 21 deletions.
1 change: 1 addition & 0 deletions includes/class-create-block-theme-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ function rest_export_theme( $request ) {
header( 'Content-Length: ' . filesize( $filename ) );
flush();
echo readfile( $filename );
exit;
}

/**
Expand Down
27 changes: 6 additions & 21 deletions src/utils/download-file.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* WordPress dependencies
*/
import { downloadBlob } from '@wordpress/blob';

/*
* Download a file from in a browser.
*
Expand All @@ -9,25 +14,5 @@ export default async function downloadFile( response ) {
const filename = response.headers
.get( 'Content-Disposition' )
.split( 'filename=' )[ 1 ];

// Check if the browser supports navigator.msSaveBlob or navigator.saveBlob
if ( window.navigator.msSaveBlob || window.navigator.saveBlob ) {
const saveBlob =
window.navigator.msSaveBlob || window.navigator.saveBlob;
saveBlob.call( window.navigator, blob, filename );
} else {
// Fall back to creating an object URL and triggering a download using an anchor element
const url = URL.createObjectURL( blob );

const a = document.createElement( 'a' );
a.href = url;
a.download = filename;
document.body.appendChild( a );
a.click();
document.body.removeChild( a );

setTimeout( () => {
URL.revokeObjectURL( url );
}, 100 );
}
downloadBlob( filename, blob, 'application/zip' );
}

0 comments on commit 58fed31

Please sign in to comment.