Skip to content

Commit d007b98

Browse files
Copilotswissspidy
andcommitted
Fix test: use $wpdb->insert() to preserve backslash-escaped JSON in post content
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent 11fa959 commit d007b98

1 file changed

Lines changed: 20 additions & 7 deletions

File tree

features/search-replace.feature

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -244,13 +244,26 @@ Feature: Do global search/replace
244244
And a create-post-with-json-content.php file:
245245
"""
246246
<?php
247-
$post_id = wp_insert_post( [
248-
'post_type' => 'post',
249-
'post_status' => 'publish',
250-
'post_title' => 'Font Test',
251-
'post_content' => json_encode( [ 'src' => 'http://example.com/wp-content/uploads/fonts/test.woff2', 'fontWeight' => '400' ] ),
252-
] );
253-
echo $post_id;
247+
// Insert directly via $wpdb to preserve backslash-escaped JSON (as WordPress font face data is stored).
248+
global $wpdb;
249+
$wpdb->insert(
250+
$wpdb->posts,
251+
[
252+
'post_type' => 'post',
253+
'post_status' => 'publish',
254+
'post_title' => 'Font Test',
255+
'post_content' => '{"src":"http:\/\/example.com\/wp-content\/uploads\/fonts\/test.woff2","fontWeight":"400"}',
256+
'post_author' => 1,
257+
'post_date' => '2024-01-01 00:00:00',
258+
'post_date_gmt' => '2024-01-01 00:00:00',
259+
'post_modified' => '2024-01-01 00:00:00',
260+
'post_modified_gmt' => '2024-01-01 00:00:00',
261+
'to_ping' => '',
262+
'pinged' => '',
263+
'post_content_filtered' => '',
264+
]
265+
);
266+
echo $wpdb->insert_id;
254267
"""
255268
And I run `wp eval-file create-post-with-json-content.php`
256269
Then save STDOUT as {POST_ID}

0 commit comments

Comments
 (0)