Privacy: Ensure "Export Personal Data" does not generate invalid JSON.

Previously, when exporting personal data, if the JSON encoding of the data failed, the invalid JSON was still written to `export.json`.  This change captures the JSON encoding failure and adds a notice to the UI.  

Props hellofromTonya, jrf, SergeyBiryukov.
Fixes #52892.
Built from https://develop.svn.wordpress.org/trunk@50713


git-svn-id: http://core.svn.wordpress.org/trunk@50322 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
davidbaumwald 2021-04-14 21:28:08 +00:00
parent 294c370d72
commit b7280388d6
2 changed files with 11 additions and 1 deletions

View File

@ -413,6 +413,16 @@ function wp_privacy_generate_personal_data_export_file( $request_id ) {
// Convert the groups to JSON format.
$groups_json = wp_json_encode( $groups );
if ( false === $groups_json ) {
$error_message = sprintf(
/* translators: %s: Error message. */
__( 'Unable to encode the personal data for export. Error: %s' ),
json_last_error_msg()
);
wp_send_json_error( $error_message );
}
/*
* Handle the JSON export.
*/

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.8-alpha-50712';
$wp_version = '5.8-alpha-50713';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.