I have a post of post_type = dog. It contains a ACF field of titles (text).
It’s an example of dog’s titles: “4xCAC, 4xCACIB, BOS, 2 BOB, 2xGrand champion of Ukraine PROCREATOR of CHAMPIONS HD-A\A ED-0\0”.
But, are you see “\A” & “\0”? Then I press “Save post” the field convert to that: http://prntscr.com/anzn3b
I don’t want it. 🙂 I need to see a just simple string with char “\”.
And now I think about other my fields… What must I do for normal use char “\” in a text field? Maybe some hook or setting?
Attention: User will be copy-paste content of some fields, therefore the decision must be automatic. It’s not instructions: «Please, write “\\” instead “\”». 🙂
I’m hope for your help.
Hmm… It’s not good news.
Maybe you can advise me? Look at please: http://prntscr.com/ao2ahp
I think I didn’t some special actions with the character set. I’m confused.
Do I understand you right? It’s not ACF-plugin. Maybe it’s WP-core?
Just advise me, please: the right direction for Google search or any tries to fix it.
P.S. Sorry about my English. 🙂
The character set is the same as mine, so that’s probably not it. There must be some type of filter running on the values before they are inserted into the database. The next step would be to narrow down what that might be by deactivating other plugins on the site and maybe even switching themes to one of the default WP themes and then doing some more testing to see if you can get it to work.
I came back! 🙂
Now I’m just one step away to the solution. So… What have we?
I wrote into the field, for example, “\0”. I pressed “Save post”. And in Debugger, I saw the string $v=”\\0″ in PHPStorm. So, some code makes my string shielded from “\0” to “\\0”. It’s good because without that we will have controls symbol.
But later in this place:
on the 181 row the function update_value( $value, $post_id, $field ) un-shielded my string: $value = stripslashes_deep($value);
I see comments about “not need” etc, but I don’t understand this very clear. Especially in regard to the possible impact on other fields. And why need we strip slashes?
Easy solution looks like: //$value = stripslashes_deep($value); But I concern about effect on other fields.
Please, help me comprehend this all. I think this will be helpful for other people.
That will not work. I just realized that you’re using ACF4 and that filter does not exist, try this
add_filter('acf/update_value', 'wp_slash', 1);
still not sure that it won’t have some other side effects, you may just want to do it for the field that’s giving you a problem.
First. Thanks for help with instructions!
Second. Yes, I was thinking about something like that. For minimizing surprises in future it’s better way:
add_filter('acf/update_value/name=titles', 'wp_slash', 1);
But it’s a typical crutch (not sure is it good English word).
Thirdly. Can you tell me clear why ACF do unshielded my strings at that place? Looks like ACF do the “bad” action there. And why put a comment with a link (I think there is the problem description, but now it’s broken). I want to understand why we need this string in ACF-code:
$value = stripslashes_deep($value);
Well, way back in the history of PHP it was necessary because the slashes added by the browser where not automatically removed. Then there was a setting called magic_quotes and you could turn it off to keep the old functionality or have it on and PHP would remove the slashes. Now there is no setting and PHP always removes them. If you’re using an older version of PHP you may still have this setting and stripslashes is a way to make sure they’re removed. Why ACF is still doing it, not really sure. If you are using an up to date version of PHP on the server then it shouldn’t be needed. If you want more information start here http://php.net/manual/en/security.magicquotes.php
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
© 2023 Advanced Custom Fields.