#41579 closed defect (bug) (invalid)
Post_content / meta value unable to store slashed content
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Posts, Post Types | Keywords: | |
Focuses: | Cc: |
Description
Hi there,
In my plugin I'm storing data from another service. This service returns regex data on how some fields are getting validated.
When saving these values to either post_content or a post meta the values are getting slashed. I could save these are options but due to it being specific to a post_type this does not make sense.
To test:
$regex = '(\b16-\d{3}\b)'; $post_id = wp_insert_post( [ 'post_title' => 'Test regex', 'post_content' => $regex, 'post_type' => 'post', ] ); var_dump($regex); echo '<br>'; var_dump( get_post($post_id )->post_content ); die();
Output:
string(14) "(\b16-\d{3}\b)" string(11) "(b16-d{3}b)"
It seems like there is no way of skipping the current API from slashing the values with wp_unslash.
Change History (3)
Note: See
TracTickets for help on using
tickets.
Hello @Compute,
by default
wp_insert_post()
doesn't add slashes to the post data because it expects the data already to be slashed. Before the data gets stored into the databasewp_unslash()
is called. That's why the slashes from the regex are removed.To solve this you have to call
wp_slash()
on your$regex
first.