Stripping URLs & Email from post submissions

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

Leave a Reply

Your email address will not be published. Required fields are marked *