CheckExcludedTrait.php
1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
namespace WP_Rocket\Engine\Preload\Controller;
trait CheckExcludedTrait {
/**
* Add new pattern of excluded uri.
*
* @param array $regexes regexes used to exclude urls.
* @return array
*/
public function add_cache_reject_uri_to_excluded( array $regexes ): array {
$regexes[] = get_rocket_cache_reject_uri();
return $regexes;
}
/**
* Check if the url is excluded by using a filter.
*
* @param string $url url to check.
* @return bool
*/
protected function is_excluded_by_filter( string $url ): bool {
/**
* Regex to exclude URI from preload.
*
* @param string[] regexes to check
*/
$regexes = (array) apply_filters( 'rocket_preload_exclude_urls', [] );
if ( empty( $regexes ) ) {
return false;
}
$regexes = array_unique( $regexes );
$url = user_trailingslashit( $url );
foreach ( $regexes as $regex ) {
if ( ! is_string( $regex ) ) {
continue;
}
$regex = user_trailingslashit( $regex );
if ( preg_match( "@$regex$@m", $url ) ) {
return true;
}
}
return false;
}
}