Core Ticket 51423: test script to make `wp_json_encode` fail during generation of personal data export JSON file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Testing\Ticket51423; | |
add_action( 'wp_privacy_personal_data_export_file', __NAMESPACE__ . '\setup_testing_export_file', 5 ); | |
function setup_testing_export_file( $request_id ) { | |
$GLOBALS['testing_51423'] = array( | |
'request_id' => $request_id, | |
'_export_data_grouped' => get_post_meta( $request_id, '_export_data_grouped', true ), | |
); | |
add_filter( 'get_post_metadata', __NAMESPACE__ . '\filter_export_data_grouped', 99, 3 ); | |
} | |
function filter_export_data_grouped( $value, $id, $meta_key ) { | |
if ( '_export_data_grouped' !== $meta_key ) { | |
return $value; | |
} | |
if ( $GLOBALS['testing_51423']['request_id'] !== $id ) { | |
return $value; | |
} | |
// Taken from the function. | |
$exports_dir = wp_privacy_exports_dir(); | |
$obscura = wp_generate_password( 32, false, false ); | |
$json_report_filename = "wp-personal-data-file-{$obscura}.json"; | |
$json_report_pathname = wp_normalize_path( $exports_dir . $json_report_filename ); | |
$file = fopen( $json_report_pathname, 'w' ); | |
// Add the resource to the meta which should make the encoding fail. | |
$value = $GLOBALS['testing_51423']['_export_data_grouped']; | |
$value['user']['resource'] = $file; | |
return array( $value ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment