Support

Account

Home Forums General Issues Text custom field that contain text like control symbols

Solved

Text custom field that contain text like control symbols

  • Hi!

    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.

  • I just did a test and this is not happening on my installation. At a guess I’d say that it has something to do with the database table, possibly the character set.

  • 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.

  • Another thought struck me after I posted… maybe it has something to do with the language setting you’re using for WP.

  • Ok. Thanks.
    I will write here the solution of the problem in future.

  • 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:

    [domen]\wp-content\plugins\advanced-custom-fields\core\fields\_functions.php

    on the 181 row the function update_value( $value, $post_id, $field ) un-shielded my string: $value = stripslashes_deep($value);

    Screenshot: http://prntscr.com/ao66r9

    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.

  • Try adding this to functions.php, though I’m not sure of what other side effects this may have.

    
    add_filter('acf/settings/stripslashes', '__return_false');
    
  • 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

  • Thanks, John!

    In future, I going to use ACF 5 Pro.

Viewing 12 posts - 1 through 12 (of 12 total)

The topic ‘Text custom field that contain text like control symbols’ is closed to new replies.