$email_address =
$request->email;
if ( !
is_email( $email_address ) ) { wp_send_json_error( __( 'Invalid email address when generating personal data export file.'
) );
} // Create the exports folder if needed.
$exports_dir =
wp_privacy_exports_dir();
$exports_url =
wp_privacy_exports_url();
if ( !
wp_mkdir_p( $exports_dir ) ) { wp_send_json_error( __( 'Unable to create personal data export folder.'
) );
} // Protect export folder from browsing.
$index_pathname =
$exports_dir . 'index.php';
if ( !
file_exists( $index_pathname ) ) { $file =
fopen( $index_pathname, 'w'
);
if ( false ===
$file ) { wp_send_json_error( __( 'Unable to protect personal data export folder from browsing.'
) );
} fwrite( $file, "<?php\n// Silence is golden.\n"
);