Quality: Fix warning error when exporting theme (#671)

This commit is contained in:
Aki Hamano 2024-06-10 23:14:51 +09:00 committed by GitHub
parent ddf7459282
commit 58fed318c7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 21 deletions

View file

@ -308,6 +308,7 @@ class CBT_Theme_API {
header( 'Content-Length: ' . filesize( $filename ) );
flush();
echo readfile( $filename );
exit;
}

/**

View file

@ -1,3 +1,8 @@
/**
* WordPress dependencies
*/
import { downloadBlob } from '@wordpress/blob';

/*
* Download a file from in a browser.
*
@ -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' );
}