-
-
Save tommcfarlin/590bbb593f01fe95ce0b11106e7e86cb to your computer and use it in GitHub Desktop.
[WordPress][PHP] Sanitizing URLs in WordPress with Its API and PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$data['url'] = 'https://tommcfarlin.com/<script type="text/javascript">alert(\'hello world!\');</script>'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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