Skip to content

Instantly share code, notes, and snippets.

@jchristopher
Created December 18, 2015 13:22
Show Gist options
  • Save jchristopher/a7e2693d72bfe2f1aac4 to your computer and use it in GitHub Desktop.
Save jchristopher/a7e2693d72bfe2f1aac4 to your computer and use it in GitHub Desktop.
SearchWP Regex Whitelist modification to allow strings with letters, numbers, hyphens, underscores, and periods
<?php
function my_searchwp_term_pattern_whitelist( $whitelist ) {
$my_whitelist = array(
"/(\\b[-_.]?[0-9a-zA-Z]+(?:[-_.]+[0-9a-zA-Z]+)+[-_.]?)/iu", // strings with letters, numbers, hyphens, underscores, and periods (no spaces)
);
// we want our pattern to be considered the most specific
// so that false positive matches do not interfere
$whitelist = array_merge( $my_whitelist, $whitelist );
return $whitelist;
}
add_filter( 'searchwp_term_pattern_whitelist', 'my_searchwp_term_pattern_whitelist' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment