Skip to content

Commit fbecc6e

Browse files
authored
Merge pull request #526 from Codeinwp/fix/437
chore: checking http_referer on page exclusions #437
2 parents ff92235 + e86474a commit fbecc6e

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

inc/filters.php

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,32 @@ final class Optml_Filters {
1616
* @return bool Should do action on page?
1717
*/
1818
public static function should_do_page( $contains_flags, $match_flags ) {
19+
20+
if ( empty( $contains_flags ) && empty( $match_flags ) ) {
21+
return true;
22+
}
23+
1924
if ( ! isset( $_SERVER['REQUEST_URI'] ) ) {
2025
return true;
2126
}
2227

23-
foreach ( $match_flags as $rule_flag => $status ) {
24-
if ( $rule_flag === $_SERVER['REQUEST_URI'] ) {
25-
return false;
26-
}
28+
$check_against = [ $_SERVER['REQUEST_URI'] ];
29+
if ( isset( $_SERVER['HTTP_REFERER'] ) ) {
30+
$check_against[] = $_SERVER['HTTP_REFERER'];
2731
}
28-
foreach ( $contains_flags as $rule_flag => $status ) {
29-
if ( strpos( $_SERVER['REQUEST_URI'], $rule_flag ) !== false ) {
30-
return false;
32+
foreach ( $check_against as $check ) {
33+
foreach ( $match_flags as $rule_flag => $status ) {
34+
if ( $rule_flag === $check ) {
35+
return false;
36+
}
3137
}
32-
if ( $rule_flag === 'home' && ( empty( $_SERVER['REQUEST_URI'] ) || $_SERVER['REQUEST_URI'] === '/' ) ) {
33-
return false;
38+
foreach ( $contains_flags as $rule_flag => $status ) {
39+
if ( strpos( $check, $rule_flag ) !== false ) {
40+
return false;
41+
}
42+
if ( $rule_flag === 'home' && ( empty( $check ) || $check === '/' ) ) {
43+
return false;
44+
}
3445
}
3546
}
3647

0 commit comments

Comments
 (0)