Code Modernization: Check if the `_export_data_grouped` post meta is an array when generating a personal data export file.
This avoids a fatal error on PHP 8 in `wp_privacy_generate_personal_data_export_file()` if the `_export_data_grouped` post meta exists but is not an array. Additionally, refactor unit tests for the function to: * Reduce redundant code * Switch to data provider * Test on the full HTML output instead of select pieces of the output * Expand unhappy path coverage Follow-up to [43012], [44786], [47146], [47278]. Props hellofromTonya, jrf, xknown. See #51423. Built from https://develop.svn.wordpress.org/trunk@50613 git-svn-id: http://core.svn.wordpress.org/trunk@50226 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
59d32bfe24
commit
69a7063a49
|
@ -362,9 +362,6 @@ function wp_privacy_generate_personal_data_export_file( $request_id ) {
|
||||||
$email_address
|
$email_address
|
||||||
);
|
);
|
||||||
|
|
||||||
// And now, all the Groups.
|
|
||||||
$groups = get_post_meta( $request_id, '_export_data_grouped', true );
|
|
||||||
|
|
||||||
// First, build an "About" group on the fly for this report.
|
// First, build an "About" group on the fly for this report.
|
||||||
$about_group = array(
|
$about_group = array(
|
||||||
/* translators: Header for the About section in a personal data export. */
|
/* translators: Header for the About section in a personal data export. */
|
||||||
|
@ -393,10 +390,25 @@ function wp_privacy_generate_personal_data_export_file( $request_id ) {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Merge in the special about group.
|
// And now, all the Groups.
|
||||||
$groups = array_merge( array( 'about' => $about_group ), $groups );
|
$groups = get_post_meta( $request_id, '_export_data_grouped', true );
|
||||||
|
if ( is_array( $groups ) ) {
|
||||||
|
// Merge in the special "About" group.
|
||||||
|
$groups = array_merge( array( 'about' => $about_group ), $groups );
|
||||||
|
$groups_count = count( $groups );
|
||||||
|
} else {
|
||||||
|
if ( false !== $groups ) {
|
||||||
|
_doing_it_wrong(
|
||||||
|
__FUNCTION__,
|
||||||
|
/* translators: %s: Post meta key. */
|
||||||
|
sprintf( __( 'The %s post meta must be an array.' ), '<code>_export_data_grouped</code>' ),
|
||||||
|
'5.8.0'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
$groups_count = count( $groups );
|
$groups = null;
|
||||||
|
$groups_count = 0;
|
||||||
|
}
|
||||||
|
|
||||||
// Convert the groups to JSON format.
|
// Convert the groups to JSON format.
|
||||||
$groups_json = wp_json_encode( $groups );
|
$groups_json = wp_json_encode( $groups );
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '5.8-alpha-50612';
|
$wp_version = '5.8-alpha-50613';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue