{
"sections": [
{
"section_name": "Objective",
"data": "<span style=\\"font-weight: bold;\\">Test</span>",
"key": "ref"
}
]
}
我正在通过wp\\u update\\u post将上述JSON数据更新为纯文本
data = <<<EOD
{"sections":[{"section_name":"Objective","data":"<span style=\\"font-weight: bold;\\">Test</span>","key":"ref"}]}
EOD;
$new = array(
\'post_title\' => $title,
\'post_content\' => $data,
\'post_author\' => $userid,
\'post_status\' => \'pending\',
\'post_type\' => \'post\'
);
$id = wp_insert_post($new );
数据的保存方式与仅在“管理员”登录时使用转义斜杠传递的数据完全相同。
对于所有其他用户类型,例如“subscriber”,斜杠在保存时会自动删除。这使得JSON无效。
如何为所有用户类型保存准确传递的数据?
SO网友:Jagan K
我通过将unfiltered\\u html设置为true来创建一个新的用户类型,从而解决了这个问题
$result = add_role(
\'jobseeker\',
__( \'Job Seeker\' ),
array(
\'read\' => true,
\'edit_posts\' => true,
\'delete_posts\' => true,
\'delete_published_posts\' => true,
\'upload_files\' => true,
\'edit_others_posts\' => false,
\'delete_others_posts\' => false,
\'unfiltered_html\' => true, //this line does the magic
)
);
if ( null !== $result ) {
echo \'Yay! New role created!\';
}
else {
echo \'Oh... the basic_contributor role already exists.\';
}