PluginProbe
Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization / trunk
Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization vtrunk
4.2.14 4.2.13 4.2.12 4.2.11 4.2.10 4.2.9 4.2.8 4.2.7 4.2.6 4.2.5 2.5.5 2.5.6 2.5.7 3.0.0 3.0.1 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.11.0 3.11.1 3.11.2 3.11.3 3.12.0 All 135 releases
← All changes | inc/filters.php +29 -10 2.5.5 → trunk View file →
@@ -10,22 +10,42 @@
10 10
11 11 /**
12 12 * Generic method to check if the page is allowed to do the action.
13 13 *
14 - * @param array $flags Flags array.
15 - *
14 + * @param array $contains_flags Contains flags array.
15 + * @param array $match_flags Exact path match flags array.
16 16 * @return bool Should do action on page?
17 17 */
18 - public static function should_do_page( $flags ) {
18 + public static function should_do_page( $contains_flags, $match_flags ) {
19 +
20 + if ( empty( $contains_flags ) && empty( $match_flags ) ) {
21 + return true;
22 + }
23 +
19 24 if ( ! isset( $_SERVER['REQUEST_URI'] ) ) {
20 25 return true;
21 26 }
22 - foreach ( $flags as $rule_flag => $status ) {
23 - if ( strpos( $_SERVER['REQUEST_URI'], $rule_flag ) !== false ) {
24 - return false;
27 +
28 + $check_against = [ $_SERVER['REQUEST_URI'] ];
29 + // This code is designed to handle ajax requests on pages that are excluded.
30 + // For ajax requests, the referer is set to the page URL and they use a POST method.
31 + // If an ajax request uses a GET method, it can be managed using the available exclusion rules.
32 + if ( isset( $_SERVER['HTTP_REFERER'] ) && $_SERVER['REQUEST_METHOD'] === 'POST' ) {
33 + $check_against[] = $_SERVER['HTTP_REFERER'];
34 + }
35 + foreach ( $check_against as $check ) {
36 + foreach ( $match_flags as $rule_flag => $status ) {
37 + if ( $rule_flag === $check ) {
38 + return false;
39 + }
25 40 }
26 - if ( $rule_flag === 'home' && ( empty( $_SERVER['REQUEST_URI'] ) || $_SERVER['REQUEST_URI'] === '/' ) ) {
27 - return false;
41 + foreach ( $contains_flags as $rule_flag => $status ) {
42 + if ( strpos( $check, $rule_flag ) !== false ) {
43 + return false;
44 + }
45 + if ( $rule_flag === 'home' && ( empty( $check ) || $check === '/' ) ) {
46 + return false;
47 + }
28 48 }
29 49 }
30 50
31 51 return true;
@@ -47,9 +67,8 @@
47 67 }
48 68 }
49 69
50 70 return true;
51 -
52 71 }
53 72
54 73 /**
55 74 *
@@ -57,9 +76,9 @@
57 76 *
58 77 * @param array $flags Flags array.
59 78 * @param string $ext Extension string.
60 79 *
61 - * @return bool Should we do the processing?
80 + * @return bool|string Should we do the processing?
62 81 */
63 82 public static function should_do_extension( $flags, $ext ) {
64 83 foreach ( $flags as $rule_flag => $status ) {
65 84 if ( $rule_flag === $ext ) {