我想用PHP操作Gutenberg块。因此,我需要将post\\u内容解析为一个数组,并在操作后以同样的方式返回。但我没有走那么远,因为来回的解析已经不起作用了。
function change_post_data_before_save( $data, $postarr ) {
$post_data = $data[\'post_content\']; //post_content seems to be json encoded
//stripping slashes otherwise $blocks[0][\'attrs\'] would be NULL
$post_data = str_replace(\'\\\\"\', \'"\', $post_data);
//trying to replace double slash in unicodes but it seems not to work
$post_data = str_replace(\'\\\\\\u\', \'\\u\', $post_data);
$blocks = parse_blocks($post_data); //there are still some issues with schema and other array parts
//manipulation of $blocks if needed
$post_content = serialize_blocks( $blocks ); //seems to work correct
$data[\'post_content\'] = $post_content;
return $data;
}
add_filter( \'wp_insert_post_data\', \'change_post_data_before_save\', 10, 2 );
你知道如何用json解码$数据[\'post\\u data\'],而不破坏$块[0][\'attrs\']中需要json编码的部分吗?我尝试过替换,但它似乎对Unicode不起作用,serialize\\u blocks()最终会破坏它。
示例代码:
//expected result - saved in database without wp_insert_post_data (see above)
<!-- wp:uagb/faq {"block_id":"f1ad85bc","enableSchemaSupport":true,"schema":"{\\u0022@context\\u0022:\\u0022https://schema.org\\u0022,\\u0022@type\\u0022:\\u0022FAQPage\\u0022,\\u0022@id\\u0022:\\u0022http://localhost/specials/gutenberg/\\u0022,\\u0022mainEntity\\u0022:[{\\u0022@type\\u0022:\\u0022Question\\u0022,\\u0022name\\u0022:\\u0022Headline with special characters: (°C, ä, ö, ü, ß, Ö, Ä, Ü)\\u0022,\\u0022acceptedAnswer\\u0022:{\\u0022@type\\u0022:\\u0022Answer\\u0022,\\u0022text\\u0022:\\u0022This is a test with special characters: (°C, ä, ö, ü, ß, Ö, Ä, Ü)\\u0022}}]}"} -->
<div class="wp-block-uagb-faq uagb-faq__outer-wrap uagb-block-f1ad85bc uagb-faq-icon-row uagb-faq-layout-accordion uagb-faq-expand-first-false uagb-faq-inactive-other-true uagb-faq-equal-height" data-faqtoggle="true" role="tablist"><script type="application/ld+json">{"@context":"https://schema.org","@type":"FAQPage","@id":"http://localhost/specials/gutenberg/","mainEntity":[{"@type":"Question","name":"Headline with special characters: (°C, ä, ö, ü, ß, Ö, Ä, Ü)","acceptedAnswer":{"@type":"Answer","text":"This is a test with special characters: (°C, ä, ö, ü, ß, Ö, Ä, Ü)"}}]}</script><div class="uagb-faq__wrap uagb-buttons-layout-wrap"><!-- wp:uagb/faq-child {"block_id":"61cac9b0","question":"Headline with special characters: (°C, ä, ö, ü, ß, Ö, Ä, Ü)","answer":"This is a test with special characters: (°C, ä, ö, ü, ß, Ö, Ä, Ü)"} -->
<div class="wp-block-uagb-faq-child uagb-faq-child__outer-wrap uagb-block-61cac9b0"><div class="uagb-faq-child__wrapper"><div class="uagb-faq-item" role="tab" tabindex="0"><div class="uagb-faq-questions-button uagb-faq-questions"><span class="uagb-icon uagb-faq-icon-wrap"><svg xmlns="http://www.w3.org/2000/svg" viewbox="0 0 448 512"><path d="M416 208H272V64c0-17.67-14.33-32-32-32h-32c-17.67 0-32 14.33-32 32v144H32c-17.67 0-32 14.33-32 32v32c0 17.67 14.33 32 32 32h144v144c0 17.67 14.33 32 32 32h32c17.67 0 32-14.33 32-32V304h144c17.67 0 32-14.33 32-32v-32c0-17.67-14.33-32-32-32z"></path></svg></span><span class="uagb-icon-active uagb-faq-icon-wrap"><svg xmlns="http://www.w3.org/2000/svg" viewbox="0 0 448 512"><path d="M416 208H32c-17.67 0-32 14.33-32 32v32c0 17.67 14.33 32 32 32h384c17.67 0 32-14.33 32-32v-32c0-17.67-14.33-32-32-32z"></path></svg></span><span class="uagb-question">Headline with special characters: (°C, ä, ö, ü, ß, Ö, Ä, Ü)</span></div><div class="uagb-faq-content"><span><p>This is a test with special characters: (°C, ä, ö, ü, ß, Ö, Ä, Ü)</p></span></div></div></div></div>
<!-- /wp:uagb/faq-child --></div></div>
<!-- /wp:uagb/faq -->
<!-- wp:kadence/iconlist {"items":[{"icon":"fe_alertCircle","link":"","target":"_self","size":20,"width":2,"text":"This is a test with special characters: (°C, ä, ö, ü, ß, Ö, Ä, Ü)","color":"","background":"","border":"","borderRadius":0,"padding":5,"borderWidth":1,"style":"default"}],"uniqueID":"_a79c18-e7"} -->
<div class="wp-block-kadence-iconlist kt-svg-icon-list-items kt-svg-icon-list-items_a79c18-e7 kt-svg-icon-list-columns-1 alignnone"><ul class="kt-svg-icon-list"><li class="kt-svg-icon-list-style-default kt-svg-icon-list-item-wrap kt-svg-icon-list-item-0"><div style="display:inline-flex;justify-content:center;align-items:center" class="kt-svg-icon-list-single kt-svg-icon-list-single-fe_alertCircle"><svg style="display:inline-block;vertical-align:middle" viewbox="0 0 24 24" height="20" width="20" fill="none" stroke="currentColor" xmlns="http://www.w3.org/2000/svg" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"></circle><line x1="12" y1="8" x2="12" y2="12"></line><line x1="12" y1="16" x2="12" y2="16"></line></svg></div><span class="kt-svg-icon-list-text">This is a test with special characters: (°C, ä, ö, ü, ß, Ö, Ä, Ü)</span></li></ul></div>
<!-- /wp:kadence/iconlist -->
调试:
//result of $data[\'post_content\']
<!-- wp:uagb/faq {\\\\"block_id\\\\":\\\\"f1ad85bc\\\\",\\\\"enableSchemaSupport\\\\":true,\\\\"schema\\\\":\\\\"{\\\\\\\\u0022@context\\\\\\\\u0022:\\\\\\\\u0022https://schema.org\\\\\\\\u0022,\\\\\\\\u0022@type\\\\\\\\u0022:\\\\\\\\u0022FAQPage\\\\\\\\u0022,\\\\\\\\u0022@id\\\\\\\\u0022:\\\\\\\\u0022http://localhost/specials/gutenberg/\\\\\\\\u0022,\\\\\\\\u0022mainEntity\\\\\\\\u0022:[{\\\\\\\\u0022@type\\\\\\\\u0022:\\\\\\\\u0022Question\\\\\\\\u0022,\\\\\\\\u0022name\\\\\\\\u0022:\\\\\\\\u0022Headline with special characters: (°C, ä, ö, ü, ß, Ö, Ä, Ü)\\\\\\\\u0022,\\\\\\\\u0022acceptedAnswer\\\\\\\\u0022:{\\\\\\\\u0022@type\\\\\\\\u0022:\\\\\\\\u0022Answer\\\\\\\\u0022,\\\\\\\\u0022text\\\\\\\\u0022:\\\\\\\\u0022This is a test with special characters: (°C, ä, ö, ü, ß, Ö, Ä, Ü)\\\\\\\\u0022}}]}\\\\"} -->
<div class=\\\\"wp-block-uagb-faq uagb-faq__outer-wrap uagb-block-f1ad85bc uagb-faq-icon-row uagb-faq-layout-accordion uagb-faq-expand-first-false uagb-faq-inactive-other-true uagb-faq-equal-height\\\\" data-faqtoggle=\\\\"true\\\\" role=\\\\"tablist\\\\"><script type=\\\\"application/ld+json\\\\">{\\\\"@context\\\\":\\\\"https://schema.org\\\\",\\\\"@type\\\\":\\\\"FAQPage\\\\",\\\\"@id\\\\":\\\\"http://localhost/specials/gutenberg/\\\\",\\\\"mainEntity\\\\":[{\\\\"@type\\\\":\\\\"Question\\\\",\\\\"name\\\\":\\\\"Headline with special characters: (°C, ä, ö, ü, ß, Ö, Ä, Ü)\\\\",\\\\"acceptedAnswer\\\\":{\\\\"@type\\\\":\\\\"Answer\\\\",\\\\"text\\\\":\\\\"This is a test with special characters: (°C, ä, ö, ü, ß, Ö, Ä, Ü)\\\\"}}]}</script><div class=\\\\"uagb-faq__wrap uagb-buttons-layout-wrap\\\\"><!-- wp:uagb/faq-child {\\\\"block_id\\\\":\\\\"61cac9b0\\\\",\\\\"question\\\\":\\\\"Headline with special characters: (°C, ä, ö, ü, ß, Ö, Ä, Ü)\\\\",\\\\"answer\\\\":\\\\"This is a test with special characters: (°C, ä, ö, ü, ß, Ö, Ä, Ü)\\\\"} -->
<div class=\\\\"wp-block-uagb-faq-child uagb-faq-child__outer-wrap uagb-block-61cac9b0\\\\"><div class=\\\\"uagb-faq-child__wrapper\\\\"><div class=\\\\"uagb-faq-item\\\\" role=\\\\"tab\\\\" tabindex=\\\\"0\\\\"><div class=\\\\"uagb-faq-questions-button uagb-faq-questions\\\\"><span class=\\\\"uagb-icon uagb-faq-icon-wrap\\\\"><svg xmlns=\\\\"http://www.w3.org/2000/svg\\\\" viewbox=\\\\"0 0 448 512\\\\"><path d=\\\\"M416 208H272V64c0-17.67-14.33-32-32-32h-32c-17.67 0-32 14.33-32 32v144H32c-17.67 0-32 14.33-32 32v32c0 17.67 14.33 32 32 32h144v144c0 17.67 14.33 32 32 32h32c17.67 0 32-14.33 32-32V304h144c17.67 0 32-14.33 32-32v-32c0-17.67-14.33-32-32-32z\\\\"></path></svg></span><span class=\\\\"uagb-icon-active uagb-faq-icon-wrap\\\\"><svg xmlns=\\\\"http://www.w3.org/2000/svg\\\\" viewbox=\\\\"0 0 448 512\\\\"><path d=\\\\"M416 208H32c-17.67 0-32 14.33-32 32v32c0 17.67 14.33 32 32 32h384c17.67 0 32-14.33 32-32v-32c0-17.67-14.33-32-32-32z\\\\"></path></svg></span><span class=\\\\"uagb-question\\\\">Headline with special characters: (°C, ä, ö, ü, ß, Ö, Ä, Ü)</span></div><div class=\\\\"uagb-faq-content\\\\"><span><p>This is a test with special characters: (°C, ä, ö, ü, ß, Ö, Ä, Ü)</p></span></div></div></div></div>
<!-- /wp:uagb/faq-child --></div></div>
<!-- /wp:uagb/faq -->
<!-- wp:kadence/iconlist {\\\\"items\\\\":[{\\\\"icon\\\\":\\\\"fe_alertCircle\\\\",\\\\"link\\\\":\\\\"\\\\",\\\\"target\\\\":\\\\"_self\\\\",\\\\"size\\\\":20,\\\\"width\\\\":2,\\\\"text\\\\":\\\\"This is a test with special characters: (°C, ä, ö, ü, ß, Ö, Ä, Ü)\\\\",\\\\"color\\\\":\\\\"\\\\",\\\\"background\\\\":\\\\"\\\\",\\\\"border\\\\":\\\\"\\\\",\\\\"borderRadius\\\\":0,\\\\"padding\\\\":5,\\\\"borderWidth\\\\":1,\\\\"style\\\\":\\\\"default\\\\"}],\\\\"uniqueID\\\\":\\\\"_a79c18-e7\\\\"} -->
<div class=\\\\"wp-block-kadence-iconlist kt-svg-icon-list-items kt-svg-icon-list-items_a79c18-e7 kt-svg-icon-list-columns-1 alignnone\\\\"><ul class=\\\\"kt-svg-icon-list\\\\"><li class=\\\\"kt-svg-icon-list-style-default kt-svg-icon-list-item-wrap kt-svg-icon-list-item-0\\\\"><div style=\\\\"display:inline-flex;justify-content:center;align-items:center\\\\" class=\\\\"kt-svg-icon-list-single kt-svg-icon-list-single-fe_alertCircle\\\\"><svg style=\\\\"display:inline-block;vertical-align:middle\\\\" viewbox=\\\\"0 0 24 24\\\\" height=\\\\"20\\\\" width=\\\\"20\\\\" fill=\\\\"none\\\\" stroke=\\\\"currentColor\\\\" xmlns=\\\\"http://www.w3.org/2000/svg\\\\" stroke-width=\\\\"2\\\\" stroke-linecap=\\\\"round\\\\" stroke-linejoin=\\\\"round\\\\"><circle cx=\\\\"12\\\\" cy=\\\\"12\\\\" r=\\\\"10\\\\"></circle><line x1=\\\\"12\\\\" y1=\\\\"8\\\\" x2=\\\\"12\\\\" y2=\\\\"12\\\\"></line><line x1=\\\\"12\\\\" y1=\\\\"16\\\\" x2=\\\\"12\\\\" y2=\\\\"16\\\\"></line></svg></div><span class=\\\\"kt-svg-icon-list-text\\\\">This is a test with special characters: (°C, ä, ö, ü, ß, Ö, Ä, Ü)</span></li></ul></div>
<!-- /wp:kadence/iconlist -->
//result of $post_data
<!-- wp:uagb/faq {"block_id":"f1ad85bc","enableSchemaSupport":true,"schema":"{\\\\u0022@context\\\\u0022:\\\\u0022https://schema.org\\\\u0022,\\\\u0022@type\\\\u0022:\\\\u0022FAQPage\\\\u0022,\\\\u0022@id\\\\u0022:\\\\u0022http://localhost/specials/gutenberg/\\\\u0022,\\\\u0022mainEntity\\\\u0022:[{\\\\u0022@type\\\\u0022:\\\\u0022Question\\\\u0022,\\\\u0022name\\\\u0022:\\\\u0022Headline with special characters: (°C, ä, ö, ü, ß, Ö, Ä, Ü)\\\\u0022,\\\\u0022acceptedAnswer\\\\u0022:{\\\\u0022@type\\\\u0022:\\\\u0022Answer\\\\u0022,\\\\u0022text\\\\u0022:\\\\u0022This is a test with special characters: (°C, ä, ö, ü, ß, Ö, Ä, Ü)\\\\u0022}}]}"} -->
<div class="wp-block-uagb-faq uagb-faq__outer-wrap uagb-block-f1ad85bc uagb-faq-icon-row uagb-faq-layout-accordion uagb-faq-expand-first-false uagb-faq-inactive-other-true uagb-faq-equal-height" data-faqtoggle="true" role="tablist"><script type="application/ld+json">{"@context":"https://schema.org","@type":"FAQPage","@id":"http://localhost/specials/gutenberg/","mainEntity":[{"@type":"Question","name":"Headline with special characters: (°C, ä, ö, ü, ß, Ö, Ä, Ü)","acceptedAnswer":{"@type":"Answer","text":"This is a test with special characters: (°C, ä, ö, ü, ß, Ö, Ä, Ü)"}}]}</script><div class="uagb-faq__wrap uagb-buttons-layout-wrap"><!-- wp:uagb/faq-child {"block_id":"61cac9b0","question":"Headline with special characters: (°C, ä, ö, ü, ß, Ö, Ä, Ü)","answer":"This is a test with special characters: (°C, ä, ö, ü, ß, Ö, Ä, Ü)"} -->
<div class="wp-block-uagb-faq-child uagb-faq-child__outer-wrap uagb-block-61cac9b0"><div class="uagb-faq-child__wrapper"><div class="uagb-faq-item" role="tab" tabindex="0"><div class="uagb-faq-questions-button uagb-faq-questions"><span class="uagb-icon uagb-faq-icon-wrap"><svg xmlns="http://www.w3.org/2000/svg" viewbox="0 0 448 512"><path d="M416 208H272V64c0-17.67-14.33-32-32-32h-32c-17.67 0-32 14.33-32 32v144H32c-17.67 0-32 14.33-32 32v32c0 17.67 14.33 32 32 32h144v144c0 17.67 14.33 32 32 32h32c17.67 0 32-14.33 32-32V304h144c17.67 0 32-14.33 32-32v-32c0-17.67-14.33-32-32-32z"></path></svg></span><span class="uagb-icon-active uagb-faq-icon-wrap"><svg xmlns="http://www.w3.org/2000/svg" viewbox="0 0 448 512"><path d="M416 208H32c-17.67 0-32 14.33-32 32v32c0 17.67 14.33 32 32 32h384c17.67 0 32-14.33 32-32v-32c0-17.67-14.33-32-32-32z"></path></svg></span><span class="uagb-question">Headline with special characters: (°C, ä, ö, ü, ß, Ö, Ä, Ü)</span></div><div class="uagb-faq-content"><span><p>This is a test with special characters: (°C, ä, ö, ü, ß, Ö, Ä, Ü)</p></span></div></div></div></div>
<!-- /wp:uagb/faq-child --></div></div>
<!-- /wp:uagb/faq -->
<!-- wp:kadence/iconlist {"items":[{"icon":"fe_alertCircle","link":"","target":"_self","size":20,"width":2,"text":"This is a test with special characters: (°C, ä, ö, ü, ß, Ö, Ä, Ü)","color":"","background":"","border":"","borderRadius":0,"padding":5,"borderWidth":1,"style":"default"}],"uniqueID":"_a79c18-e7"} -->
<div class="wp-block-kadence-iconlist kt-svg-icon-list-items kt-svg-icon-list-items_a79c18-e7 kt-svg-icon-list-columns-1 alignnone"><ul class="kt-svg-icon-list"><li class="kt-svg-icon-list-style-default kt-svg-icon-list-item-wrap kt-svg-icon-list-item-0"><div style="display:inline-flex;justify-content:center;align-items:center" class="kt-svg-icon-list-single kt-svg-icon-list-single-fe_alertCircle"><svg style="display:inline-block;vertical-align:middle" viewbox="0 0 24 24" height="20" width="20" fill="none" stroke="currentColor" xmlns="http://www.w3.org/2000/svg" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"></circle><line x1="12" y1="8" x2="12" y2="12"></line><line x1="12" y1="16" x2="12" y2="16"></line></svg></div><span class="kt-svg-icon-list-text">This is a test with special characters: (°C, ä, ö, ü, ß, Ö, Ä, Ü)</span></li></ul></div>
<!-- /wp:kadence/iconlist -->
//result of $blocks
array (
0 =>
array (
\'blockName\' => \'uagb/faq\',
\'attrs\' =>
array (
\'block_id\' => \'f1ad85bc\',
\'enableSchemaSupport\' => true,
\'schema\' => \'{"@context":"https://schema.org","@type":"FAQPage","@id":"http://localhost/specials/gutenberg/","mainEntity":[{"@type":"Question","name":"Headline with special characters: (°C, ä, ö, ü, ß, Ö, Ä, Ü)","acceptedAnswer":{"@type":"Answer","text":"This is a test with special characters: (°C, ä, ö, ü, ß, Ö, Ä, Ü)"}}]}\',
),
\'innerBlocks\' =>
array (
0 =>
array (
\'blockName\' => \'uagb/faq-child\',
\'attrs\' =>
array (
\'block_id\' => \'61cac9b0\',
\'question\' => \'Headline with special characters: (°C, ä, ö, ü, ß, Ö, Ä, Ü)\',
\'answer\' => \'This is a test with special characters: (°C, ä, ö, ü, ß, Ö, Ä, Ü)\',
),
\'innerBlocks\' =>
array (
),
\'innerHTML\' => \'
<div class="wp-block-uagb-faq-child uagb-faq-child__outer-wrap uagb-block-61cac9b0"><div class="uagb-faq-child__wrapper"><div class="uagb-faq-item" role="tab" tabindex="0"><div class="uagb-faq-questions-button uagb-faq-questions"><span class="uagb-icon uagb-faq-icon-wrap"><svg xmlns="http://www.w3.org/2000/svg" viewbox="0 0 448 512"><path d="M416 208H272V64c0-17.67-14.33-32-32-32h-32c-17.67 0-32 14.33-32 32v144H32c-17.67 0-32 14.33-32 32v32c0 17.67 14.33 32 32 32h144v144c0 17.67 14.33 32 32 32h32c17.67 0 32-14.33 32-32V304h144c17.67 0 32-14.33 32-32v-32c0-17.67-14.33-32-32-32z"></path></svg></span><span class="uagb-icon-active uagb-faq-icon-wrap"><svg xmlns="http://www.w3.org/2000/svg" viewbox="0 0 448 512"><path d="M416 208H32c-17.67 0-32 14.33-32 32v32c0 17.67 14.33 32 32 32h384c17.67 0 32-14.33 32-32v-32c0-17.67-14.33-32-32-32z"></path></svg></span><span class="uagb-question">Headline with special characters: (°C, ä, ö, ü, ß, Ö, Ä, Ü)</span></div><div class="uagb-faq-content"><span><p>This is a test with special characters: (°C, ä, ö, ü, ß, Ö, Ä, Ü)</p></span></div></div></div></div>
\',
\'innerContent\' =>
array (
0 => \'
<div class="wp-block-uagb-faq-child uagb-faq-child__outer-wrap uagb-block-61cac9b0"><div class="uagb-faq-child__wrapper"><div class="uagb-faq-item" role="tab" tabindex="0"><div class="uagb-faq-questions-button uagb-faq-questions"><span class="uagb-icon uagb-faq-icon-wrap"><svg xmlns="http://www.w3.org/2000/svg" viewbox="0 0 448 512"><path d="M416 208H272V64c0-17.67-14.33-32-32-32h-32c-17.67 0-32 14.33-32 32v144H32c-17.67 0-32 14.33-32 32v32c0 17.67 14.33 32 32 32h144v144c0 17.67 14.33 32 32 32h32c17.67 0 32-14.33 32-32V304h144c17.67 0 32-14.33 32-32v-32c0-17.67-14.33-32-32-32z"></path></svg></span><span class="uagb-icon-active uagb-faq-icon-wrap"><svg xmlns="http://www.w3.org/2000/svg" viewbox="0 0 448 512"><path d="M416 208H32c-17.67 0-32 14.33-32 32v32c0 17.67 14.33 32 32 32h384c17.67 0 32-14.33 32-32v-32c0-17.67-14.33-32-32-32z"></path></svg></span><span class="uagb-question">Headline with special characters: (°C, ä, ö, ü, ß, Ö, Ä, Ü)</span></div><div class="uagb-faq-content"><span><p>This is a test with special characters: (°C, ä, ö, ü, ß, Ö, Ä, Ü)</p></span></div></div></div></div>
\',
),
),
),
\'innerHTML\' => \'
<div class="wp-block-uagb-faq uagb-faq__outer-wrap uagb-block-f1ad85bc uagb-faq-icon-row uagb-faq-layout-accordion uagb-faq-expand-first-false uagb-faq-inactive-other-true uagb-faq-equal-height" data-faqtoggle="true" role="tablist"><script type="application/ld+json">{"@context":"https://schema.org","@type":"FAQPage","@id":"http://localhost/specials/gutenberg/","mainEntity":[{"@type":"Question","name":"Headline with special characters: (°C, ä, ö, ü, ß, Ö, Ä, Ü)","acceptedAnswer":{"@type":"Answer","text":"This is a test with special characters: (°C, ä, ö, ü, ß, Ö, Ä, Ü)"}}]}</script><div class="uagb-faq__wrap uagb-buttons-layout-wrap"></div></div>
\',
\'innerContent\' =>
array (
0 => \'
<div class="wp-block-uagb-faq uagb-faq__outer-wrap uagb-block-f1ad85bc uagb-faq-icon-row uagb-faq-layout-accordion uagb-faq-expand-first-false uagb-faq-inactive-other-true uagb-faq-equal-height" data-faqtoggle="true" role="tablist"><script type="application/ld+json">{"@context":"https://schema.org","@type":"FAQPage","@id":"http://localhost/specials/gutenberg/","mainEntity":[{"@type":"Question","name":"Headline with special characters: (°C, ä, ö, ü, ß, Ö, Ä, Ü)","acceptedAnswer":{"@type":"Answer","text":"This is a test with special characters: (°C, ä, ö, ü, ß, Ö, Ä, Ü)"}}]}</script><div class="uagb-faq__wrap uagb-buttons-layout-wrap">\',
1 => NULL,
2 => \'</div></div>
\',
),
),
1 =>
array (
\'blockName\' => NULL,
\'attrs\' =>
array (
),
\'innerBlocks\' =>
array (
),
\'innerHTML\' => \'
\',
\'innerContent\' =>
array (
0 => \'
\',
),
),
2 =>
array (
\'blockName\' => \'kadence/iconlist\',
\'attrs\' =>
array (
\'items\' =>
array (
0 =>
array (
\'icon\' => \'fe_alertCircle\',
\'link\' => \'\',
\'target\' => \'_self\',
\'size\' => 20,
\'width\' => 2,
\'text\' => \'This is a test with special characters: (°C, ä, ö, ü, ß, Ö, Ä, Ü)\',
\'color\' => \'\',
\'background\' => \'\',
\'border\' => \'\',
\'borderRadius\' => 0,
\'padding\' => 5,
\'borderWidth\' => 1,
\'style\' => \'default\',
),
),
\'uniqueID\' => \'_a79c18-e7\',
),
\'innerBlocks\' =>
array (
),
\'innerHTML\' => \'
<div class="wp-block-kadence-iconlist kt-svg-icon-list-items kt-svg-icon-list-items_a79c18-e7 kt-svg-icon-list-columns-1 alignnone"><ul class="kt-svg-icon-list"><li class="kt-svg-icon-list-style-default kt-svg-icon-list-item-wrap kt-svg-icon-list-item-0"><div style="display:inline-flex;justify-content:center;align-items:center" class="kt-svg-icon-list-single kt-svg-icon-list-single-fe_alertCircle"><svg style="display:inline-block;vertical-align:middle" viewbox="0 0 24 24" height="20" width="20" fill="none" stroke="currentColor" xmlns="http://www.w3.org/2000/svg" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"></circle><line x1="12" y1="8" x2="12" y2="12"></line><line x1="12" y1="16" x2="12" y2="16"></line></svg></div><span class="kt-svg-icon-list-text">This is a test with special characters: (°C, ä, ö, ü, ß, Ö, Ä, Ü)</span></li></ul></div>
\',
\'innerContent\' =>
array (
0 => \'
<div class="wp-block-kadence-iconlist kt-svg-icon-list-items kt-svg-icon-list-items_a79c18-e7 kt-svg-icon-list-columns-1 alignnone"><ul class="kt-svg-icon-list"><li class="kt-svg-icon-list-style-default kt-svg-icon-list-item-wrap kt-svg-icon-list-item-0"><div style="display:inline-flex;justify-content:center;align-items:center" class="kt-svg-icon-list-single kt-svg-icon-list-single-fe_alertCircle"><svg style="display:inline-block;vertical-align:middle" viewbox="0 0 24 24" height="20" width="20" fill="none" stroke="currentColor" xmlns="http://www.w3.org/2000/svg" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"></circle><line x1="12" y1="8" x2="12" y2="12"></line><line x1="12" y1="16" x2="12" y2="16"></line></svg></div><span class="kt-svg-icon-list-text">This is a test with special characters: (°C, ä, ö, ü, ß, Ö, Ä, Ü)</span></li></ul></div>
\',
),
),
)
serialize\\u blocks()后的最终结果:
//result of $post_content [can not be shown in Gutenberg UI "This block contains unexpected or invalid content."]
<!-- wp:uagb/faq {"block_id":"f1ad85bc","enableSchemaSupport":true,"schema":"{\\\\u0022@context\\\\u0022:\\\\u0022https:\\\\/\\\\/schema.org\\\\u0022,\\\\u0022@type\\\\u0022:\\\\u0022FAQPage\\\\u0022,\\\\u0022@id\\\\u0022:\\\\u0022http:\\\\/\\\\/localhost\\\\/specials\\\\/gutenberg\\\\/\\\\u0022,\\\\u0022mainEntity\\\\u0022:[{\\\\u0022@type\\\\u0022:\\\\u0022Question\\\\u0022,\\\\u0022name\\\\u0022:\\\\u0022Headline with special characters: (\\\\u00b0C, \\\\u00e4, \\\\u00f6, \\\\u00fc, \\\\u00df, \\\\u00d6, \\\\u00c4, \\\\u00dc)\\\\u0022,\\\\u0022acceptedAnswer\\\\u0022:{\\\\u0022@type\\\\u0022:\\\\u0022Answer\\\\u0022,\\\\u0022text\\\\u0022:\\\\u0022This is a test with special characters: (\\\\u00b0C, \\\\u00e4, \\\\u00f6, \\\\u00fc, \\\\u00df, \\\\u00d6, \\\\u00c4, \\\\u00dc)\\\\u0022}}]}"} -->
<div class="wp-block-uagb-faq uagb-faq__outer-wrap uagb-block-f1ad85bc uagb-faq-icon-row uagb-faq-layout-accordion uagb-faq-expand-first-false uagb-faq-inactive-other-true uagb-faq-equal-height" data-faqtoggle="true" role="tablist"><script type="application/ld+json">{"@context":"https://schema.org","@type":"FAQPage","@id":"http://localhost/specials/gutenberg/","mainEntity":[{"@type":"Question","name":"Headline with special characters: (°C, ä, ö, ü, ß, Ö, Ä, Ü)","acceptedAnswer":{"@type":"Answer","text":"This is a test with special characters: (°C, ä, ö, ü, ß, Ö, Ä, Ü)"}}]}</script><div class="uagb-faq__wrap uagb-buttons-layout-wrap"><!-- wp:uagb/faq-child {"block_id":"61cac9b0","question":"Headline with special characters: (\\\\u00b0C, \\\\u00e4, \\\\u00f6, \\\\u00fc, \\\\u00df, \\\\u00d6, \\\\u00c4, \\\\u00dc)","answer":"This is a test with special characters: (\\\\u00b0C, \\\\u00e4, \\\\u00f6, \\\\u00fc, \\\\u00df, \\\\u00d6, \\\\u00c4, \\\\u00dc)"} -->
<div class="wp-block-uagb-faq-child uagb-faq-child__outer-wrap uagb-block-61cac9b0"><div class="uagb-faq-child__wrapper"><div class="uagb-faq-item" role="tab" tabindex="0"><div class="uagb-faq-questions-button uagb-faq-questions"><span class="uagb-icon uagb-faq-icon-wrap"><svg xmlns="http://www.w3.org/2000/svg" viewbox="0 0 448 512"><path d="M416 208H272V64c0-17.67-14.33-32-32-32h-32c-17.67 0-32 14.33-32 32v144H32c-17.67 0-32 14.33-32 32v32c0 17.67 14.33 32 32 32h144v144c0 17.67 14.33 32 32 32h32c17.67 0 32-14.33 32-32V304h144c17.67 0 32-14.33 32-32v-32c0-17.67-14.33-32-32-32z"></path></svg></span><span class="uagb-icon-active uagb-faq-icon-wrap"><svg xmlns="http://www.w3.org/2000/svg" viewbox="0 0 448 512"><path d="M416 208H32c-17.67 0-32 14.33-32 32v32c0 17.67 14.33 32 32 32h384c17.67 0 32-14.33 32-32v-32c0-17.67-14.33-32-32-32z"></path></svg></span><span class="uagb-question">Headline with special characters: (°C, ä, ö, ü, ß, Ö, Ä, Ü)</span></div><div class="uagb-faq-content"><span><p>This is a test with special characters: (°C, ä, ö, ü, ß, Ö, Ä, Ü)</p></span></div></div></div></div>
<!-- /wp:uagb/faq-child --></div></div>
<!-- /wp:uagb/faq -->
<!-- wp:kadence/iconlist {"items":[{"icon":"fe_alertCircle","link":"","target":"_self","size":20,"width":2,"text":"This is a test with special characters: (\\\\u00b0C, \\\\u00e4, \\\\u00f6, \\\\u00fc, \\\\u00df, \\\\u00d6, \\\\u00c4, \\\\u00dc)","color":"","background":"","border":"","borderRadius":0,"padding":5,"borderWidth":1,"style":"default"}],"uniqueID":"_a79c18-e7"} -->
<div class="wp-block-kadence-iconlist kt-svg-icon-list-items kt-svg-icon-list-items_a79c18-e7 kt-svg-icon-list-columns-1 alignnone"><ul class="kt-svg-icon-list"><li class="kt-svg-icon-list-style-default kt-svg-icon-list-item-wrap kt-svg-icon-list-item-0"><div style="display:inline-flex;justify-content:center;align-items:center" class="kt-svg-icon-list-single kt-svg-icon-list-single-fe_alertCircle"><svg style="display:inline-block;vertical-align:middle" viewbox="0 0 24 24" height="20" width="20" fill="none" stroke="currentColor" xmlns="http://www.w3.org/2000/svg" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"></circle><line x1="12" y1="8" x2="12" y2="12"></line><line x1="12" y1="16" x2="12" y2="16"></line></svg></div><span class="kt-svg-icon-list-text">This is a test with special characters: (°C, ä, ö, ü, ß, Ö, Ä, Ü)</span></li></ul></div>
<!-- /wp:kadence/iconlist -->
相关主题:
serialize_blocks breaking html tags in content