carbon-fields icon indicating copy to clipboard operation
carbon-fields copied to clipboard

Rich text content was mangled with wp_update_post

Open DevAndreyBilchenko opened this issue 1 year ago • 0 comments

Version

  • Carbon Fields: 3.6.5
  • WordPress: 6.6.2
  • PHP: 7.4

Expected Behavior

<!-- wp:carbon-fields/crb-test {"data":{"crb_text":"\u003cp\u003esome text\u003c/p\u003e"}} /-->

Actual Behavior

<!-- wp:carbon-fields/crb-test {"data":{"crb_text":"u003cpu003esome textu003c/pu003e"}} /-->

Gutenberg block definition

<?php

use Carbon_Fields\Block;
use Carbon_Fields\Field;

Block::make("crb_test", "TEST")
    ->add_fields(array(
        Field::make('rich_text', 'crb_text', "Content")
            ->set_width(100)
    ))
    ->set_mode('preview')
    ->set_category('theme-blocks')
    ->set_render_callback(function ($fields, $attributes, $inner_blocks) {
?>
    <div>
        <?= $fields['crb_text']; ?>
    </div>
<?php

Steps to Reproduce the Problem

  1. Create a page with crb_test block inside
  2. Fill text inside rich text. Check for the paragraph tag in text tab
  3. Call wp_update_post with post_content of created post
  4. Reload created page

Comments

I'm used this snipped for checking wp_update_post behavior. functions.php

add_action('init', function () {
	$check = isset($_GET['test']);
	if (!$check) {
		return;
	}
	$created_post_id = 1245;
	$post = get_post($created_post_id);
	echo esc_html($post->post_content);

	if (has_blocks($post->post_content)) {
		wp_update_post([
			'ID' => $post->ID,
			'post_content' => $post->post_content
		]);
	}

	echo "<br>";
	$post = get_post($created_post_id);
	echo esc_html($post->post_content);

	exit(200);
});

Then visit website.com/?test

DevAndreyBilchenko avatar Sep 24 '24 13:09 DevAndreyBilchenko