WordPress text editor input validation. Prevent save when certain characters are
-
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?
The topic ‘WordPress text editor input validation. Prevent save when certain characters are’ is closed to new replies.