Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quality: Fix warning error when exporting theme #671

Merged
merged 1 commit into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -442,6 +442,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' );
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a minor refactoring. With this change, we no longer check if the browser is IE, but this should not be a problem since WordPress itself does not support IE.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was actually unfamiliar with msSaveBlob until looking into this change. Likewise WordPress' implementation of the anchor downloading technique so I'm happy to replace that. It works as expected.

Thank's for cleaning that up.

}
Loading