forked from Sophia/better-yourls-blacklist-domains
Add possible regex handling
This commit is contained in:
17
plugin.php
17
plugin.php
@@ -45,10 +45,17 @@ function better_blacklist_domain_check( $shunt, $url ) {
|
||||
$blacklisted_domains = unserialize( $blacklisted_domains );
|
||||
|
||||
foreach ( $blacklisted_domains as $blacklisted_domain ) {
|
||||
// Use a regex to match the domain or subdomain
|
||||
$pattern = '/(?:^|\.)' . preg_quote( $blacklisted_domain, '/' ) . '$/i';
|
||||
if ( preg_match( $pattern, $domain ) ) {
|
||||
return blacklist_fail_response();
|
||||
// Check if the entry starts with '/', then consider regex handling
|
||||
if (strpos($blacklisted_domain, '/') === 0) {
|
||||
if (@preg_match($blacklisted_domain, $domain)) {
|
||||
return blacklist_fail_response();
|
||||
}
|
||||
} else {
|
||||
// Otherwise treat as plain domain (old behavior)
|
||||
$pattern = '/(?:^|\.)' . preg_quote( $blacklisted_domain, '/' ) . '$/i';
|
||||
if ( preg_match( $pattern, $domain ) ) {
|
||||
return blacklist_fail_response();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -126,4 +133,4 @@ function better_blacklist_process_form() {
|
||||
}
|
||||
echo "</ul>";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user