I want to prevent users posting in this instance of WordPress from submitting URLs and Emails in posts.

I’m trying to do it via Regex but I’m not sure if I’m writing the Regex incorrectly because it doesn’t seem to be stripping any URLs (haven’t written the one for emails yet). Can anyone spot what I’m doing wrong:

function censor_links( $content ) {
return preg_replace( '/^(https?://)?([da-z.-]+).([a-z.]{2,6})([/w .-]*)*/?$/', '[LINK NOT SHOWN]', $content );
add_filter( 'the_content', 'censor_links' );

Should I be using a filter on save_post or something else?

Read more here: Stripping URLs & Email from post submissions


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: