Check if it exists before replacing the "[site_url]" or "[site_url_secur...

Added " && preg_match("/\[site_url(_url_secure)?\]/", $value)"
This will decrease the execution time, because str_replace is time consuming function, so if there are a lot Options to go through it will take a while.