Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/wp-rocket/inc/deprecated/3.5.php

Keine Baseline-Datei – Diff nur gegen leer.
Zur Liste
1 -
1 + <?php
2 + // phpcs:ignoreFile
3 +
4 + defined( 'ABSPATH' ) || exit;
5 +
6 + /**
7 + * Class aliases.
8 + */
9 + class_alias( '\WP_Rocket\Engine\Admin\Settings\Page', '\WP_Rocket\Admin\Settings\Page' );
10 + class_alias( '\WP_Rocket\Engine\Admin\Settings\Render', '\WP_Rocket\Admin\Settings\Render' );
11 + class_alias( '\WP_Rocket\Engine\Admin\Settings\Settings', '\WP_Rocket\Admin\Settings\Settings' );
12 + class_alias( '\WP_Rocket\Engine\Admin\Settings\ServiceProvider', '\WP_Rocket\ServiceProvider\Settings' );
13 + class_alias( '\WP_Rocket\Engine\Admin\Settings\Subscriber', '\WP_Rocket\Subscriber\Admin\Settings\Page_Subscriber' );
14 + class_alias( '\WP_Rocket\Engine\Optimization\GoogleFonts\Combine', '\WP_Rocket\Optimization\CSS\Combine_Google_Fonts' );
15 + class_alias( '\WP_Rocket\Engine\Optimization\GoogleFonts\Subscriber', '\WP_Rocket\Subscriber\Optimization\Combine_Google_Fonts_Subscriber' );
16 +
17 + //RocketCDN Start
18 + class_alias('\WP_Rocket\Engine\CDN\RocketCDN\AdminPageSubscriber', '\WP_Rocket\Subscriber\CDN\RocketCDN\AdminPageSubscriber');
19 + class_alias('\WP_Rocket\Engine\CDN\RocketCDN\APIClient', '\WP_Rocket\CDN\RocketCDN\APIClient');
20 + class_alias('\WP_Rocket\Engine\CDN\RocketCDN\CDNOptionsManager', '\WP_Rocket\CDN\RocketCDN\CDNOptionsManager');
21 + class_alias('\WP_Rocket\Engine\CDN\RocketCDN\DataManagerSubscriber', '\WP_Rocket\Subscriber\CDN\RocketCDN\DataManagerSubscriber');
22 + class_alias('\WP_Rocket\Engine\CDN\RocketCDN\NoticesSubscriber', '\WP_Rocket\Subscriber\CDN\RocketCDN\NoticesSubscriber');
23 + class_alias('\WP_Rocket\Engine\CDN\RocketCDN\RESTSubscriber', '\WP_Rocket\Subscriber\CDN\RocketCDN\RESTSubscriber');
24 + class_alias('\WP_Rocket\Engine\CDN\RocketCDN\ServiceProvider', '\WP_Rocket\ServiceProvider\RocketCDN');
25 + //RocketCDN End
26 +
27 + /**
28 + * Removes Minification, DNS Prefetch, LazyLoad, Defer JS when on an AMP version of a post with the AMP for WordPress plugin from Auttomatic
29 + *
30 + * @since 2.8.10 Compatibility with wp_resource_hints in WP 4.6
31 + * @since 2.7
32 + * @deprecated 3.5.2
33 + *
34 + * @author Remy Perona
35 + */
36 + function rocket_disable_options_on_amp() {
37 + _deprecated_function( __FUNCTION__ . '()', '3.5.2', '\WP_Rocket\ThirdParty\Plugins\Optimization\AMP::disable_options_on_amp()' );
38 + global $wp_filter;
39 +
40 + if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) {
41 + remove_filter( 'wp_resource_hints', 'rocket_dns_prefetch', 10, 2 );
42 + add_filter( 'do_rocket_lazyload', '__return_false' );
43 + unset( $wp_filter['rocket_buffer'] );
44 +
45 + // this filter is documented in inc/front/protocol.php.
46 + $do_rocket_protocol_rewrite = apply_filters( 'do_rocket_protocol_rewrite', false ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
47 +
48 + if ( ( get_rocket_option( 'do_cloudflare', 0 ) && get_rocket_option( 'cloudflare_protocol_rewrite', 0 ) || $do_rocket_protocol_rewrite ) ) {
49 + remove_filter( 'rocket_buffer', 'rocket_protocol_rewrite', PHP_INT_MAX );
50 + remove_filter( 'wp_calculate_image_srcset', 'rocket_protocol_rewrite_srcset', PHP_INT_MAX );
51 + }
52 + }
53 + }
54 +
55 + /**
56 + * Validate Cloudflare input data
57 + *
58 + * @since 3.4.1
59 + * @deprecated 3.5
60 + * @author Soponar Cristina
61 + *
62 + * @param string $cf_email - Cloudflare email.
63 + * @param string $cf_api_key - Cloudflare API key.
64 + * @param string $cf_zone_id - Cloudflare zone ID.
65 + * @param bool $basic_validation - Bypass Cloudflare API user and zone validation.
66 + * @return Object - true if credentials are ok, WP_Error otherwise.
67 + */
68 + function rocket_is_api_keys_valid_cloudflare( $cf_email, $cf_api_key, $cf_zone_id, $basic_validation = true ) {
69 + _deprecated_function( __FUNCTION__ . '()', '3.5', '\WP_Rocket\Subscriber\Tools\Cloudflare_Subscriber::is_api_keys_valid()' );
70 + if ( ! function_exists( 'curl_init' ) || ! function_exists( 'curl_exec' ) ) {
71 + return new WP_Error( 'curl_disabled', __( 'Curl is disabled on your server. Please ask your host to enable it. This is required for the Cloudflare Add-on to work correctly.', 'rocket' ) );
72 + }
73 +
74 + if ( ! isset( $cf_email, $cf_api_key ) || empty( $cf_email ) || empty( $cf_api_key ) ) {
75 + return new WP_Error(
76 + 'cloudflare_credentials_empty',
77 + sprintf(
78 + /* translators: %1$s = opening link; %2$s = closing link */
79 + __( 'Cloudflare email, API key and Zone ID are not set. Read the %1$sdocumentation%2$s for further guidance.', 'rocket' ),
80 + // translators: Documentation exists in EN, FR; use localized URL if applicable.
81 + '<a href="' . esc_url( __( 'https://docs.wp-rocket.me/article/18-using-wp-rocket-with-cloudflare/?utm_source=wp_plugin&utm_medium=wp_rocket#add-on', 'rocket' ) ) . '" rel="noopener noreferrer" target="_blank">',
82 + '</a>'
83 + )
84 + );
85 + }
86 +
87 + if ( ! isset( $cf_zone_id ) || empty( $cf_zone_id ) ) {
88 + $msg = __( 'Missing Cloudflare Zone ID.', 'rocket' );
89 +
90 + $msg .= ' ' . sprintf(
91 + /* translators: %1$s = opening link; %2$s = closing link */
92 + __( 'Read the %1$sdocumentation%2$s for further guidance.', 'rocket' ),
93 + // translators: Documentation exists in EN, FR; use localized URL if applicable.
94 + '<a href="' . esc_url( __( 'https://docs.wp-rocket.me/article/18-using-wp-rocket-with-cloudflare/?utm_source=wp_plugin&utm_medium=wp_rocket#add-on', 'rocket' ) ) . '" rel="noopener noreferrer" target="_blank">',
95 + '</a>'
96 + );
97 +
98 + return new WP_Error( 'cloudflare_no_zone_id', $msg );
99 + }
100 +
101 + if ( $basic_validation ) {
102 + return true;
103 + }
104 +
105 + try {
106 + $cf_api_instance = new Cloudflare\Api( $cf_email, $cf_api_key );
107 + $cf_zone = $cf_api_instance->get( 'zones/' . $cf_zone_id );
108 +
109 + if ( ! isset( $cf_zone->success ) || empty( $cf_zone->success ) ) {
110 + foreach ( $cf_zone->errors as $error ) {
111 + if ( 6003 === $error->code ) {
112 + $msg = __( 'Incorrect Cloudflare email address or API key.', 'rocket' );
113 +
114 + $msg .= ' ' . sprintf(
115 + /* translators: %1$s = opening link; %2$s = closing link */
116 + __( 'Read the %1$sdocumentation%2$s for further guidance.', 'rocket' ),
117 + // translators: Documentation exists in EN, FR; use localized URL if applicable.
118 + '<a href="' . esc_url( __( 'https://docs.wp-rocket.me/article/18-using-wp-rocket-with-cloudflare/?utm_source=wp_plugin&utm_medium=wp_rocket#add-on', 'rocket' ) ) . '" rel="noopener noreferrer" target="_blank">',
119 + '</a>'
120 + );
121 +
122 + return new WP_Error( 'cloudflare_invalid_auth', $msg );
123 + }
124 + }
125 + $msg = __( 'Incorrect Cloudflare Zone ID.', 'rocket' );
126 +
127 + $msg .= ' ' . sprintf(
128 + /* translators: %1$s = opening link; %2$s = closing link */
129 + __( 'Read the %1$sdocumentation%2$s for further guidance.', 'rocket' ),
130 + // translators: Documentation exists in EN, FR; use localized URL if applicable.
131 + '<a href="' . esc_url( __( 'https://docs.wp-rocket.me/article/18-using-wp-rocket-with-cloudflare/?utm_source=wp_plugin&utm_medium=wp_rocket#add-on', 'rocket' ) ) . '" rel="noopener noreferrer" target="_blank">',
132 + '</a>'
133 + );
134 + return new WP_Error( 'cloudflare_invalid_auth', $msg );
135 + }
136 +
137 + if ( true === $cf_zone->success ) {
138 + $zone_found = false;
139 + $site_url = get_site_url();
140 +
141 + if ( function_exists( 'domain_mapping_siteurl' ) ) {
142 + $site_url = domain_mapping_siteurl( $site_url );
143 + }
144 +
145 + if ( ! empty( $cf_zone->result ) ) {
146 + $parsed_url = wp_parse_url( $site_url );
147 + if ( false !== strpos( strtolower( $parsed_url['host'] ), $cf_zone->result->name ) ) {
148 + $zone_found = true;
149 + }
150 + }
151 +
152 + if ( ! $zone_found ) {
153 + $msg = __( 'It looks like your domain is not set up on Cloudflare.', 'rocket' );
154 +
155 + $msg .= ' ' . sprintf(
156 + /* translators: %1$s = opening link; %2$s = closing link */
157 + __( 'Read the %1$sdocumentation%2$s for further guidance.', 'rocket' ),
158 + // translators: Documentation exists in EN, FR; use localized URL if applicable.
159 + '<a href="' . esc_url( __( 'https://docs.wp-rocket.me/article/18-using-wp-rocket-with-cloudflare/?utm_source=wp_plugin&utm_medium=wp_rocket#add-on', 'rocket' ) ) . '" rel="noopener noreferrer" target="_blank">',
160 + '</a>'
161 + );
162 +
163 + return new WP_Error( 'cloudflare_wrong_zone_id', $msg );
164 + }
165 +
166 + return true;
167 + }
168 + } catch ( Exception $e ) {
169 + $msg = __( 'Incorrect Cloudflare email address or API key.', 'rocket' );
170 +
171 + $msg .= ' ' . sprintf(
172 + /* translators: %1$s = opening link; %2$s = closing link */
173 + __( 'Read the %1$sdocumentation%2$s for further guidance.', 'rocket' ),
174 + // translators: Documentation exists in EN, FR; use localized URL if applicable.
175 + '<a href="' . esc_url( __( 'https://docs.wp-rocket.me/article/18-using-wp-rocket-with-cloudflare/?utm_source=wp_plugin&utm_medium=wp_rocket#add-on', 'rocket' ) ) . '" rel="noopener noreferrer" target="_blank">',
176 + '</a>'
177 + );
178 +
179 + return new WP_Error( 'cloudflare_invalid_auth', $msg );
180 + }
181 + }
182 +
183 + /**
184 + * Get a Cloudflare\Api instance
185 + *
186 + * @since 2.8.21
187 + * @deprecated 3.5
188 + * @author Soponar Cristina
189 + *
190 + * @return Object Cloudflare\Api instance if crendentials are set, WP_Error otherwise
191 + */
192 + function get_rocket_cloudflare_api_instance() {
193 + _deprecated_function( __FUNCTION__ . '()', '3.5' );
194 + if ( ! function_exists( 'curl_init' ) || ! function_exists( 'curl_exec' ) ) {
195 + return new WP_Error( 'curl_disabled', __( 'Curl is disabled on your server. Please ask your host to enable it. This is required for the Cloudflare Add-on to work correctly.', 'rocket' ) );
196 + }
197 +
198 + $cf_email = get_rocket_option( 'cloudflare_email', null );
199 + $cf_api_key = ( defined( 'WP_ROCKET_CF_API_KEY' ) ) ? WP_ROCKET_CF_API_KEY : get_rocket_option( 'cloudflare_api_key', null );
200 +
201 + if ( ! isset( $cf_email, $cf_api_key ) ) {
202 + return new WP_Error(
203 + 'cloudflare_credentials_empty',
204 + sprintf(
205 + /* translators: %1$s = opening link; %2$s = closing link */
206 + __( 'Cloudflare email and API key are not set. Read the %1$sdocumentation%2$s for further guidance.', 'rocket' ),
207 + // translators: Documentation exists in EN, FR; use localized URL if applicable.
208 + '<a href="' . esc_url( __( 'https://docs.wp-rocket.me/article/18-using-wp-rocket-with-cloudflare/?utm_source=wp_plugin&utm_medium=wp_rocket#add-on', 'rocket' ) ) . '" rel="noopener noreferrer" target="_blank">',
209 + '</a>'
210 + )
211 + );
212 + }
213 + return new Cloudflare\Api( $cf_email, $cf_api_key );
214 + }
215 +
216 + /**
217 + * Get a Cloudflare\Api instance & the zone_id corresponding to the domain
218 + *
219 + * @since 2.8.21 Get the zone ID from the options
220 + * @since 2.8.18 Add try/catch to prevent fatal error Uncaugh Exception
221 + * @since 2.8.16 Update to Cloudflare API v4
222 + * @since 2.5
223 + * @deprecated 3.5
224 + *
225 + * @return Object Cloudflare instance & zone_id if credentials are correct, WP_Error otherwise
226 + */
227 + function get_rocket_cloudflare_instance() {
228 + _deprecated_function( __FUNCTION__ . '()', '3.5', '\WP_Rocket\Subscriber\Tools\Cloudflare_Subscriber::get_instance()' );
229 + $cf_email = get_rocket_option( 'cloudflare_email', null );
230 + $cf_api_key = ( defined( 'WP_ROCKET_CF_API_KEY' ) ) ? WP_ROCKET_CF_API_KEY : get_rocket_option( 'cloudflare_api_key', null );
231 + $cf_zone_id = get_rocket_option( 'cloudflare_zone_id', null );
232 + $is_api_keys_valid_cf = rocket_is_api_keys_valid_cloudflare( $cf_email, $cf_api_key, $cf_zone_id, true );
233 +
234 + if ( is_wp_error( $is_api_keys_valid_cf ) ) {
235 + return $is_api_keys_valid_cf;
236 + }
237 +
238 + $cf_api_instance = get_rocket_cloudflare_api_instance();
239 +
240 + $cf_instance = (object) [
241 + 'auth' => $cf_api_instance,
242 + 'zone_id' => $cf_zone_id,
243 + ];
244 +
245 + return $cf_instance;
246 + }
247 +
248 +
249 + /**
250 + * Test the connection with Cloudflare
251 + *
252 + * @since 2.9
253 + * @deprecated 3.5
254 + * @author Remy Perona
255 + *
256 + * @throws Exception If the connection to Cloudflare failed.
257 + * @return Object True if connection is successful, WP_Error otherwise
258 + */
259 + function rocket_cloudflare_valid_auth() {
260 + _deprecated_function( __FUNCTION__ . '()', '3.5' );
261 + $cf_api_instance = get_rocket_cloudflare_api_instance();
262 + if ( is_wp_error( $cf_api_instance ) ) {
263 + return $cf_api_instance;
264 + }
265 +
266 + try {
267 + $cf_zone_instance = new Cloudflare\Zone( $cf_api_instance );
268 + $cf_zones = $cf_zone_instance->zones();
269 +
270 + if ( ! isset( $cf_zones->success ) || empty( $cf_zones->success ) ) {
271 + throw new Exception( __( 'Connection to Cloudflare failed', 'rocket' ) );
272 + }
273 +
274 + if ( true === $cf_zones->success ) {
275 + return true;
276 + }
277 + } catch ( Exception $e ) {
278 + return new WP_Error( 'cloudflare_invalid_auth', $e->getMessage() );
279 + }
280 + }
281 +
282 +
283 +
284 + /**
285 + * Get all the current Cloudflare settings for a given domain.
286 + *
287 + * @since 2.8.16 Update to Cloudflare API v4
288 + * @since 2.5
289 + * @deprecated 3.5
290 + *
291 + * @return mixed bool|Array Array of Cloudflare settings, false if any error connection to Cloudflare
292 + */
293 + function get_rocket_cloudflare_settings() {
294 + _deprecated_function( __FUNCTION__ . '()', '3.5', '\WP_Rocket\Subscriber\Tools\Cloudflare_Subscriber::get_settings()' );
295 + }
296 +
297 +
298 + /**
299 + * Set the Cloudflare Development mode.
300 + *
301 + * @since 2.9 Now returns a value
302 + * @since 2.8.16 Update to Cloudflare API v4
303 + * @since 2.5
304 + * @deprecated 3.5
305 + *
306 + * @param string $mode Value for Cloudflare development mode.
307 + * @throws Exception If any error occurs when doing the API request.
308 + * @return mixed Object|String Mode value if the update is successful, WP_Error otherwise
309 + */
310 + function set_rocket_cloudflare_devmode( $mode ) {
311 + _deprecated_function( __FUNCTION__ . '()', '3.5', '\WP_Rocket\Subscriber\Tools\Cloudflare_Subscriber::set_devmode()' );
312 + }
313 +
314 +
315 + /**
316 + * Set the Cloudflare Caching level.
317 + *
318 + * @since 2.9 Now returns a value
319 + * @since 2.8.16 Update to Cloudflare API v4
320 + * @since 2.5
321 + * @deprecated 3.5
322 + *
323 + * @param string $mode Value for Cloudflare caching level.
324 + * @throws Exception If any error occurs when doing the API request.
325 + * @return mixed Object|String Mode value if the update is successful, WP_Error otherwise
326 + */
327 + function set_rocket_cloudflare_cache_level( $mode ) {
328 + _deprecated_function( __FUNCTION__ . '()', '3.5', '\WP_Rocket\Subscriber\Tools\Cloudflare_Subscriber::set_cache_level()' );
329 + }
330 +
331 + /**
332 + * Set the Cloudflare Minification.
333 + *
334 + * @since 2.9 Now returns a value
335 + * @since 2.8.16 Update to Cloudflare API v4
336 + * @since 2.5
337 + * @deprecated 3.5
338 + *
339 + * @param string $mode Value for Cloudflare minification.
340 + * @throws Exception If any error occurs when doing the API request.
341 + * @return mixed Object|String Mode value if the update is successful, WP_Error otherwise
342 + */
343 + function set_rocket_cloudflare_minify( $mode ) {
344 + _deprecated_function( __FUNCTION__ . '()', '3.5', '\WP_Rocket\Subscriber\Tools\Cloudflare_Subscriber::set_minify()' );
345 + }
346 +
347 +
348 + /**
349 + * Set the Cloudflare Rocket Loader.
350 + *
351 + * @since 2.9 Now returns value
352 + * @since 2.8.16 Update to Cloudflare API v4
353 + * @since 2.5
354 + * @deprecated 3.5
355 + *
356 + * @param string $mode Value for Cloudflare Rocket Loader.
357 + * @throws Exception If any error occurs when doing the API request.
358 + * @return mixed Object|String Mode value if the update is successful, WP_Error otherwise
359 + */
360 + function set_rocket_cloudflare_rocket_loader( $mode ) {
361 + _deprecated_function( __FUNCTION__ . '()', '3.5', '\WP_Rocket\Subscriber\Tools\Cloudflare_Subscriber::set_rocket_loader()' );
362 + }
363 +
364 +
365 + /**
366 + * Set the Browser Cache TTL in Cloudflare.
367 + *
368 + * @since 2.9 Now returns value
369 + * @since 2.8.16
370 + * @deprecated 3.5
371 + *
372 + * @param string $mode Value for Cloudflare browser cache TTL.
373 + * @throws Exception If any error occurs when doing the API request.
374 + * @return mixed Object|String Mode value if the update is successful, WP_Error otherwise
375 + */
376 + function set_rocket_cloudflare_browser_cache_ttl( $mode ) {
377 + _deprecated_function( __FUNCTION__ . '()', '3.5', '\WP_Rocket\Subscriber\Tools\Cloudflare_Subscriber::set_browser_cache_ttl()' );
378 + }
379 +
380 +
381 + /**
382 + * Purge Cloudflare cache.
383 + *
384 + * @since 2.9 Now returns value
385 + * @since 2.8.16 Update to Cloudflare API v4
386 + * @since 2.5
387 + * @deprecated 3.5
388 + *
389 + * @throws Exception If any error occurs when doing the API request.
390 + * @return mixed Object|bool true if the purge is successful, WP_Error otherwise
391 + */
392 + function rocket_purge_cloudflare() {
393 + _deprecated_function( __FUNCTION__ . '()', '3.5', '\WP_Rocket\Subscriber\Tools\Cloudflare_Subscriber::purge_cloudflare()' );
394 + }
395 +
396 + /**
397 + * Get Cloudflare IPs.
398 + *
399 + * @since 2.8.21 Save IPs in a transient to prevent calling the API everytime
400 + * @since 2.8.16
401 + * @deprecated 3.5
402 + *
403 + * @author Remy Perona
404 + *
405 + * @throws Exception If any error occurs when doing the API request.
406 + * @return Object Result of API request if successful, WP_Error otherwise
407 + */
408 + function rocket_get_cloudflare_ips() {
409 + _deprecated_function( __FUNCTION__ . '()', '3.5', '\WP_Rocket\Subscriber\Tools\Cloudflare_Subscriber::get_cloudflare_ips()' );
410 + $cf_instance = get_rocket_cloudflare_api_instance();
411 + if ( is_wp_error( $cf_instance ) ) {
412 + return $cf_instance;
413 + }
414 +
415 + $cf_ips = get_transient( 'rocket_cloudflare_ips' );
416 + if ( false === $cf_ips ) {
417 + try {
418 + $cf_ips_instance = new Cloudflare\IPs( $cf_instance );
419 + $cf_ips = $cf_ips_instance->ips();
420 +
421 + if ( ! isset( $cf_ips->success ) || ! $cf_ips->success ) {
422 + throw new Exception( 'Error connecting to Cloudflare' );
423 + }
424 +
425 + set_transient( 'rocket_cloudflare_ips', $cf_ips, 2 * WEEK_IN_SECONDS );
426 + } catch ( Exception $e ) {
427 + $cf_ips = (object) [
428 + 'success' => true,
429 + 'result' => (object) [],
430 + ];
431 +
432 + $cf_ips->result->ipv4_cidrs = [
433 + '103.21.244.0/22',
434 + '103.22.200.0/22',
435 + '103.31.4.0/22',
436 + '104.16.0.0/12',
437 + '108.162.192.0/18',
438 + '131.0.72.0/22',
439 + '141.101.64.0/18',
440 + '162.158.0.0/15',
441 + '172.64.0.0/13',
442 + '173.245.48.0/20',
443 + '188.114.96.0/20',
444 + '190.93.240.0/20',
445 + '197.234.240.0/22',
446 + '198.41.128.0/17',
447 + ];
448 +
449 + $cf_ips->result->ipv6_cidrs = [
450 + '2400:cb00::/32',
451 + '2405:8100::/32',
452 + '2405:b500::/32',
453 + '2606:4700::/32',
454 + '2803:f800::/32',
455 + '2c0f:f248::/32',
456 + '2a06:98c0::/29',
457 + ];
458 +
459 + set_transient( 'rocket_cloudflare_ips', $cf_ips, 2 * WEEK_IN_SECONDS );
460 + return $cf_ips;
461 + }
462 + }
463 +
464 + return $cf_ips;
465 + }
466 +
467 + /**
468 + * Set Real IP from CloudFlare
469 + *
470 + * @since 2.8.16 Uses CloudFlare API v4 to get CloudFlare IPs
471 + * @since 2.5.4
472 + *
473 + * @deprecated 3.5
474 + *
475 + * @source cloudflare.php - https://wordpress.org/plugins/cloudflare/
476 + */
477 + function rocket_set_real_ip_cloudflare() {
478 + _deprecated_function( __FUNCTION__ . '()', '3.5', '\WP_Rocket\Subscriber\Tools\Cloudflare_Subscriber::set_real_ip()' );
479 + global $is_cf;
480 +
481 + $is_cf = ( isset( $_SERVER['HTTP_CF_CONNECTING_IP'] ) ) ? true : false;
482 +
483 + if ( ! $is_cf ) {
484 + return;
485 + }
486 +
487 + // only run this logic if the REMOTE_ADDR is populated, to avoid causing notices in CLI mode.
488 + if ( isset( $_SERVER['REMOTE_ADDR'] ) ) {
489 + $cf_ips_values = rocket_get_cloudflare_ips();
490 +
491 + if ( is_wp_error( $cf_ips_values ) || ! isset( $cf_ips_values->success ) || ! $cf_ips_values->success ) {
492 + return;
493 + }
494 +
495 + if ( strpos( $_SERVER['REMOTE_ADDR'], ':' ) === false ) {
496 + $cf_ip_ranges = $cf_ips_values->result->ipv4_cidrs;
497 +
498 + // IPV4: Update the REMOTE_ADDR value if the current REMOTE_ADDR value is in the specified range.
499 + foreach ( $cf_ip_ranges as $range ) {
500 + if ( rocket_ipv4_in_range( $_SERVER['REMOTE_ADDR'], $range ) ) {
501 + if ( $_SERVER['HTTP_CF_CONNECTING_IP'] ) {
502 + $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_CF_CONNECTING_IP'];
503 + }
504 + break;
505 + }
506 + }
507 + }
508 + else {
509 + $cf_ip_ranges = $cf_ips_values->result->ipv6_cidrs;
510 +
511 + $ipv6 = get_rocket_ipv6_full( $_SERVER['REMOTE_ADDR'] );
512 + foreach ( $cf_ip_ranges as $range ) {
513 + if ( rocket_ipv6_in_range( $ipv6, $range ) ) {
514 + if ( $_SERVER['HTTP_CF_CONNECTING_IP'] ) {
515 + $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_CF_CONNECTING_IP'];
516 + }
517 + break;
518 + }
519 + }
520 + }
521 + }
522 +
523 + // Let people know that the CF WP plugin is turned on.
524 + if ( ! headers_sent() ) {
525 + header( 'X-CF-Powered-By: WP Rocket ' . WP_ROCKET_VERSION );
526 + }
527 + }
528 +
529 + /**
530 + * This notice is displayed after purging the CloudFlare cache
531 + *
532 + * @since 2.9
533 + * @author Remy Perona
534 + *
535 + * @deprecated 3.5
536 + *
537 + */
538 + function rocket_cloudflare_purge_result() {
539 + _deprecated_function( __FUNCTION__ . '()', '3.5', '\WP_Rocket\Subscriber\Tools\Cloudflare_Subscriber::maybe_print_notice()' );
540 + global $current_user;
541 + if ( ! current_user_can( 'rocket_purge_cloudflare_cache' ) ) {
542 + return;
543 + }
544 +
545 + if ( ! is_admin() ) {
546 + return;
547 + }
548 +
549 + $notice = get_transient( $current_user->ID . '_cloudflare_purge_result' );
550 + if ( ! $notice ) {
551 + return;
552 + }
553 +
554 + delete_transient( $current_user->ID . '_cloudflare_purge_result' );
555 +
556 + rocket_notice_html( [
557 + 'status' => $notice['result'],
558 + 'message' => $notice['message'],
559 + ] );
560 + }
561 +
562 + /**
563 + * Purge CloudFlare cache
564 + *
565 + * @since 2.5
566 + *
567 + * @deprecated 3.5
568 + *
569 + */
570 + function do_admin_post_rocket_purge_cloudflare() {
571 + _deprecated_function( __FUNCTION__ . '()', '3.5', '\WP_Rocket\Subscriber\Tools\Cloudflare_Subscriber::do_purge_cloudflare()' );
572 + if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( $_GET['_wpnonce'], 'rocket_purge_cloudflare' ) ) {
573 + wp_nonce_ays( '' );
574 + }
575 +
576 + if ( ! current_user_can( 'rocket_purge_cloudflare_cache' ) ) {
577 + return;
578 + }
579 +
580 + // Purge CloudFlare.
581 + $cf_purge = rocket_purge_cloudflare();
582 +
583 + if ( is_wp_error( $cf_purge ) ) {
584 + $cf_purge_result = [
585 + 'result' => 'error',
586 + // translators: %s = CloudFare API return message.
587 + 'message' => sprintf( __( '<strong>WP Rocket:</strong> %s', 'rocket' ), $cf_purge->get_error_message() ),
588 + ];
589 + } else {
590 + $cf_purge_result = [
591 + 'result' => 'success',
592 + 'message' => __( '<strong>WP Rocket:</strong> Cloudflare cache successfully purged.', 'rocket' ),
593 + ];
594 + }
595 +
596 + set_transient( get_current_user_id() . '_cloudflare_purge_result', $cf_purge_result );
597 +
598 + wp_safe_redirect( esc_url_raw( wp_get_referer() ) );
599 + die();
600 + }
601 +
602 + /**
603 + * This notice is displayed after modifying the CloudFlare settings
604 + *
605 + * @since 2.9
606 + * @author Remy Perona
607 + *
608 + * @deprecated 3.5
609 + */
610 + function rocket_cloudflare_update_settings() {
611 + _deprecated_function( __FUNCTION__ . '()', '3.5', '\WP_Rocket\Subscriber\Tools\Cloudflare_Subscriber::maybe_print_update_settings_notice()' );
612 + global $current_user;
613 + $screen = get_current_screen();
614 +
615 + if ( ! current_user_can( 'rocket_manage_options' ) ) {
616 + return;
617 + }
618 +
619 + if ( 'settings_page_wprocket' !== $screen->id ) {
620 + return;
621 + }
622 +
623 + $notices = get_transient( $current_user->ID . '_cloudflare_update_settings' );
624 + if ( $notices ) {
625 + $errors = '';
626 + $success = '';
627 + delete_transient( $current_user->ID . '_cloudflare_update_settings' );
628 + foreach ( $notices as $notice ) {
629 + if ( 'error' === $notice['result'] ) {
630 + $errors .= $notice['message'] . '<br>';
631 + } elseif ( 'success' === $notice['result'] ) {
632 + $success .= $notice['message'] . '<br>';
633 + }
634 + }
635 +
636 + if ( ! empty( $success ) ) {
637 + rocket_notice_html( [
638 + 'message' => $success,
639 + ] );
640 + }
641 +
642 + if ( ! empty( $errors ) ) {
643 + rocket_notice_html( [
644 + 'status' => 'error',
645 + 'message' => $success,
646 + ] );
647 + }
648 + }
649 + }
650 +
651 + /**
652 + * Purge all the domain
653 + *
654 + * @since 2.6.8
655 + * @deprecated 3.5
656 + *
657 + * @param string $root The path of home cache file.
658 + * @param string $lang The current lang to purge.
659 + * @param string $url The home url.
660 + */
661 + function rocket_varnish_clean_domain( $root, $lang, $url ) {
662 + _deprecated_function( __FUNCTION__ . '()', '3.5', 'WP_Rocket\Subscriber\Addons\Varnish\VarnishSubscriber::clean_domain()' );
663 + rocket_varnish_http_purge( trailingslashit( $url ) . '?vregex' );
664 + }
665 +
666 + /**
667 + * Purge a specific page
668 + *
669 + * @since 2.6.8
670 + * @deprecated 3.5
671 + *
672 + * @param string $url The url to purge.
673 + */
674 + function rocket_varnish_clean_file( $url ) {
675 + _deprecated_function( __FUNCTION__ . '()', '3.5', 'WP_Rocket\Subscriber\Addons\Varnish\VarnishSubscriber::clean_file()' );
676 + rocket_varnish_http_purge( trailingslashit( $url ) . '?vregex' );
677 + }
678 +
679 + /**
680 + * Purge the homepage and its pagination
681 + *
682 + * @since 2.6.8
683 + * @deprecated 3.5
684 + *
685 + * @param string $root The path of home cache file.
686 + * @param string $lang The current lang to purge.
687 + */
688 + function rocket_varnish_clean_home( $root, $lang ) {
689 + _deprecated_function( __FUNCTION__ . '()', '3.5', 'WP_Rocket\Subscriber\Addons\Varnish\VarnishSubscriber::clean_home()' );
690 + $home_url = trailingslashit( get_rocket_i18n_home_url( $lang ) );
691 + $home_pagination_url = $home_url . trailingslashit( $GLOBALS['wp_rewrite']->pagination_base ) . '?vregex';
692 +
693 + rocket_varnish_http_purge( $home_url );
694 + rocket_varnish_http_purge( $home_pagination_url );
695 + }
696 +
697 + /**
698 + * Sets the Varnish IP to localhost if Cloudflare is active
699 + *
700 + * @since 3.3.5
701 + * @deprecated 3.5
702 + * @author Remy Perona
703 + *
704 + * @return string
705 + */
706 + function rocket_varnish_proxy_host() {
707 + _deprecated_function( __FUNCTION__ . '()', '3.5', 'WP_Rocket\Subscriber\Addons\Cloudflare\CloudflareSubscriber::set_varnish_localhost()' );
708 + return 'localhost';
709 + }
710 +
711 + /**
712 + * Sets the Host header to the website domain if Cloudflare is active
713 + *
714 + * @since 3.3.5
715 + * @deprecated 3.5
716 + * @author Remy Perona
717 + *
718 + * @return string
719 + */
720 + function rocket_varnish_proxy_request_host() {
721 + _deprecated_function( __FUNCTION__ . '()', '3.5', 'WP_Rocket\Subscriber\Addons\Cloudflare\CloudflareSubscriber::set_varnish_purge_request_host()' );
722 + return wp_parse_url( home_url(), PHP_URL_HOST );
723 + }
724 +
725 + /**
726 + * Send data to Varnish
727 + *
728 + * @since 2.6.8
729 + * @deprecated 3.5
730 + *
731 + * @param string $url The URL to purge.
732 + * @return void
733 + */
734 + function rocket_varnish_http_purge( $url ) {
735 + _deprecated_function( __FUNCTION__ . '()', '3.5', 'WP_Rocket\Addons\Varnish\Varnish::purge()' );
736 + $parse_url = get_rocket_parse_url( $url );
737 +
738 + $varnish_x_purgemethod = 'default';
739 + $regex = '';
740 +
741 + if ( 'vregex' === $parse_url['query'] ) {
742 + $varnish_x_purgemethod = 'regex';
743 + $regex = '.*';
744 + }
745 +
746 + /**
747 + * Filter the Varnish IP to call
748 + *
749 + * @since 2.6.8
750 + * @param string The Varnish IP
751 + */
752 + $varnish_ip = apply_filters( 'rocket_varnish_ip', '' );
753 +
754 + if ( defined( 'WP_ROCKET_VARNISH_IP' ) && ! $varnish_ip ) {
755 + $varnish_ip = WP_ROCKET_VARNISH_IP;
756 + }
757 +
758 + /**
759 + * Filter the HTTP protocol (scheme)
760 + *
761 + * @since 2.7.3
762 + * @param string The HTTP protocol
763 + */
764 + $scheme = apply_filters( 'rocket_varnish_http_purge_scheme', 'http' );
765 +
766 + $parse_url['host'] = ( $varnish_ip ) ? $varnish_ip : $parse_url['host'];
767 + $purgeme = $scheme . '://' . $parse_url['host'] . $parse_url['path'] . $regex;
768 +
769 + wp_remote_request(
770 + $purgeme,
771 + array(
772 + 'method' => 'PURGE',
773 + 'blocking' => false,
774 + 'redirection' => 0,
775 + /**
776 + * Filters the headers to send with the Varnish purge request
777 + *
778 + * @since 3.1
779 + * @author Remy Perona
780 + *
781 + * @param array $headers Headers to send.
782 + */
783 + 'headers' => apply_filters(
784 + 'rocket_varnish_purge_headers',
785 + [
786 + /**
787 + * Filters the host value passed in the request headers
788 + *
789 + * @since 2.8.15
790 + * @param string The host
791 + */
792 + 'host' => apply_filters( 'rocket_varnish_purge_request_host', $parse_url['host'] ),
793 + 'X-Purge-Method' => $varnish_x_purgemethod,
794 + ]
795 + ),
796 + )
797 + );
798 + }
799 +
800 + /**
801 + * Display a warning notice if WP Rocket scheduled events are not running properly
802 + *
803 + * @since 3.5.4 deprecated
804 + * @since 3.3.7
805 + * @author Remy Perona
806 + *
807 + * @return void
808 + */
809 + function rocket_warning_cron() {
810 + _deprecated_function( __FUNCTION__ . '()', '3.5.4', 'WP_Rocket\Engine\Admin\HealthCheck::missed_cron()' );
811 + $screen = get_current_screen();
812 +
813 + // This filter is documented in inc/admin-bar.php.
814 + if ( ! current_user_can( apply_filters( 'rocket_capacity', 'manage_options' ) ) ) {
815 + return;
816 + }
817 +
818 + if ( 'settings_page_wprocket' !== $screen->id ) {
819 + return;
820 + }
821 +
822 + $boxes = get_user_meta( get_current_user_id(), 'rocket_boxes', true );
823 +
824 + if ( in_array( __FUNCTION__, (array) $boxes, true ) ) {
825 + return;
826 + }
827 +
828 + if ( 0 === (int) get_rocket_option( 'purge_cron_interval' ) && 0 === get_rocket_option( 'async_css' ) && 0 === get_rocket_option( 'manual_preload' ) && 0 === get_rocket_option( 'schedule_automatic_cleanup' ) ) {
829 + return;
830 + }
831 +
832 + $events = [
833 + 'rocket_purge_time_event' => 'Scheduled Cache Purge',
834 + 'rocket_database_optimization_time_event' => 'Scheduled Database Optimization',
835 + 'rocket_database_optimization_cron_interval' => 'Database Optimization Process',
836 + 'rocket_preload_cron_interval' => 'Preload',
837 + 'rocket_critical_css_generation_cron_interval' => 'Critical Path CSS Generation Process',
838 + ];
839 +
840 + foreach ( $events as $event => $description ) {
841 + $timestamp = wp_next_scheduled( $event );
842 +
843 + if ( false === $timestamp ) {
844 + unset( $events[ $event ] );
845 + continue;
846 + }
847 +
848 + if ( $timestamp - time() > 0 ) {
849 + unset( $events[ $event ] );
850 + continue;
851 + }
852 + }
853 +
854 + if ( empty( $events ) ) {
855 + return;
856 + }
857 +
858 + $message = '<p>' . _n( 'The following scheduled event failed to run. This may indicate the CRON system is not running properly, which can prevent some WP Rocket features from working as intended:', 'The following scheduled events failed to run. This may indicate the CRON system is not running properly, which can prevent some WP Rocket features from working as intended:', count( $events ), 'rocket' ) . '</p>';
859 +
860 + $message .= '<ul>';
861 +
862 + foreach ( $events as $description ) {
863 + $message .= '<li>' . $description . '</li>';
864 + }
865 +
866 + $message .= '</ul>';
867 + $message .= '<p>' . __( 'Please contact your host to check if CRON is working.', 'rocket' ) . '</p>';
868 +
869 + rocket_notice_html(
870 + [
871 + 'status' => 'warning',
872 + 'dismissible' => '',
873 + 'message' => $message,
874 + 'dismiss_button' => __FUNCTION__,
875 + ]
876 + );
877 + }
878 +
879 + /**
880 + * Add a link "Purge this cache" in the taxonomy edit area
881 + *
882 + * @since 3.5.5 deprecated
883 + * @since 1.0
884 + *
885 + * @param array $actions An array of row action links.
886 + * @param object $term The term object.
887 + * @return array Updated array of row action links
888 + */
889 + function rocket_tag_row_actions( $actions, $term ) {
890 + _deprecated_function( __FUNCTION__ . '()', '3.5.5', 'WP_Rocket\Engine\Cache\AdminSubscriber::add_purge_term_link()' );
891 + global $taxnow;
892 +
893 + if ( ! current_user_can( 'rocket_purge_terms' ) ) {
894 + return $actions;
895 + }
896 +
897 + $url = wp_nonce_url( admin_url( 'admin-post.php?action=purge_cache&type=term-' . $term->term_id . '&taxonomy=' . $taxnow ), 'purge_cache_term-' . $term->term_id );
898 + $actions['rocket_purge'] = sprintf( '<a href="%s">%s</a>', $url, __( 'Clear this cache', 'rocket' ) );
899 +
900 + return $actions;
901 + }
902 +