0
{
  "sections": [
    {
      "section_name": "Objective",
      "data": "<span style=\"font-weight: bold;\">Test</span>",
      "key": "ref"
    }
  ]
}

I am updating the above JSON data as plain text through wp_update_post

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 );

The data is saved exactly like it passed with escaped slashes only on "Administrator" login.

On all other user types, for ex "subscriber", the slashes are automatically stripped when saved. which makes it invalid JSON.

How to save the exact passed data for all user types?

0

I solved this problem by creating a new user type with unfiltered_html set to 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.';
}
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.