Revisions: slash meta values for autosave (preview) revisions.

Correct an issue where meta values containing characters like quote `”` could not be previewed on published posts. The function `update_metadata` expects data to be slashed.

Also, add a test to confirm that storing JSON data which requires slashing in autosave meta works as expected, and improve naming for a data provider added in [56714].

Follow up to [56714].

Props mukesh27, spacedmonkey.
Fixes #20564.



git-svn-id: https://develop.svn.wordpress.org/trunk@56745 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Adam Silverstein
2023-09-29 15:05:40 +00:00
parent 345fb48865
commit 1f914ecb2f
3 changed files with 73 additions and 4 deletions

View File

@@ -421,7 +421,7 @@ class WP_REST_Autosaves_Controller extends WP_REST_Revisions_Controller {
if ( ! empty( $meta ) ) {
foreach ( $revisioned_meta_keys as $meta_key ) {
if ( isset( $meta[ $meta_key ] ) ) {
update_metadata( 'post', $revision_id, $meta_key, $meta[ $meta_key ] );
update_metadata( 'post', $revision_id, $meta_key, wp_slash( $meta[ $meta_key ] ) );
}
}
}