I am trying to write a short plugin that will filter html characters from the search form. In the event someone enters in <script>alert('some infectious js!');</script>
into the search form i want to remove the possibility of this command to be entered into the search form.
I tried this:
function SearchFilter( $query ) {
if ( is_search() ) {
$query = strip_tags($query);
return;
}
}
add_action ('pre_get_posts', 'SearchFilter');
When I go to test it, i enter <script>alert('some infectious js!');</script>
above into the search field and all I get is a blank white page in wordpress. The search still works but anytime i type in script it breaks the box. This seems odd that wordpress doesn't handle this by default OR am i totally wrong on this?
Thanks in advance.