Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/wp-rocket/inc/Engine/Media/Fonts/FontsTrait.php

Keine Baseline-Datei – Diff nur gegen leer.
Zur Liste
1 -
1 + <?php
2 + declare(strict_types=1);
3 +
4 + namespace WP_Rocket\Engine\Media\Fonts;
5 +
6 + trait FontsTrait {
7 +
8 + /**
9 + * Get the list of patterns to exclude from media fonts rewrite.
10 + *
11 + * @return string[]
12 + */
13 + protected function get_exclusions(): array {
14 + /**
15 + * Filters the list of patterns to exclude from media font rewrite.
16 + *
17 + * @since 3.18
18 + *
19 + * @param string[] $exclusions The list of patterns to exclude from media fonts.
20 + */
21 + return wpm_apply_filters_typed( 'string[]', 'rocket_exclude_locally_host_fonts', [] );
22 + }
23 +
24 + /**
25 + * Checks if a font is excluded based on the provided exclusions.
26 + *
27 + * @param string $subject The string to check.
28 + * @param string[] $exclusions The list of exclusions.
29 + *
30 + * @return bool True if the URL is excluded, false otherwise.
31 + */
32 + protected function is_excluded( string $subject, array $exclusions ): bool {
33 + // Bail out early if there are no exclusions.
34 + if ( empty( $exclusions ) ) {
35 + return false;
36 + }
37 +
38 + // Escape each exclusion pattern to prevent regex issues.
39 + $escaped_exclusions = array_map(
40 + function ( $exclusion ) {
41 + $query_string = preg_replace( '@(https?:)?(//)?fonts\.googleapis\.com/css2?\?@i', '', $exclusion );
42 +
43 + return str_replace(
44 + [ '#', '+', '=' ],
45 + [ '\#', '\+', '\=' ],
46 + $query_string
47 + );
48 + },
49 + $exclusions
50 + );
51 +
52 + // Combine all patterns into a single regex string.
53 + $exclusions_str = implode( '|', $escaped_exclusions );
54 +
55 + // Check the URL against the combined regex pattern.
56 + return (bool) preg_match( '#(' . $exclusions_str . ')#i', $subject );
57 + }
58 + }
59 +