Created
December 18, 2015 13:22
-
-
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
This file contains hidden or 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 | |
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