Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin
Created June 14, 2018 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tommcfarlin/590bbb593f01fe95ce0b11106e7e86cb to your computer and use it in GitHub Desktop.
Save tommcfarlin/590bbb593f01fe95ce0b11106e7e86cb to your computer and use it in GitHub Desktop.
[WordPress][PHP] Sanitizing URLs in WordPress with Its API and PHP
<?php
$data['url'] = 'https://tommcfarlin.com/<script type="text/javascript">alert(\'hello world!\');</script>';
<?php
if (!isset($data['url']) {
return '';
}
$url = $data['url'];
$data['url'] = strip_tags(
stripslashes(
filter_var($url, FILTER_VALIDATE_URL)
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment