MrFacundo
MrFacundo

Reputation: 176

Wordpress text editor input validation. Prevent save when certain characters are used on input

I'm trying to create a function on my theme's functions.php file that accomplishes that goal.

I want the editor to prevent saving or updating new posts when certain characters are used on the editor. Characters like non-breaking space, certain brackets and aposthrophes and encoded html entities.

I've managed to create a function to sanitize the input after the post was saved to the database, getting rid of all these undesired characters. I did this by writing a function that includes

$wpdb->update('wp_posts', ['post_excerpt' =>$sanitized_post_excerpt], ['id' => $post_id]);

and then adding the function as a hook to save_post:

add_action('save_post', 'sm_sanitize_HTML_entities', 99, 3);

Is there a way to prevent the input of the characters being saved (maybe even displaying a message to the user), rather than updating a sanitized version of the data after it's already been saved?

Upvotes: 0

Views: 119

Answers (1)

user20479463
user20479463

Reputation: 11

What da butt? enter code here

Blockquo [enter link description here][1]

Olá [1]: https://%20xpt.

Upvotes: 1

Related Questions