0

I have never come across this before and it's completely stumped me!

I am using some custom front end posting scripts in Wordpress, these work absolutely fine, everything is escaped correctly before the data is saved to the db etc, but I seem to be having an issue with the apostrophe (single quote) when entered on a Mac keyboard.

An example post using various chars is entered in the text area :

 a post with other chars `~":;?/[]{}-_=+!£$%^&*()'

And this is what is saved in the db (and then displayed on the page when called) :

 a post with other chars `~":;?/[]{}-_=+!£$%^&*()'

This is how the data is being saved to the db for clarity :

esc_attr(strip_tags($_POST['postContent'])),

If I copy and paste an apostrophe from a webpage like this for example it saves just fine :

 Ain’t that strange!

But that slanted apostrophe isn't available (as standard) on the Mac keyboard, the default is the single quote '

I have never come across this issue before.

Anybody got any suggestions or workarounds as I'm at my wits end!

Grant
  • 1,297
  • 2
  • 16
  • 39

1 Answers1

0

Ok found it..

Instead of :

 esc_attr(strip_tags($_POST['postContent'])),

Use the built in wordpress function sanitize_text_field :

 'post_content' => sanitize_text_field($_POST['postContent']),
Grant
  • 1,297
  • 2
  • 16
  • 39