Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/wp-rocket/inc/functions/api.php
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
<?php
2
+
3
+
/**
4
+
* Get an URL with one of CNAMES added in options
5
+
*
6
+
* @since 2.1
7
+
*
8
+
* @param string $url The URL to parse.
9
+
* @param array $zone (default: array( 'all' )). Deprecated.
10
+
* @return string
11
+
*/
12
+
function get_rocket_cdn_url( $url, $zone = [ 'all' ] ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals, Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
13
+
$container = apply_filters( 'rocket_container', '' );
14
+
$cdn = $container->get( 'cdn' );
15
+
16
+
return $cdn->rewrite_url( $url );
17
+
}
18
+
19
+
/**
20
+
* Wrapper of get_rocket_cdn_url() and print result
21
+
*
22
+
* @since 2.1
23
+
*
24
+
* @param string $url The URL to parse.
25
+
* @param array $zone (default: array( 'all' )). Deprecated.
26
+
*/
27
+
function rocket_cdn_url( $url, $zone = [ 'all' ] ) {
28
+
echo esc_url( get_rocket_cdn_url( $url, $zone ) );
29
+
}
30
+
31
+
/**
32
+
* Get all CNAMES.
33
+
*
34
+
* @since 2.1
35
+
* @since 3.0 Don't check for WP Rocket CDN option activated to be able to use the function on Hosting with CDN auto-enabled.
36
+
*
37
+
* @param string $zone List of zones. Default is 'all'.
38
+
* @return array List of CNAMES
39
+
*/
40
+
function get_rocket_cdn_cnames( $zone = 'all' ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
41
+
$hosts = [];
42
+
$cnames = get_rocket_option( 'cdn_cnames', [] );
43
+
44
+
if ( $cnames ) {
45
+
$cnames_zone = get_rocket_option( 'cdn_zone', [] );
46
+
$zone = (array) $zone;
47
+
48
+
foreach ( $cnames as $k => $_urls ) {
49
+
if ( ! in_array( $cnames_zone[ $k ], $zone, true ) ) {
50
+
continue;
51
+
}
52
+
53
+
$_urls = explode( ',', $_urls );
54
+
$_urls = array_map( 'trim', $_urls );
55
+
56
+
foreach ( $_urls as $url ) {
57
+
$hosts[] = $url;
58
+
}
59
+
}
60
+
}
61
+
62
+
/**
63
+
* Filter all CNAMES.
64
+
*
65
+
* @since 2.7
66
+
*
67
+
* @param array $hosts List of CNAMES.
68
+
* @param array $zone Array of CDN zones.
69
+
*/
70
+
$hosts = (array) apply_filters( 'rocket_cdn_cnames', $hosts, $zone );
71
+
$hosts = array_filter( $hosts );
72
+
$hosts = array_flip( array_flip( $hosts ) );
73
+
$hosts = array_values( $hosts );
74
+
75
+
return $hosts;
76
+
}
77
+
78
+
/**
79
+
* Check if the current URL is for a live site (not local, not staging).
80
+
*
81
+
* @since 3.5
82
+
* @author Remy Perona
83
+
*
84
+
* @return bool True if live, false otherwise.
85
+
*/
86
+
function rocket_is_live_site() {
87
+
if ( rocket_get_constant( 'WP_ROCKET_DEBUG' ) ) {
88
+
return true;
89
+
}
90
+
91
+
$host = wp_parse_url( home_url(), PHP_URL_HOST );
92
+
if ( ! $host ) {
93
+
return false;
94
+
}
95
+
96
+
// Check for local development sites.
97
+
$local_tlds = [
98
+
'127.0.0.1',
99
+
'localhost',
100
+
'.local',
101
+
'.test',
102
+
'.docksal',
103
+
'.docksal.site',
104
+
'.dev.cc',
105
+
'.lndo.site',
106
+
];
107
+
foreach ( $local_tlds as $local_tld ) {
108
+
if ( $host === $local_tld ) {
109
+
return false;
110
+
}
111
+
112
+
// Check the TLD.
113
+
if ( substr( $host, -strlen( $local_tld ) ) === $local_tld ) {
114
+
return false;
115
+
}
116
+
}
117
+
118
+
$default_staging = [];
119
+
120
+
/**
121
+
* Get the list of staging domains from SaaS
122
+
*
123
+
* @param array $default_staging default result in case there isn't.
124
+
*/
125
+
$staging = apply_filters( 'rocket_staging_list', $default_staging );
126
+
127
+
if ( ! is_array( $staging ) ) {
128
+
$staging = $default_staging;
129
+
}
130
+
131
+
foreach ( $staging as $partial_host ) {
132
+
if ( strpos( $host, $partial_host ) ) {
133
+
return false;
134
+
}
135
+
}
136
+
137
+
return true;
138
+
}
139
+
140
+
/**
141
+
* Checks if importing
142
+
*
143
+
* @return bool
144
+
*/
145
+
function rocket_is_importing() {
146
+
/**
147
+
* Filter use to determine if we are currently importing data into the WordPress.
148
+
* Bails out if this filter returns true.
149
+
*
150
+
* @param boolean Tells if we are importing or not.
151
+
*/
152
+
return (bool) apply_filters( 'rocket_is_importing', rocket_get_constant( 'WP_IMPORTING' ) );
153
+
}
154
+