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

Keine Baseline-Datei – Diff nur gegen leer.
Zur Liste
1 -
1 + <?php
2 + use WP_Rocket\Dependencies\Minify;
3 +
4 + defined( 'ABSPATH' ) || exit;
5 +
6 + /**
7 + * Deprecated functions come here to die.
8 + */
9 +
10 + if ( ! function_exists( 'rocket_replace_domain_mapping_siteurl' ) ) :
11 + /**
12 + * Get Domain Mapping host based on original URL
13 + *
14 + * @since 2.2
15 + * @deprecated 2.6.5
16 + *
17 + * @param string $url Original URL.
18 + */
19 + function rocket_replace_domain_mapping_siteurl( $url = null ) {
20 + _deprecated_function( __FUNCTION__, '2.6.5' );
21 + return false;
22 + }
23 + endif;
24 +
25 + if ( ! function_exists( 'rocket_sanitize_cookie' ) ) :
26 + /**
27 + * Used to sanitize values of the "Don't cache pages that use the following cookies" option.
28 + *
29 + * @since 2.6.4
30 + * @deprecated 2.7
31 + * @deprecated Use rocket_sanitize_key()
32 + *
33 + * @param string $cookie Cookie value to sanitize.
34 + */
35 + function rocket_sanitize_cookie( $cookie ) {
36 + _deprecated_function( __FUNCTION__, '2.7', 'rocket_sanitize_key()' );
37 + return rocket_sanitize_key( $cookie );
38 + }
39 + endif;
40 +
41 + if ( ! function_exists( 'set_rocket_cloudflare_async' ) ) :
42 + /**
43 + * Used to set the CloudFlare Rocket Loader value
44 + *
45 + * @since 2.5
46 + * @deprecated 2.8.16
47 + * @deprecated Use set_rocket_cloudflare_rocket_loader()
48 + *
49 + * @param string $cf_rocket_loader Value for the Rocket Loader.
50 + */
51 + function set_rocket_cloudflare_async( $cf_rocket_loader ) {
52 + _deprecated_function( __FUNCTION__, '2.8.16', 'set_rocket_cloudflare_rocket_loader()' );
53 + }
54 + endif;
55 +
56 + if ( ! function_exists( 'set_rocket_cloudflare_cache_lvl' ) ) :
57 + /**
58 + * Used to set the CloudFlare cache level
59 + *
60 + * @since 2.5
61 + * @deprecated 2.8.16
62 + * @deprecated Use set_rocket_cloudflare_cache_level()
63 + *
64 + * @param string $cf_cache_level Value for the cache level.
65 + */
66 + function set_rocket_cloudflare_cache_lvl( $cf_cache_level ) {
67 + _deprecated_function( __FUNCTION__, '2.8.16', 'set_rocket_cloudflare_cache_level()' );
68 + }
69 + endif;
70 +
71 + if ( ! function_exists( 'rocket_delete_script_wp_version' ) ) :
72 + /**
73 + * Used to remove version query string in CSS/JS URL
74 + *
75 + * @since 1.1.6
76 + * @deprecated 2.9
77 + * @deprecated Use rocket_browser_cache_busting()
78 + *
79 + * @param string $src Source URL for the JS/CSS.
80 + */
81 + function rocket_delete_script_wp_version( $src ) {
82 + _deprecated_function( __FUNCTION__, '2.9', 'rocket_browser_cache_busting()' );
83 + return rocket_browser_cache_busting( $src );
84 + }
85 + endif;
86 +
87 + if ( ! function_exists( 'rocket_exclude_deferred_js' ) ) :
88 + /**
89 + * Used to remove deferred JS files from the buffer
90 + *
91 + * @since 1.1.0
92 + * @deprecated 2.10
93 + * @deprecated Use rocket_insert_deferred_js()
94 + *
95 + * @param string $buffer HTML code.
96 + */
97 + function rocket_exclude_deferred_js( $buffer ) {
98 + _deprecated_function( __FUNCTION__, '2.10', 'rocket_insert_deferred_js()' );
99 + return rocket_insert_deferred_js( $buffer );
100 + }
101 + endif;
102 +
103 + if ( ! function_exists( 'is_rocket_cache_feed' ) ) :
104 + /**
105 + * Check if we need to cache the feeds of the website
106 + *
107 + * @since 2.7
108 + * @deprecated 2.10
109 + *
110 + * @return bool True if option is activated
111 + */
112 + function is_rocket_cache_feed() {
113 + _deprecated_function( __FUNCTION__, '2.10' );
114 + return get_rocket_option( 'cache_feed', false );
115 + }
116 + endif;
117 +
118 + if ( ! function_exists( 'rocket_exclude_js_buddypress' ) ) :
119 + /**
120 + * Excludes BuddyPress's plupload from JS minification
121 + *
122 + * Exclude it to prevent an error after minification/concatenation
123 + * preventing the image upload from working correctly
124 + *
125 + * @since 2.8.10
126 + * @deprecated 2.10.7
127 + * @author Remy Perona
128 + *
129 + * @param Array $excluded_handle An array of JS handles enqueued in WordPress.
130 + * @return Array the updated array of handles
131 + */
132 + function rocket_exclude_js_buddypress( $excluded_handle ) {
133 + _deprecated_function( __FUNCTION__, '2.10.7' );
134 + return $excluded_handle;
135 + }
136 + endif;
137 +
138 + if ( ! function_exists( 'get_rocket_logins_exclude_pages' ) ) :
139 + /**
140 + * Get hide login pages to automatically exclude them to the cache.
141 + *
142 + * @since 2.6
143 + * @deprecated 2.11
144 + *
145 + * @return array $urls
146 + */
147 + function get_rocket_logins_exclude_pages() {
148 + _deprecated_function( __FUNCTION__, '2.11' );
149 + return array();
150 + }
151 + endif;
152 +
153 + if ( ! function_exists( 'get_rocket_ecommerce_exclude_pages' ) ) :
154 + /**
155 + * Get cart & checkout path with their translations to automatically exclude them to the cache.
156 + *
157 + * @since 2.4
158 + * @deprecated 2.11
159 + *
160 + * @return array $urls
161 + */
162 + function get_rocket_ecommerce_exclude_pages() {
163 + _deprecated_function( __FUNCTION__, '2.11' );
164 + return array();
165 + }
166 + endif;
167 +
168 +
169 + /**
170 + * Get list of JS files to deferred.
171 + *
172 + * @since 2.6
173 + * @deprecated 2.11
174 + *
175 + * @return array List of JS files.
176 + */
177 + function get_rocket_deferred_js_files() {
178 + _deprecated_function( __FUNCTION__, '2.11' );
179 + /**
180 + * Filter list of Deferred JavaScript files
181 + *
182 + * @since 1.1.0
183 + *
184 + * @param array List of Deferred JavaScript files
185 + */
186 + $deferred_js_files = apply_filters( 'rocket_minify_deferred_js', get_rocket_option( 'deferred_js_files', array() ) );
187 +
188 + return $deferred_js_files;
189 + }
190 +
191 + /**
192 + * Add defer attribute to script that should be deferred
193 + *
194 + * @since 2.10 Use defer attribute instead of labJS
195 + * @since 1.1.0
196 + * @deprecated 2.11
197 + *
198 + * @param string $buffer HTML content in the buffer.
199 + * @return string Updated HTML content
200 + */
201 + function rocket_insert_deferred_js( $buffer ) {
202 + _deprecated_function( __FUNCTION__, '2.11', 'rocket_defer_js()' );
203 + if ( get_rocket_option( 'defer_all_js' ) ) {
204 + return $buffer;
205 + }
206 +
207 + // Get all JS files with this regex.
208 + preg_match_all( '#<script.*src=[\'|"]([^\'|"]+\.js?.+)[\'|"].*></script>#iU', $buffer, $tags_match );
209 +
210 + if ( ! isset( $tags_match[0] ) ) {
211 + return $buffer;
212 + }
213 +
214 + foreach ( $tags_match[0] as $i => $tag ) {
215 + // Strip query args.
216 + $url = strtok( $tags_match[1][ $i ], '?' );
217 +
218 + $deferred_js_files = array_flip( get_rocket_deferred_js_files() );
219 +
220 + // Check if this file should be deferred.
221 + if ( isset( $deferred_js_files[ $url ] ) ) {
222 + $deferred_tag = str_replace( '></script>', ' defer></script>', $tag );
223 + $buffer = str_replace( $tag, $deferred_tag, $buffer );
224 + }
225 + }
226 +
227 + return $buffer;
228 + }
229 +
230 + /**
231 + * Used to display the deferred module on settings form
232 + *
233 + * @since 1.1.0
234 + * @deprecated 2.11
235 + */
236 + function rocket_defered_module() {
237 + _deprecated_function( __FUNCTION__, '2.11' );
238 + ?>
239 + <fieldset>
240 + <legend class="screen-reader-text"><span><?php _e( '<strong>JS</strong> files with Deferred Loading JavaScript', 'rocket' ); ?></span></legend>
241 +
242 + <div id="rkt-drop-deferred" class="rkt-module rkt-module-drop">
243 +
244 + <?php
245 + $deferred_js_files = get_rocket_option( 'deferred_js_files' );
246 +
247 + if ( $deferred_js_files ) {
248 +
249 + foreach ( $deferred_js_files as $k => $_url ) {
250 + ?>
251 +
252 + <p class="rkt-module-drag">
253 + <span class="dashicons dashicons-sort rkt-module-move hide-if-no-js"></span>
254 +
255 + <input style="width: 32em" type="text" placeholder="http://" class="deferred_js regular-text" name="wp_rocket_settings[deferred_js_files][<?php echo $k; ?>]" value="<?php echo esc_url( $_url ); ?>" />
256 +
257 + <span class="dashicons dashicons-no rkt-module-remove hide-if-no-js"></span>
258 + </p>
259 + <!-- .rkt-module-drag -->
260 +
261 + <?php
262 + }
263 + } else {
264 + // If no files yet, use this template inside #rkt-drop-deferred.
265 + ?>
266 +
267 + <p class="rkt-module-drag">
268 + <span class="dashicons dashicons-sort rkt-module-move hide-if-no-js"></span>
269 +
270 + <input style="width: 32em" type="text" placeholder="http://" class="deferred_js regular-text" name="wp_rocket_settings[deferred_js_files][0]" value="" />
271 + </p>
272 + <!-- .rkt-module-drag -->
273 +
274 + <?php } ?>
275 +
276 + </div>
277 + <!-- .rkt-drop-deferred -->
278 +
279 +
280 + <div class="rkt-module-model hide-if-js">
281 +
282 + <p class="rkt-module-drag">
283 + <span class="dashicons dashicons-sort rkt-module-move hide-if-no-js"></span>
284 +
285 + <input style="width: 32em" type="text" placeholder="http://" class="deferred_js regular-text" name="wp_rocket_settings[deferred_js_files][]" value="" />
286 +
287 + <span class="dashicons dashicons-no rkt-module-remove hide-if-no-js"></span>
288 + </p>
289 + <!-- .rkt-module-drag -->
290 + </div>
291 + <!-- .rkt-model-deferred-->
292 +
293 + <p><a href="javascript:void(0)" class="rkt-module-clone hide-if-no-js button-secondary"><?php _e( 'Add URL', 'rocket' ); ?></a></p>
294 +
295 + <?php
296 + }
297 +
298 + /**
299 + * Check if minify cache file exist and create it if not
300 + *
301 + * @since 2.10 Use wp_safe_remote_get() instead of curl
302 + * @since 2.1
303 + * @deprecated 2.11
304 + *
305 + * @param string $url The minified URL with Minify Library.
306 + * @param string $pretty_url The minified URL cache file.
307 + * @return bool True if successfully saved the minify cache file, false otherwise
308 + */
309 + function rocket_fetch_and_cache_minify( $url, $pretty_url ) {
310 + _deprecated_function( __FUNCTION__, '2.11', 'rocket_minify()' );
311 +
312 + return false;
313 + }
314 +
315 + /**
316 + * Minify a file and return the URL
317 + *
318 + * @since 2.10
319 + * @deprecated 2.11
320 + *
321 + * @param string $file File to minify.
322 + * @param bool $force_pretty_url (default: true).
323 + * @param string $pretty_filename (default: null) The new filename if $force_pretty_url set to true.
324 + * @return string URL of the minified file
325 + */
326 + function get_rocket_minify_file( $file, $force_pretty_url = true, $pretty_filename = null ) {
327 + _deprecated_function( __FUNCTION__, '2.11', 'get_rocket_minify_url()' );
328 +
329 + return $file;
330 + }
331 +
332 + /**
333 + * Get tag of a group of files or JS minified CSS
334 + *
335 + * @since 2.1
336 + * @deprecated 2.11
337 + *
338 + * @param array $files List of files to minify (CSS or JS).
339 + * @param bool $force_pretty_url (default: true).
340 + * @param string $pretty_filename (default: null) The new filename if $force_pretty_url set to true.
341 + * @return string $tags HTML tags for the minified CSS/JS files
342 + */
343 + function get_rocket_minify_files( $files, $force_pretty_url = true, $pretty_filename = null ) {
344 + _deprecated_function( __FUNCTION__, '2.11', 'get_rocket_minify_url()' );
345 +
346 + return false;
347 + }
348 +
349 + /**
350 + * Used to minify and concat CSS files
351 + *
352 + * @since 1.1.0 Fix Bug with externals URLs like //ajax.google.com
353 + * @since 1.0.2 Remove the filter, remove the array_chunk, add an automatic way to cut strings to 255c max
354 + * @since 1.0
355 + * @deprecated 2.11
356 + *
357 + * @param string $buffer HTML content.
358 + * @return string Updated HTML content
359 + */
360 + function rocket_minify_css( $buffer ) {
361 + _deprecated_function( __FUNCTION__, '2.11', 'rocket_minify_files()' );
362 +
363 + return rocket_minify_files( $buffer, 'css' );
364 + }
365 +
366 + /**
367 + * Used to minify and concat JavaScript files
368 + *
369 + * @since 1.1.0 Fix Bug with externals URLs like //ajax.google.com
370 + * @since 1.0.2 Remove the filter, remove the array_chunk, add an automatic way to cut strings to 255c max
371 + * @since 1.0
372 + * @deprecated 2.11
373 + *
374 + * @param string $buffer HTML content.
375 + * @return string Updated HTML content
376 + */
377 + function rocket_minify_js( $buffer ) {
378 + _deprecated_function( __FUNCTION__, '2.11', 'rocket_minify_files()' );
379 +
380 + return rocket_minify_files( $buffer, 'js' );
381 + }
382 +
383 + /**
384 + * Minify CSS/JS files without concatenation.
385 + *
386 + * @since 2.10
387 + * @deprecated 2.11
388 + * @author Remy Perona
389 + *
390 + * @param string $buffer HTML code to parse.
391 + * @param string $extension css or js.
392 + * @return string Updated HTML code
393 + */
394 + function rocket_minify_only( $buffer, $extension ) {
395 + _deprecated_function( __FUNCTION__, '2.11', 'rocket_minify_files()' );
396 +
397 + return rocket_minify_files( $buffer, $extension );
398 + }
399 +
400 + /**
401 + * Get all CSS files to exclude to the minification.
402 + *
403 + * @since 2.6
404 + * @deprecated 2.11
405 + *
406 + * @return array List of excluded CSS files.
407 + */
408 + function get_rocket_exclude_css() {
409 + _deprecated_function( __FUNCTION__, '2.11', 'get_rocket_exclude_files()' );
410 +
411 + return get_rocket_exclude_files( 'css' );
412 + }
413 +
414 + /**
415 + * Get all JS files to exclude to the minification.
416 + *
417 + * @since 2.6
418 + * @deprecated 2.11
419 + *
420 + * @return array List of excluded JS files.
421 + */
422 + function get_rocket_exclude_js() {
423 + _deprecated_function( __FUNCTION__, '2.11', 'get_rocket_exclude_files()' );
424 +
425 + return get_rocket_exclude_files( 'js' );
426 + }
427 +
428 + /**
429 + * Get all JS files to move in the footer during the minification.
430 + *
431 + * @since 2.6
432 + * @deprecated 2.11
433 + *
434 + * @return array List of JS files.
435 + */
436 + function get_rocket_minify_js_in_footer() {
437 + _deprecated_function( __FUNCTION__, '2.11' );
438 +
439 + return array();
440 + }
441 +
442 + /**
443 + * Extract all enqueued CSS files which should be exclude to the minification
444 + *
445 + * @since 2.6
446 + * @deprecated 2.11
447 + */
448 + function rocket_extract_excluded_css_files() {
449 + _deprecated_function( __FUNCTION__, '2.11' );
450 +
451 + return false;
452 + }
453 +
454 + /**
455 + * Extract all enqueued JS files which should be exclude to the minification
456 + *
457 + * @since 2.6.1
458 + * @deprecated 2.11
459 + */
460 + function rocket_extract_excluded_js_files() {
461 + _deprecated_function( __FUNCTION__, '2.11' );
462 +
463 + return false;
464 + }
465 +
466 + /**
467 + * Extract all enqueued JS files which should be insert in the footer
468 + *
469 + * @since 2.10
470 + * @since 2.6
471 + * @deprecated 2.11
472 + */
473 + function rocket_extract_js_files_from_footer() {
474 + _deprecated_function( __FUNCTION__, '2.11' );
475 +
476 + return false;
477 + }
478 +
479 + /**
480 + * Insert JS minify files in footer
481 + *
482 + * @since 2.2
483 + */
484 + function rocket_insert_minify_js_in_footer() {
485 + _deprecated_function( __FUNCTION__, '2.11' );
486 +
487 + return false;
488 + }
489 +
490 + /**
491 + * Compatibility with WordPress multisite with subfolders websites
492 + *
493 + * @since 2.6.5
494 + * @deprecated 2.11
495 + *
496 + * @param string $url minified file URL.
497 + * @return string Updated minified file URL
498 + */
499 + function rocket_fix_minify_multisite_path_issue( $url ) {
500 + _deprecated_function( __FUNCTION__, '2.11' );
501 +
502 + return $url;
503 + }
504 +
505 + /**
506 + * Force the minification to create only 1 file.
507 + *
508 + * @param int $length maximum URL length.
509 + * @param string $ext file extension.
510 + * @return int Updated length
511 + */
512 + function rocket_force_minify_combine_all( $length, $ext ) {
513 + _deprecated_function( __FUNCTION__, '2.11' );
514 + if ( 'css' === $ext && get_rocket_option( 'minify_css_combine_all', false ) ) {
515 + $length = PHP_INT_MAX;
516 + }
517 +
518 + if ( 'js' === $ext && get_rocket_option( 'minify_js_combine_all', false ) ) {
519 + $length = PHP_INT_MAX;
520 + }
521 +
522 + return $length;
523 + }
524 +
525 + /**
526 + * Add some CSS to display the dismiss cross
527 + *
528 + * @since 1.1.10
529 + * @deprecated 2.11
530 + */
531 + function rocket_admin_print_styles() {
532 + _deprecated_function( __FUNCTION__, '2.11' );
533 + }
534 +
535 + /**
536 + * Optimizes the database depending on the option
537 + *
538 + * @since 2.8
539 + * @deprecated 2.11
540 + * @see Rocket_Background_Database_Optimisation->task()
541 + * @author Remy Perona
542 + *
543 + * @param string $type Type of optimization to perform.
544 + */
545 + function rocket_database_optimize( $type ) {
546 + _deprecated_function( __FUNCTION__, '2.11', 'Rocket_Background_Database_Optimisation->task()' );
547 + }
548 +
549 + /**
550 + * Launches the database optimization from admin
551 + *
552 + * @since 2.8
553 + * @deprecated 2.11
554 + * @see Rocket_Database_Optimisation->optimize()
555 + * @author Remy Perona
556 + */
557 + function rocket_optimize_database() {
558 + _deprecated_function( __FUNCTION__, '2.11', 'Rocket_Database_Optimisation->optimize()' );
559 + }
560 +
561 + /**
562 + * Count the number of items concerned by the database cleanup
563 + *
564 + * @since 2.8
565 + * @deprecated 2.11
566 + * @see Rocket_Database_Optimisation->count_cleanup_items()
567 + * @author Remy Perona
568 + *
569 + * @param string $type Item type to count.
570 + * @return int Number of items for this type
571 + */
572 + function rocket_database_count_cleanup_items( $type ) {
573 + _deprecated_function( __FUNCTION__, '2.11', 'Rocket_Database_Optimisation->count_cleanup_items()' );
574 +
575 + return 0;
576 + }
577 +
578 + /**
579 + * Planning database optimization cron
580 + * If the task is not programmed, it is automatically triggered
581 + *
582 + * @since 2.8
583 + * @deprecated 2.11
584 + * @see Rocket_Database_Optimisation->database_optimization_scheduled()
585 + * @author Remy Perona
586 + */
587 + function rocket_database_optimization_scheduled() {
588 + _deprecated_function( __FUNCTION__, '2.11', 'Rocket_Database_Optimisation->database_optimization_scheduled()' );
589 + }
590 +
591 + /**
592 + * Performs the database optimization
593 + *
594 + * @since 2.8
595 + * @deprecated 2.11
596 + * @see Rocket_Database_Optimisation->process_handler()
597 + * @author Remy Perona
598 + */
599 + function do_rocket_database_optimization() {
600 + _deprecated_function( __FUNCTION__, '2.11', 'Rocket_Database_Optimisation->process_handler()' );
601 + }
602 +
603 + if ( ! function_exists( 'rocket_define_donotminify_constants' ) ) {
604 + /**
605 + * Declare and set value to DONOTMINIFYCSS & DONOTMINIFYJS constant
606 + *
607 + * @since 2.6.2
608 + * @deprecated 2.11
609 + * @see rocket_define_donotoptimize_constant()
610 + *
611 + * @param bool $value true or false.
612 + */
613 + function rocket_define_donotminify_constants( $value ) {
614 + _deprecated_function( __FUNCTION__, '2.11', 'rocket_define_donotoptimize_constant' );
615 +
616 + if ( ! defined( 'DONOTMINIFYCSS' ) ) {
617 + define( 'DONOTMINIFYCSS', (bool) $value );
618 + }
619 + if ( ! defined( 'DONOTMINIFYJS' ) ) {
620 + define( 'DONOTMINIFYJS', (bool) $value );
621 + }
622 + }
623 + }
624 +
625 + if ( ! function_exists( 'rocket_define_donotasync_css_constant' ) ) {
626 + /**
627 + * Declare and set value to DONOTMASYNCCSS constant
628 + *
629 + * @since 2.10
630 + * @deprecated 2.11
631 + * @see rocket_define_donotoptimize_constant()
632 + * @author Remy Perona
633 + *
634 + * @param bool $value true or false.
635 + */
636 + function rocket_define_donotasync_css_constant( $value ) {
637 + _deprecated_function( __FUNCTION__, '2.11', 'rocket_define_donotoptimize_constant' );
638 +
639 + if ( ! defined( 'DONOTASYNCCSS' ) ) {
640 + define( 'DONOTASYNCCSS', (bool) $value );
641 + }
642 + }
643 + }
644 +
645 + /**
646 + * Defer loading of CSS files
647 + *
648 + * @since 2.10
649 + * @deprecated 2.11
650 + * @see Rocket_Critical_CSS->async_css()
651 + * @author Remy Perona
652 + *
653 + * @param string $buffer HTML code.
654 + * @return string Updated HTML code
655 + */
656 + function rocket_async_css( $buffer ) {
657 + _deprecated_function( __FUNCTION__, '2.11', 'Rocket_Critical_CSS->async_css()' );
658 +
659 + return $buffer;
660 + }
661 +
662 + /**
663 + * Insert critical CSS in the <head>
664 + *
665 + * @since 2.10
666 + * @deprecated 2.11
667 + * @see Rocket_Critical_CSS->insert_critical_css()
668 + * @author Remy Perona
669 + */
670 + function rocket_insert_critical_css() {
671 + _deprecated_function( __FUNCTION__, '2.11', 'Rocket_Critical_CSS->insert_critical_css()' );
672 + }
673 +
674 + /**
675 + * Insert loadCSS script in <head>
676 + *
677 + * @since 2.10
678 + * @deprecated 2.11
679 + * @see WP_Rocket\Engine\CriticalPath\CriticalCSSSubscriber->insert_load_css()
680 + * @author Remy Perona
681 + */
682 + function rocket_insert_load_css() {
683 + _deprecated_function( __FUNCTION__, '2.11', 'WP_Rocket\Engine\CriticalPath\CriticalCSSSubscriber->insert_load_css()' );
684 + }
685 +
686 + if ( ! function_exists( 'rocket_lazyload_async_script' ) ) {
687 + /**
688 + * Add tags to the lazyload script to async and prevent concatenation
689 + *
690 + * @since 2.11
691 + * @deprecated 2.11.2
692 + * @author Remy Perona
693 + *
694 + * @param string $tag HTML for the script.
695 + * @param string $handle Handle for the script.
696 + *
697 + * @return string Updated HTML
698 + */
699 + function rocket_lazyload_async_script( $tag, $handle ) {
700 + _deprecated_function( __FUNCTION__, '2.11.2' );
701 +
702 + return $tag;
703 + }
704 + }
705 +
706 + if ( ! function_exists( 'is_rocket_cdn_on_ssl' ) ) {
707 + /**
708 + * Check if we need to disable CDN on SSL pages
709 + *
710 + * @since 2.5
711 + * @deprecated 3.0
712 + *
713 + * @return bool True if option is activated
714 + */
715 + function is_rocket_cdn_on_ssl() {
716 + _deprecated_function( __FUNCTION__, '3.0' );
717 + return is_ssl() && get_rocket_option( 'cdn_ssl', 0 ) ? false : true;
718 + }
719 + }
720 +
721 + if ( ! function_exists( 'is_rocket_cache_ssl' ) ) {
722 + /**
723 + * Check if we need to cache SSL requests of the website (if available)
724 + *
725 + * @since 1.0
726 + * @deprecated 3.0
727 + *
728 + * @return bool True if option is activated
729 + */
730 + function is_rocket_cache_ssl() {
731 + _deprecated_function( __FUNCTION__, '3.0' );
732 + return false;
733 + }
734 + }
735 +
736 + if ( ! function_exists( 'rocket_reset_white_label_values_action' ) ) {
737 + /**
738 + * Reset White Label values to WP Rocket default values
739 + *
740 + * @since 2.1
741 + * @deprecated 3.0
742 + */
743 + function rocket_reset_white_label_values_action() {
744 + _deprecated_function( __FUNCTION__, '3.0' );
745 + if ( isset( $_GET['_wpnonce'] ) && wp_verify_nonce( $_GET['_wpnonce'], 'rocket_resetwl' ) ) {
746 + rocket_reset_white_label_values( true );
747 + }
748 + wp_safe_redirect( add_query_arg( 'page', 'wprocket', remove_query_arg( 'page', wp_get_referer() ) ) );
749 + die();
750 + }
751 + }
752 +
753 + if ( ! function_exists( 'rocket_white_label' ) ) {
754 + /**
755 + * White Label the plugin, if you need to
756 + *
757 + * @since 2.1
758 + * @deprecated 3.0
759 + *
760 + * @param array $plugins An array of plugins installed.
761 + * @return array Updated array of plugins installed
762 + */
763 + function rocket_white_label( $plugins ) {
764 + _deprecated_function( __FUNCTION__, '3.0' );
765 + $white_label_description = get_rocket_option( 'wl_description' );
766 + // We change the plugin's header.
767 + $plugins['wp-rocket/wp-rocket.php'] = array(
768 + 'Name' => get_rocket_option( 'wl_plugin_name' ),
769 + 'PluginURI' => get_rocket_option( 'wl_plugin_URI' ),
770 + 'Version' => isset( $plugins['wp-rocket/wp-rocket.php']['Version'] ) ? $plugins['wp-rocket/wp-rocket.php']['Version'] : '',
771 + 'Description' => reset( ( $white_label_description ) ),
772 + 'Author' => get_rocket_option( 'wl_author' ),
773 + 'AuthorURI' => get_rocket_option( 'wl_author_URI' ),
774 + 'TextDomain' => isset( $plugins['wp-rocket/wp-rocket.php']['TextDomain'] ) ? $plugins['wp-rocket/wp-rocket.php']['TextDomain'] : '',
775 + 'DomainPath' => isset( $plugins['wp-rocket/wp-rocket.php']['DomainPath'] ) ? $plugins['wp-rocket/wp-rocket.php']['DomainPath'] : '',
776 + );
777 +
778 + // if white label, remove our names from contributors.
779 + if ( rocket_is_white_label() ) {
780 + remove_filter( 'plugin_row_meta', 'rocket_plugin_row_meta', 10, 2 );
781 + }
782 +
783 + return $plugins;
784 + }
785 + }
786 +
787 + if ( ! function_exists( 'rocket_is_white_label' ) ) {
788 + /**
789 + * Is this version White Labeled?
790 + *
791 + * @since 2.1
792 + * @deprecated 3.0
793 + */
794 + function rocket_is_white_label() {
795 + _deprecated_function( __FUNCTION__, '3.0' );
796 + $options = '';
797 + $names = array(
798 + 'wl_plugin_name',
799 + 'wl_plugin_URI',
800 + 'wl_description',
801 + 'wl_author',
802 + 'wl_author_URI',
803 + );
804 +
805 + foreach ( $names as $value ) {
806 + $option = get_rocket_option( $value );
807 + $options .= ! is_array( $option ) ? $option : reset( ( $option ) );
808 + }
809 +
810 + return '7ddca92d3d48d4da715a90ebcb3ec1f0' !== md5( $options );
811 + }
812 + }
813 +
814 + if ( ! function_exists( 'rocket_reset_white_label_values' ) ) {
815 + /**
816 + * Reset white label options
817 + *
818 + * @since 2.1
819 + * @deprecated 3.0
820 + *
821 + * @param bool $hack_post true if we need to modify the $_POST content, false otherwise.
822 + * @return void
823 + */
824 + function rocket_reset_white_label_values( $hack_post ) {
825 + _deprecated_function( __FUNCTION__, '3.0' );
826 + // White Label default values - !!! DO NOT TRANSLATE !!!
827 + $options = get_option( WP_ROCKET_SLUG );
828 + $options['wl_plugin_name'] = 'WP Rocket';
829 + $options['wl_plugin_slug'] = 'wprocket';
830 + $options['wl_plugin_URI'] = 'https://wp-rocket.me';
831 + $options['wl_description'] = array( 'The best WordPress performance plugin.' );
832 + $options['wl_author'] = 'WP Media';
833 + $options['wl_author_URI'] = 'https://wp-media.me';
834 +
835 + if ( $hack_post ) {
836 + // hack $_POST to force refresh of files, sorry.
837 + $_POST['page'] = 'wprocket';
838 + }
839 +
840 + update_option( WP_ROCKET_SLUG, $options );
841 + }
842 + }
843 +
844 + if ( ! function_exists( 'rocket_check_no_empty_name' ) ) {
845 + /**
846 + * When you're doing an update, the constant does not contain yet your option or any value, reset and redirect!
847 + *
848 + * @since 2.1
849 + * @deprecated 3.0
850 + */
851 + function rocket_check_no_empty_name() {
852 + _deprecated_function( __FUNCTION__, '3.0' );
853 + $wl_plugin_name = trim( get_rocket_option( 'wl_plugin_name' ) );
854 +
855 + if ( empty( $wl_plugin_name ) ) {
856 + wp_safe_redirect( $_SERVER['REQUEST_URI'] );
857 + die();
858 + }
859 + }
860 + }
861 +
862 + if ( ! function_exists( 'rocket_correct_capability_for_options_page' ) ) {
863 + /**
864 + * Fix the capability for our capacity filter hook
865 + *
866 + * @since 2.6
867 + * @deprecated 3.0
868 + * @see WP_Rocket\Engine\Settings\Page->required_capability()
869 + *
870 + * @param string $capability Capacity to access WP Rocket options.
871 + * @return string Updated capacity
872 + */
873 + function rocket_correct_capability_for_options_page( $capability ) {
874 + _deprecated_function( __FUNCTION__, '3.0', 'WP_Rocket\Engine\Settings\Page->required_compatibility()' );
875 + /** This filter is documented in inc/admin-bar.php */
876 + return apply_filters( 'rocket_capacity', 'manage_options' );
877 + }
878 + }
879 +
880 + if ( ! function_exists( 'rocket_admin_menu' ) ) {
881 + /**
882 + * Add submenu in menu "Settings"
883 + *
884 + * @since 1.0
885 + * @deprecated 3.0
886 + * @see WP_Rocket\Engine\Settings\Page->add_admin_page()
887 + */
888 + function rocket_admin_menu() {
889 + _deprecated_function( __FUNCTION__, '3.0', 'WP_Rocket\Engine\Settings\Page->add_admin_page()' );
890 + add_options_page( WP_ROCKET_PLUGIN_NAME, WP_ROCKET_PLUGIN_NAME, apply_filters( 'rocket_capacity', 'manage_options' ), WP_ROCKET_PLUGIN_SLUG, 'rocket_display_options' );
891 + }
892 + }
893 +
894 + if ( ! function_exists( 'rocket_include' ) ) {
895 + /**
896 + * Used to include a file in any tab
897 + *
898 + * @since 2.2
899 + * @deprecated 3.0
900 + *
901 + * @param array $args An array of arguments to include the file.
902 + */
903 + function rocket_include( $args ) {
904 + _deprecated_function( __FUNCTION__, '3.0' );
905 + include_once dirname( __FILE__ ) . '/' . str_replace( '..', '', $args['file'] ) . '.inc.php';
906 + }
907 + }
908 +
909 + if ( ! function_exists( 'rocket_register_setting' ) ) {
910 + /**
911 + * Tell to WordPress to be confident with our setting, we are clean!
912 + *
913 + * @since 1.0
914 + * @deprecated 3.0
915 + * @see WP_Rocket\Engine\Settings\Page->configure()
916 + */
917 + function rocket_register_setting() {
918 + _deprecated_function( __FUNCTION__, '3.0', 'WP_Rocket\Engine\Settings\Page->configure()' );
919 + register_setting( 'wp_rocket', WP_ROCKET_SLUG, 'rocket_settings_callback' );
920 + }
921 + }
922 +
923 + if ( ! function_exists( 'rocket_settings_callback' ) ) {
924 + /**
925 + * Used to clean and sanitize the settings fields
926 + *
927 + * @since 1.0
928 + *
929 + * @param array $inputs An array of values submitted by the settings form.
930 + */
931 + function rocket_settings_callback( $inputs ) {
932 + _deprecated_function( __FUNCTION__, '3.0', 'WP_Rocket\Engine\Admin\Settings\Settings->sanitize_callback()' );
933 + if ( isset( $_GET['action'] ) && 'purge_cache' === $_GET['action'] ) {
934 + return $inputs;
935 + }
936 +
937 + /*
938 + * Option : Minification CSS & JS
939 + */
940 + $inputs['minify_css'] = ! empty( $inputs['minify_css'] ) ? 1 : 0;
941 + $inputs['minify_js'] = ! empty( $inputs['minify_js'] ) ? 1 : 0;
942 +
943 + // Option: mobile cache.
944 + if ( rocket_is_mobile_plugin_active() ) {
945 + $inputs['cache_mobile'] = 1;
946 + $inputs['do_caching_mobile_files'] = 1;
947 + }
948 +
949 + if ( empty( $inputs['lazyload_iframes'] ) ) {
950 + $inputs['lazyload_youtube'] = 0;
951 + }
952 +
953 + /*
954 + * Option : Purge delay
955 + */
956 + $inputs['purge_cron_interval'] = isset( $inputs['purge_cron_interval'] ) ? (int) $inputs['purge_cron_interval'] : get_rocket_option( 'purge_cron_interval' );
957 + $inputs['purge_cron_unit'] = isset( $inputs['purge_cron_unit'] ) ? $inputs['purge_cron_unit'] : get_rocket_option( 'purge_cron_unit' );
958 +
959 + if ( $inputs['purge_cron_interval'] < 10 && 'MINUTE_IN_SECONDS' === $inputs['purge_cron_unit'] ) {
960 + $inputs['purge_cron_interval'] = 10;
961 + }
962 +
963 + /*
964 + * Option : Remove query strings
965 + */
966 + $inputs['remove_query_strings'] = ! empty( $inputs['remove_query_strings'] ) ? 1 : 0;
967 +
968 + /*
969 + * Option : Prefetch DNS requests
970 + */
971 + if ( ! empty( $inputs['dns_prefetch'] ) ) {
972 + if ( ! is_array( $inputs['dns_prefetch'] ) ) {
973 + $inputs['dns_prefetch'] = explode( "\n", $inputs['dns_prefetch'] );
974 + }
975 + $inputs['dns_prefetch'] = array_map( 'trim', $inputs['dns_prefetch'] );
976 + $inputs['dns_prefetch'] = array_map( 'esc_url', $inputs['dns_prefetch'] );
977 + $inputs['dns_prefetch'] = (array) array_filter( $inputs['dns_prefetch'] );
978 + $inputs['dns_prefetch'] = array_unique( $inputs['dns_prefetch'] );
979 + } else {
980 + $inputs['dns_prefetch'] = array();
981 + }
982 +
983 + /*
984 + * Option : Empty the cache of the following pages when updating an article
985 + */
986 + if ( ! empty( $inputs['cache_purge_pages'] ) ) {
987 + if ( ! is_array( $inputs['cache_purge_pages'] ) ) {
988 + $inputs['cache_purge_pages'] = explode( "\n", $inputs['cache_purge_pages'] );
989 + }
990 + $inputs['cache_purge_pages'] = array_map( 'trim', $inputs['cache_purge_pages'] );
991 + $inputs['cache_purge_pages'] = array_map( 'esc_url', $inputs['cache_purge_pages'] );
992 + $inputs['cache_purge_pages'] = array_map( 'rocket_clean_exclude_file', $inputs['cache_purge_pages'] );
993 + $inputs['cache_purge_pages'] = (array) array_filter( $inputs['cache_purge_pages'] );
994 + $inputs['cache_purge_pages'] = array_unique( $inputs['cache_purge_pages'] );
995 + } else {
996 + $inputs['cache_purge_pages'] = array();
997 + }
998 +
999 + /*
1000 + * Option : Never cache the following pages
1001 + */
1002 + if ( ! empty( $inputs['cache_reject_uri'] ) ) {
1003 + if ( ! is_array( $inputs['cache_reject_uri'] ) ) {
1004 + $inputs['cache_reject_uri'] = explode( "\n", $inputs['cache_reject_uri'] );
1005 + }
1006 + $inputs['cache_reject_uri'] = array_map( 'trim', $inputs['cache_reject_uri'] );
1007 + $inputs['cache_reject_uri'] = array_map( 'esc_url', $inputs['cache_reject_uri'] );
1008 + $inputs['cache_reject_uri'] = array_map( 'rocket_clean_exclude_file', $inputs['cache_reject_uri'] );
1009 + $inputs['cache_reject_uri'] = (array) array_filter( $inputs['cache_reject_uri'] );
1010 + $inputs['cache_reject_uri'] = array_unique( $inputs['cache_reject_uri'] );
1011 + } else {
1012 + $inputs['cache_reject_uri'] = array();
1013 + }
1014 +
1015 + /*
1016 + * Option : Don't cache pages that use the following cookies
1017 + */
1018 + if ( ! empty( $inputs['cache_reject_cookies'] ) ) {
1019 + if ( ! is_array( $inputs['cache_reject_cookies'] ) ) {
1020 + $inputs['cache_reject_cookies'] = explode( "\n", $inputs['cache_reject_cookies'] );
1021 + }
1022 + $inputs['cache_reject_cookies'] = array_map( 'trim', $inputs['cache_reject_cookies'] );
1023 + $inputs['cache_reject_cookies'] = array_map( 'rocket_sanitize_key', $inputs['cache_reject_cookies'] );
1024 + $inputs['cache_reject_cookies'] = (array) array_filter( $inputs['cache_reject_cookies'] );
1025 + $inputs['cache_reject_cookies'] = array_unique( $inputs['cache_reject_cookies'] );
1026 + } else {
1027 + $inputs['cache_reject_cookies'] = array();
1028 + }
1029 +
1030 + /*
1031 + * Option : Cache pages that use the following query strings (GET parameters)
1032 + */
1033 + if ( ! empty( $inputs['cache_query_strings'] ) ) {
1034 + if ( ! is_array( $inputs['cache_query_strings'] ) ) {
1035 + $inputs['cache_query_strings'] = explode( "\n", $inputs['cache_query_strings'] );
1036 + }
1037 + $inputs['cache_query_strings'] = array_map( 'trim', $inputs['cache_query_strings'] );
1038 + $inputs['cache_query_strings'] = array_map( 'rocket_sanitize_key', $inputs['cache_query_strings'] );
1039 + $inputs['cache_query_strings'] = (array) array_filter( $inputs['cache_query_strings'] );
1040 + $inputs['cache_query_strings'] = array_unique( $inputs['cache_query_strings'] );
1041 + } else {
1042 + $inputs['cache_query_strings'] = array();
1043 + }
1044 +
1045 + /*
1046 + * Option : Never send cache pages for these user agents
1047 + */
1048 + if ( ! empty( $inputs['cache_reject_ua'] ) ) {
1049 + if ( ! is_array( $inputs['cache_reject_ua'] ) ) {
1050 + $inputs['cache_reject_ua'] = explode( "\n", $inputs['cache_reject_ua'] );
1051 + }
1052 + $inputs['cache_reject_ua'] = array_map( 'trim', $inputs['cache_reject_ua'] );
1053 + $inputs['cache_reject_ua'] = array_map( 'rocket_sanitize_ua', $inputs['cache_reject_ua'] );
1054 + $inputs['cache_reject_ua'] = (array) array_filter( $inputs['cache_reject_ua'] );
1055 + $inputs['cache_reject_ua'] = array_unique( $inputs['cache_reject_ua'] );
1056 + } else {
1057 + $inputs['cache_reject_ua'] = array();
1058 + }
1059 +
1060 + /*
1061 + * Option : CSS files to exclude of the minification
1062 + */
1063 + if ( ! empty( $inputs['exclude_css'] ) ) {
1064 + if ( ! is_array( $inputs['exclude_css'] ) ) {
1065 + $inputs['exclude_css'] = explode( "\n", $inputs['exclude_css'] );
1066 + }
1067 + $inputs['exclude_css'] = array_map( 'trim', $inputs['exclude_css'] );
1068 + $inputs['exclude_css'] = array_map( 'rocket_clean_exclude_file', $inputs['exclude_css'] );
1069 + $inputs['exclude_css'] = array_map( 'rocket_sanitize_css', $inputs['exclude_css'] );
1070 + $inputs['exclude_css'] = (array) array_filter( $inputs['exclude_css'] );
1071 + $inputs['exclude_css'] = array_unique( $inputs['exclude_css'] );
1072 + } else {
1073 + $inputs['exclude_css'] = array();
1074 + }
1075 +
1076 + /*
1077 + * Option : JS files to exclude of the minification
1078 + */
1079 + if ( ! empty( $inputs['exclude_js'] ) ) {
1080 + if ( ! is_array( $inputs['exclude_js'] ) ) {
1081 + $inputs['exclude_js'] = explode( "\n", $inputs['exclude_js'] );
1082 + }
1083 + $inputs['exclude_js'] = array_map( 'trim', $inputs['exclude_js'] );
1084 + $inputs['exclude_js'] = array_map( 'rocket_clean_exclude_file', $inputs['exclude_js'] );
1085 + $inputs['exclude_js'] = array_map( 'rocket_sanitize_js', $inputs['exclude_js'] );
1086 + $inputs['exclude_js'] = (array) array_filter( $inputs['exclude_js'] );
1087 + $inputs['exclude_js'] = array_unique( $inputs['exclude_js'] );
1088 + } else {
1089 + $inputs['exclude_js'] = array();
1090 + }
1091 +
1092 + // Option: Async CSS.
1093 + $inputs['async_css'] = ! empty( $inputs['async_css'] ) ? 1 : 0;
1094 +
1095 + // Option: Critical CSS.
1096 + $inputs['critical_css'] = ! empty( $inputs['critical_css'] ) ? str_replace( array( '<style>', '</style>' ), '', wp_kses( $inputs['critical_css'], array( "\'", '\"' ) ) ) : '';
1097 +
1098 + /*
1099 + * Option : JS files to exclude from defer JS
1100 + */
1101 + if ( ! empty( $inputs['exclude_defer_js'] ) ) {
1102 + if ( ! is_array( $inputs['exclude_defer_js'] ) ) {
1103 + $inputs['exclude_defer_js'] = explode( "\n", $inputs['exclude_defer_js'] );
1104 + }
1105 + $inputs['exclude_defer_js'] = array_map( 'trim', $inputs['exclude_defer_js'] );
1106 + $inputs['exclude_defer_js'] = array_unique( $inputs['exclude_defer_js'] );
1107 + $inputs['exclude_defer_js'] = array_map( 'rocket_sanitize_js', $inputs['exclude_defer_js'] );
1108 + $inputs['exclude_defer_js'] = array_filter( $inputs['exclude_defer_js'] );
1109 + } else {
1110 + $inputs['exclude_defer_js'] = array();
1111 + }
1112 +
1113 + /**
1114 + * Database options
1115 + */
1116 + $inputs['database_revisions'] = ! empty( $inputs['database_revisions'] ) ? 1 : 0;
1117 + $inputs['database_auto_drafts'] = ! empty( $inputs['database_auto_drafts'] ) ? 1 : 0;
1118 + $inputs['database_trashed_posts'] = ! empty( $inputs['database_trashed_posts'] ) ? 1 : 0;
1119 + $inputs['database_spam_comments'] = ! empty( $inputs['database_spam_comments'] ) ? 1 : 0;
1120 + $inputs['database_trashed_comments'] = ! empty( $inputs['database_trashed_comments'] ) ? 1 : 0;
1121 + $inputs['database_expired_transients'] = ! empty( $inputs['database_expired_transients'] ) ? 1 : 0;
1122 + $inputs['database_all_transients'] = ! empty( $inputs['database_all_transients'] ) ? 1 : 0;
1123 + $inputs['database_optimize_tables'] = ! empty( $inputs['database_optimize_tables'] ) ? 1 : 0;
1124 + $inputs['schedule_automatic_cleanup'] = ! empty( $inputs['schedule_automatic_cleanup'] ) ? 1 : 0;
1125 + $inputs['automatic_cleanup_frequency'] = ! empty( $inputs['automatic_cleanup_frequency'] ) ? $inputs['automatic_cleanup_frequency'] : '';
1126 +
1127 + if ( 1 !== $inputs['schedule_automatic_cleanup'] && ( 'daily' !== $inputs['automatic_cleanup_frequency'] || 'weekly' !== $inputs['automatic_cleanup_frequency'] || 'monthly' !== $inputs['automatic_cleanup_frequency'] ) ) {
1128 + unset( $inputs['automatic_cleanup_frequency'] );
1129 + }
1130 +
1131 + /**
1132 + * Options: Activate bot preload
1133 + */
1134 + $inputs['manual_preload'] = ! empty( $inputs['manual_preload'] ) ? 1 : 0;
1135 + $inputs['automatic_preload'] = ! empty( $inputs['automatic_preload'] ) ? 1 : 0;
1136 +
1137 + /*
1138 + * Option: activate sitemap preload
1139 + */
1140 + $inputs['sitemap_preload'] = ! empty( $inputs['sitemap_preload'] ) ? 1 : 0;
1141 +
1142 + /*
1143 + * Option : XML sitemaps URLs
1144 + */
1145 + if ( ! empty( $inputs['sitemaps'] ) ) {
1146 + if ( ! is_array( $inputs['sitemaps'] ) ) {
1147 + $inputs['sitemaps'] = explode( "\n", $inputs['sitemaps'] );
1148 + }
1149 + $inputs['sitemaps'] = array_map( 'trim', $inputs['sitemaps'] );
1150 + $inputs['sitemaps'] = array_map( 'rocket_sanitize_xml', $inputs['sitemaps'] );
1151 + $inputs['sitemaps'] = (array) array_filter( $inputs['sitemaps'] );
1152 + $inputs['sitemaps'] = array_unique( $inputs['sitemaps'] );
1153 + } else {
1154 + $inputs['sitemaps'] = array();
1155 + }
1156 +
1157 + /*
1158 + * Option : CloudFlare Domain
1159 + */
1160 + if ( ! empty( $inputs['cloudflare_domain'] ) ) {
1161 + $inputs['cloudflare_domain'] = rocket_get_domain( $inputs['cloudflare_domain'] );
1162 + } else {
1163 + $inputs['cloudflare_domain'] = '';
1164 + }
1165 +
1166 + $inputs['cloudflare_devmode'] = ( isset( $inputs['cloudflare_devmode'] ) && is_numeric( $inputs['cloudflare_devmode'] ) ) ? (int) $inputs['cloudflare_devmode'] : 0;
1167 + $inputs['cloudflare_auto_settings'] = ( isset( $inputs['cloudflare_auto_settings'] ) && is_numeric( $inputs['cloudflare_auto_settings'] ) ) ? (int) $inputs['cloudflare_auto_settings'] : 0;
1168 +
1169 + /*
1170 + * Option : CloudFlare
1171 + */
1172 + if ( defined( 'WP_ROCKET_CF_API_KEY' ) ) {
1173 + $inputs['cloudflare_api_key'] = get_rocket_option( 'cloudflare_api_key' );
1174 + }
1175 +
1176 + /*
1177 + * Option : CDN
1178 + */
1179 + $inputs['cdn_cnames'] = isset( $inputs['cdn_cnames'] ) ? array_unique( array_filter( $inputs['cdn_cnames'] ) ) : array();
1180 +
1181 + if ( ! $inputs['cdn_cnames'] ) {
1182 + $inputs['cdn_zone'] = array();
1183 + } else {
1184 + $total_cdn_cnames = max( array_keys( $inputs['cdn_cnames'] ) );
1185 + for ( $i = 0; $i <= $total_cdn_cnames; $i++ ) {
1186 + if ( ! isset( $inputs['cdn_cnames'][ $i ] ) ) {
1187 + unset( $inputs['cdn_zone'][ $i ] );
1188 + } else {
1189 + $inputs['cdn_zone'][ $i ] = isset( $inputs['cdn_zone'][ $i ] ) ? $inputs['cdn_zone'][ $i ] : 'all';
1190 + }
1191 + }
1192 +
1193 + $inputs['cdn_cnames'] = array_values( $inputs['cdn_cnames'] );
1194 + $inputs['cdn_cnames'] = array_map( 'untrailingslashit', $inputs['cdn_cnames'] );
1195 + ksort( $inputs['cdn_zone'] );
1196 + $inputs['cdn_zone'] = array_values( $inputs['cdn_zone'] );
1197 + }
1198 +
1199 + /*
1200 + * Option : Files to exclude of the CDN process
1201 + */
1202 + if ( ! empty( $inputs['cdn_reject_files'] ) ) {
1203 + if ( ! is_array( $inputs['cdn_reject_files'] ) ) {
1204 + $inputs['cdn_reject_files'] = explode( "\n", $inputs['cdn_reject_files'] );
1205 + }
1206 + $inputs['cdn_reject_files'] = array_map( 'trim', $inputs['cdn_reject_files'] );
1207 + $inputs['cdn_reject_files'] = array_map( 'rocket_clean_exclude_file', $inputs['cdn_reject_files'] );
1208 + $inputs['cdn_reject_files'] = (array) array_filter( $inputs['cdn_reject_files'] );
1209 + $inputs['cdn_reject_files'] = array_unique( $inputs['cdn_reject_files'] );
1210 + } else {
1211 + $inputs['cdn_reject_files'] = array();
1212 + }
1213 +
1214 + /*
1215 + * Option: Support
1216 + */
1217 + $fake_options = array(
1218 + 'support_summary',
1219 + 'support_description',
1220 + 'support_documentation_validation',
1221 + );
1222 +
1223 + foreach ( $fake_options as $option ) {
1224 + if ( isset( $inputs[ $option ] ) ) {
1225 + unset( $inputs[ $option ] );
1226 + }
1227 + }
1228 +
1229 + if ( isset( $_FILES['import'] ) && 0 !== $_FILES['import']['size'] && $settings = rocket_handle_settings_import( $_FILES['import'], 'wp-rocket', $inputs ) ) {
1230 + $inputs = $settings;
1231 + }
1232 +
1233 + if ( ! rocket_valid_key() ) {
1234 + $checked = rocket_check_key();
1235 + }
1236 +
1237 + if ( isset( $checked ) && is_array( $checked ) ) {
1238 + $inputs['consumer_key'] = $checked['consumer_key'];
1239 + $inputs['consumer_email'] = $checked['consumer_email'];
1240 + $inputs['secret_key'] = $checked['secret_key'];
1241 + }
1242 +
1243 + if ( rocket_valid_key() && ! empty( $inputs['secret_key'] ) && ! isset( $inputs['ignore'] ) ) {
1244 + unset( $inputs['ignore'] );
1245 + add_settings_error( 'general', 'settings_updated', __( 'Settings saved.', 'rocket' ), 'updated' );
1246 + }
1247 +
1248 + return apply_filters( 'rocket_inputs_sanitize', $inputs );
1249 + }
1250 + }
1251 +
1252 + if ( ! function_exists( 'rocket_import_upload_form' ) ) {
1253 + /**
1254 + * Outputs the form used by the importers to accept the data to be imported
1255 + *
1256 + * @since 2.2
1257 + * @deprecated 3.0
1258 + *
1259 + * @see WP_Rocket\Admin\Render->render_import_form();
1260 + */
1261 + function rocket_import_upload_form() {
1262 + _deprecated_function( __FUNCTION__, '3.0', 'WP_Rocket\Admin\Render->render_import_form()' );
1263 + /**
1264 + * Filter the maximum allowed upload size for import files.
1265 + *
1266 + * @since (WordPress) 2.3.0
1267 + *
1268 + * @see wp_max_upload_size()
1269 + *
1270 + * @param int $max_upload_size Allowed upload size. Default 1 MB.
1271 + */
1272 + $bytes = apply_filters( 'import_upload_size_limit', wp_max_upload_size() ); // Filter from WP Core.
1273 + $size = size_format( $bytes );
1274 + $upload_dir = wp_upload_dir();
1275 + if ( ! empty( $upload_dir['error'] ) ) {
1276 + ?>
1277 + <div class="error"><p><?php _e( 'Before you can upload your import file, you will need to fix the following error:', 'rocket' ); ?></p>
1278 + <p><strong><?php echo $upload_dir['error']; ?></strong></p></div>
1279 + <?php
1280 + } else {
1281 + ?>
1282 + <p>
1283 + <input type="file" id="upload" name="import" size="25" />
1284 + <br />
1285 + <label for="upload">
1286 + <?php
1287 + // translators: %s is the maximum upload size set on the current server.
1288 + echo apply_filters( 'rocket_help', sprintf( __( 'Choose a file from your computer (maximum size: %s)', 'rocket' ), $size ), 'upload', 'help' );
1289 + ?>
1290 + </label>
1291 + <input type="hidden" name="max_file_size" value="<?php echo $bytes; ?>" />
1292 + </p>
1293 + <?php
1294 + submit_button( __( 'Upload file and import settings', 'rocket' ), 'button', 'import' );
1295 + }
1296 + }
1297 + }
1298 +
1299 + if ( ! function_exists( 'rocket_field' ) ) {
1300 + /**
1301 + * Used to display fields on settings form
1302 + *
1303 + * @since 1.0
1304 + * @deprecated 3.0
1305 + *
1306 + * @param array $args An array of arguments to populate the settings fields.
1307 + */
1308 + function rocket_field( $args ) {
1309 + _deprecated_function( __FUNCTION__, '3.0' );
1310 + if ( ! is_array( reset( $args ) ) ) {
1311 + $args = array( $args );
1312 + }
1313 +
1314 + $full = $args;
1315 +
1316 + foreach ( $full as $args ) {
1317 + if ( ! is_array( $args ) ) {
1318 + continue;
1319 + }
1320 +
1321 + if ( isset( $args['display'] ) && ! $args['display'] ) {
1322 + continue;
1323 + }
1324 + $args['label_for'] = isset( $args['label_for'] ) ? $args['label_for'] : '';
1325 + $args['name'] = isset( $args['name'] ) ? $args['name'] : $args['label_for'];
1326 + $parent = isset( $args['parent'] ) ? 'data-parent="' . sanitize_html_class( $args['parent'] ) . '"' : null;
1327 + $placeholder = isset( $args['placeholder'] ) ? 'placeholder="' . $args['placeholder'] . '" ' : '';
1328 + $class = isset( $args['class'] ) ? sanitize_html_class( $args['class'] ) : sanitize_html_class( $args['name'] );
1329 + $class .= ( $parent ) ? ' has-parent' : null;
1330 + $label = isset( $args['label'] ) ? $args['label'] : '';
1331 + $default = isset( $args['default'] ) ? $args['default'] : '';
1332 + $readonly = isset( $args['readonly'] ) && $args['readonly'] ? ' readonly="readonly" disabled="disabled"' : '';
1333 + $cols = isset( $args['cols'] ) ? (int) $args['cols'] : 50;
1334 + $rows = isset( $args['rows'] ) ? (int) $args['rows'] : 5;
1335 +
1336 + if ( ! isset( $args['fieldset'] ) || 'start' === $args['fieldset'] ) {
1337 + printf(
1338 + '<fieldset class="fieldname-%1$s fieldtype-%2$s %3$s">',
1339 + sanitize_html_class( $args['name'] ),
1340 + sanitize_html_class( $args['type'] ),
1341 + isset( $args['parent'] ) ? 'fieldparent-' . sanitize_html_class( $args['parent'] ) : ''
1342 + );
1343 + }
1344 +
1345 + switch ( $args['type'] ) {
1346 + case 'number':
1347 + case 'email':
1348 + case 'text':
1349 + $value = get_rocket_option( $args['name'] );
1350 + if ( false === $value ) {
1351 + $value = $default;
1352 + }
1353 +
1354 + $value = esc_attr( $value );
1355 + $number_options = 'number' === $args['type'] ? ' min="0" class="small-text"' : '';
1356 + $autocomplete = in_array( $args['name'], array( 'consumer_key', 'consumer_email' ), true ) ? ' autocomplete="off"' : '';
1357 + $disabled = ( 'consumer_key' === $args['name'] && defined( 'WP_ROCKET_KEY' ) ) || ( 'consumer_email' === $args['name'] && defined( 'WP_ROCKET_EMAIL' ) ) ? ' disabled="disabled"' : $readonly;
1358 + ?>
1359 +
1360 + <legend class="screen-reader-text"><span><?php echo $args['label_screen']; ?></span></legend>
1361 + <label><input<?php echo $autocomplete . $disabled; ?> type="<?php echo $args['type']; ?>"<?php echo $number_options; ?> id="<?php echo $args['label_for']; ?>" name="wp_rocket_settings[<?php echo $args['name']; ?>]" value="<?php echo $value; ?>" <?php echo $placeholder; ?><?php echo $readonly; ?>/> <?php echo $label; ?></label>
1362 +
1363 + <?php
1364 + break;
1365 +
1366 + case 'cloudflare_api_key':
1367 + $value = get_rocket_option( $args['name'] );
1368 +
1369 + if ( 'cloudflare_api_key' === $args['name'] && defined( 'WP_ROCKET_CF_API_KEY' ) ) {
1370 + $value = WP_ROCKET_CF_API_KEY;
1371 + }
1372 +
1373 + $value = esc_attr( $value );
1374 + $disabled = ( 'cloudflare_api_key' === $args['name'] && defined( 'WP_ROCKET_CF_API_KEY' ) ) ? ' disabled="disabled"' : $readonly;
1375 + $cf_valid_credentials = false;
1376 + if ( function_exists( 'rocket_cloudflare_valid_auth' ) ) {
1377 + $cf_valid_credentials = ( is_wp_error( rocket_cloudflare_valid_auth() ) ) ? false : true;
1378 + }
1379 + ?>
1380 + <legend class="screen-reader-text"><span><?php echo $args['label_screen']; ?></span></legend>
1381 + <label>
1382 + <input<?php echo $disabled; ?> type="text" id="<?php echo $args['label_for']; ?>" name="wp_rocket_settings[<?php echo $args['name']; ?>]" value="<?php echo $value; ?>" <?php echo $placeholder; ?><?php echo $readonly; ?>/> <?php echo $label; ?>
1383 + <?php if ( $cf_valid_credentials ) { ?>
1384 + <span id="rocket-check-cloudflare-api-container" class="rocket-cloudflare-api-valid">
1385 + <span class="dashicons dashicons-yes" aria-hidden="true"></span> <?php _e( 'Your Cloudflare credentials are valid.', 'rocket' ); ?>
1386 + </span>
1387 + <?php } elseif ( ! $cf_valid_credentials && $value ) { ?>
1388 + <span id="rocket-check-cloudflare-api-container">
1389 + <span class="dashicons dashicons-no" aria-hidden="true"></span> <?php _e( 'Your Cloudflare credentials are invalid!', 'rocket' ); ?>
1390 + </span>
1391 + <?php } ?>
1392 + </label>
1393 +
1394 + <?php
1395 + break;
1396 +
1397 + case 'textarea':
1398 + $t_temp = get_rocket_option( $args['name'], '' );
1399 +
1400 + if ( is_array( $t_temp ) ) {
1401 + $t_temp = implode( "\n", $t_temp );
1402 + }
1403 +
1404 + $value = ! empty( $t_temp ) ? esc_textarea( $t_temp ) : '';
1405 +
1406 + if ( ! $value ) {
1407 + $value = $default;
1408 + }
1409 + ?>
1410 +
1411 + <legend class="screen-reader-text"><span><?php echo $args['label_screen']; ?></span></legend>
1412 + <label><textarea id="<?php echo $args['label_for']; ?>" name="wp_rocket_settings[<?php echo $args['name']; ?>]" cols="<?php echo $cols; ?>" rows="<?php echo $rows; ?>" class="<?php echo $class; ?>"
1413 + <?php
1414 + echo $readonly;
1415 + echo $placeholder;
1416 + echo $parent;
1417 + ?>
1418 + ><?php echo esc_html( $value ); ?></textarea>
1419 + </label>
1420 +
1421 + <?php
1422 + break;
1423 +
1424 + case 'checkbox':
1425 + if ( isset( $args['label_screen'] ) ) {
1426 + ?>
1427 + <legend class="screen-reader-text"><span><?php echo $args['label_screen']; ?></span></legend>
1428 + <?php } ?>
1429 + <label><input type="checkbox" id="<?php echo $args['name']; ?>" class="<?php echo $class; ?>" name="wp_rocket_settings[<?php echo $args['name']; ?>]" value="1"<?php echo $readonly; ?> <?php checked( get_rocket_option( $args['name'], $default ), 1 ); ?> <?php echo $parent; ?>/> <?php echo $args['label']; ?>
1430 + </label>
1431 +
1432 + <?php
1433 + break;
1434 +
1435 + case 'select':
1436 + ?>
1437 +
1438 + <legend class="screen-reader-text"><span><?php echo $args['label_screen']; ?></span></legend>
1439 + <label> <select id="<?php echo $args['name']; ?>" class="<?php echo $class; ?>" name="wp_rocket_settings[<?php echo $args['name']; ?>]"<?php echo $readonly; ?> <?php echo $parent; ?>>
1440 + <?php foreach ( $args['options'] as $val => $title ) { ?>
1441 + <option value="<?php echo $val; ?>" <?php selected( get_rocket_option( $args['name'] ), $val ); ?>><?php echo $title; ?></option>
1442 + <?php } ?>
1443 + </select>
1444 + <?php echo $label; ?>
1445 + </label>
1446 +
1447 + <?php
1448 + break;
1449 +
1450 + case 'submit_optimize':
1451 + ?>
1452 +
1453 + <input type="submit" name="wp_rocket_settings[submit_optimize]" id="rocket_submit_optimize" class="button button-primary" value="<?php _e( 'Save and optimize', 'rocket' ); ?>"> <a href="<?php echo wp_nonce_url( admin_url( 'admin-post.php?action=rocket_optimize_database' ), 'rocket_optimize_database' ); ?>" class="button button-secondary"><?php _e( 'Optimize', 'rocket' ); ?></a>
1454 + <?php
1455 + break;
1456 +
1457 + case 'repeater':
1458 + $fields = new WP_Rocket_Repeater_Field( $args );
1459 + $fields->render();
1460 +
1461 + break;
1462 +
1463 + case 'helper_description':
1464 + $description = isset( $args['description'] ) ? sprintf( '<p class="description help %1$s" %2$s><span class="dashicons dashicons-info" aria-hidden="true"></span><strong class="screen-reader-text">%3$s</strong> %4$s</p>', $class, $parent, _x( 'Note:', 'screen-reader-text', 'rocket' ), $args['description'] ) : '';
1465 + echo apply_filters( 'rocket_help', $description, $args['name'], 'description' );
1466 +
1467 + break;
1468 +
1469 + case 'helper_performance':
1470 + $description = isset( $args['description'] ) ? sprintf( '<p class="description help tip--perf %1$s" %2$s><span class="dashicons dashicons-performance" aria-hidden="true"></span><strong class="screen-reader-text">%3$s</strong> <strong>%4$s</strong></p>', $class, $parent, _x( 'Performance tip:', 'screen-reader-text', 'rocket' ), $args['description'] ) : '';
1471 + echo apply_filters( 'rocket_help', $description, $args['name'], 'description' );
1472 +
1473 + break;
1474 +
1475 + case 'helper_detection':
1476 + $description = isset( $args['description'] ) ? sprintf( '<p class="description help tip--detect %1$s" %2$s><span class="dashicons dashicons-visibility" aria-hidden="true"></span><strong class="screen-reader-text">%3$s</strong> %4$s</p>', $class, $parent, _x( 'Third-party feature detected:', 'screen-reader-text', 'rocket' ), $args['description'] ) : '';
1477 + echo apply_filters( 'rocket_help', $description, $args['name'], 'description' );
1478 +
1479 + break;
1480 +
1481 + case 'helper_help':
1482 + $description = isset( $args['description'] ) ? sprintf( '<p class="description help tip--use %1$s" %2$s>%3$s</p>', $class, $parent, $args['description'] ) : '';
1483 + echo apply_filters( 'rocket_help', $description, $args['name'], 'help' );
1484 +
1485 + break;
1486 +
1487 + case 'helper_warning':
1488 + $description = isset( $args['description'] ) ? sprintf( '<p class="description warning file-error %1$s" %2$s><span class="dashicons dashicons-warning" aria-hidden="true"></span><strong class="screen-reader-text">%3$s</strong> %4$s</p>', $class, $parent, _x( 'Warning:', 'screen-reader-text', 'rocket' ), $args['description'] ) : '';
1489 + echo apply_filters( 'rocket_help', $description, $args['name'], 'warning' );
1490 +
1491 + break;
1492 +
1493 + case 'helper_panel_description':
1494 + $description = isset( $args['description'] ) ? sprintf( '<div class="rocket-panel-description"><p class="%1$s" %2$s>%3$s</p></div>', $class, $parent, $args['description'] ) : '';
1495 + echo $description;
1496 +
1497 + break;
1498 +
1499 + case 'rocket_export_form':
1500 + ?>
1501 + <a href="<?php echo wp_nonce_url( admin_url( 'admin-post.php?action=rocket_export' ), 'rocket_export' ); ?>" id="export" class="button button-secondary rocketicon"><?php _ex( 'Download settings', 'button text', 'rocket' ); ?></a>
1502 + <?php
1503 + break;
1504 +
1505 + case 'rocket_import_upload_form':
1506 + rocket_import_upload_form( 'rocket_importer' );
1507 +
1508 + break;
1509 + default:
1510 + 'Type manquant ou incorrect'; // ne pas traduire.
1511 +
1512 + }
1513 +
1514 + if ( ! isset( $args['fieldset'] ) || 'end' === $args['fieldset'] ) {
1515 + echo '</fieldset>';
1516 + }
1517 + }
1518 +
1519 + }
1520 + }
1521 +
1522 + if ( ! function_exists( 'rocket_cnames_module' ) ) {
1523 + /**
1524 + * Used to display the CNAMES module on settings form
1525 + *
1526 + * @since 2.1
1527 + */
1528 + function rocket_cnames_module() {
1529 + _deprecated_function( __FUNCTION__, '3.0' );
1530 + ?>
1531 + <legend class="screen-reader-text"><span><?php _e( 'Replace site\'s hostname with:', 'rocket' ); ?></span></legend>
1532 +
1533 + <div id="rkt-cnames" class="rkt-module">
1534 +
1535 + <?php
1536 +
1537 + $cnames = get_rocket_option( 'cdn_cnames' );
1538 + $cnames_zone = get_rocket_option( 'cdn_zone' );
1539 +
1540 + if ( $cnames ) {
1541 +
1542 + foreach ( $cnames as $k => $_url ) {
1543 + ?>
1544 +
1545 + <p>
1546 +
1547 + <input style="width: 32em" type="text" placeholder="http://" class="regular-text" name="wp_rocket_settings[cdn_cnames][<?php echo $k; ?>]" value="<?php echo esc_attr( $_url ); ?>" />
1548 +
1549 + <label>
1550 + <?php _e( 'reserved for', 'rocket' ); ?>
1551 + <select name="wp_rocket_settings[cdn_zone][<?php echo $k; ?>]">
1552 + <option value="all" <?php selected( $cnames_zone[ $k ], 'all' ); ?>><?php _e( 'All files', 'rocket' ); ?></option>
1553 + <?php
1554 + /**
1555 + * Controls the inclusion of images option for the CDN dropdown
1556 + *
1557 + * @since 2.10.7
1558 + * @author Remy Perona
1559 + *
1560 + * @param bool $allow true to add the option, false otherwise.
1561 + */
1562 + if ( apply_filters( 'rocket_allow_cdn_images', true ) ) :
1563 + ?>
1564 + <option value="images" <?php selected( $cnames_zone[ $k ], 'images' ); ?>><?php _e( 'Images', 'rocket' ); ?></option>
1565 + <?php endif; ?>
1566 + <option value="css_and_js" <?php selected( $cnames_zone[ $k ], 'css_and_js' ); ?>>CSS & JavaScript</option>
1567 + <option value="js" <?php selected( $cnames_zone[ $k ], 'js' ); ?>>JavaScript</option>
1568 + <option value="css" <?php selected( $cnames_zone[ $k ], 'css' ); ?>>CSS</option>
1569 + </select>
1570 + </label>
1571 + <span class="dashicons dashicons-no rkt-module-remove hide-if-no-js"></span>
1572 +
1573 + </p>
1574 +
1575 + <?php
1576 + }
1577 + } else {
1578 +
1579 + // If no files yet, use this template inside #rkt-cnames.
1580 + ?>
1581 +
1582 + <p>
1583 +
1584 + <input style="width: 32em" type="text" placeholder="http://" class="regular-text" name="wp_rocket_settings[cdn_cnames][]" value="" />
1585 +
1586 + <label>
1587 + <?php _e( 'reserved for', 'rocket' ); ?>
1588 + <select name="wp_rocket_settings[cdn_zone][]">
1589 + <option value="all"><?php _e( 'All files', 'rocket' ); ?></option>
1590 + <?php
1591 + // this filter is defined in inc/admin/options.php.
1592 + if ( apply_filters( 'rocket_allow_cdn_images', true ) ) :
1593 + ?>
1594 + <option value="images"><?php _e( 'Images', 'rocket' ); ?></option>
1595 + <?php endif; ?>
1596 + <option value="css_and_js">CSS & JavaScript</option>
1597 + <option value="js">JavaScript</option>
1598 + <option value="css">CSS</option>
1599 + </select>
1600 + </label>
1601 +
1602 + </p>
1603 +
1604 + <?php } ?>
1605 +
1606 + </div>
1607 + <?php // Clone Template. ?>
1608 + <div class="rkt-module-model hide-if-js">
1609 +
1610 + <p>
1611 +
1612 + <input style="width: 32em" type="text" placeholder="http://" class="regular-text" name="wp_rocket_settings[cdn_cnames][]" value="" />
1613 +
1614 + <label>
1615 + <?php _e( 'reserved for', 'rocket' ); ?>
1616 + <select name="wp_rocket_settings[cdn_zone][]">
1617 + <option value="all"><?php _e( 'All files', 'rocket' ); ?></option>
1618 + <?php
1619 + // this filter is defined in inc/admin/options.php.
1620 + if ( apply_filters( 'rocket_allow_cdn_images', true ) ) :
1621 + ?>
1622 + <option value="images"><?php _e( 'Images', 'rocket' ); ?></option>
1623 + <?php endif; ?>
1624 + <option value="css_and_js">CSS & JavaScript</option>
1625 + <option value="js">JavaScript</option>
1626 + <option value="css">CSS</option>
1627 + </select>
1628 + </label>
1629 + <span class="dashicons dashicons-no rkt-module-remove hide-if-no-js"></span>
1630 +
1631 + </p>
1632 +
1633 + </div>
1634 +
1635 + <p><a href="javascript:void(0)" class="rkt-module-clone hide-if-no-js button-secondary"><?php _e( 'Add CNAME', 'rocket' ); ?></a></p>
1636 +
1637 + </fieldset>
1638 +
1639 + <?php
1640 + }
1641 + }
1642 +
1643 + if ( ! function_exists( 'rocket_button' ) ) {
1644 + /**
1645 + * Used to display buttons on settings form, tools tab
1646 + *
1647 + * @since 1.1.0
1648 + * @deprecated 3.0
1649 + *
1650 + * @param array $args An array of arguments to populate the button attributes.
1651 + */
1652 + function rocket_button( $args ) {
1653 + _deprecated_function( __FUNCTION__, '3.0' );
1654 + $button = $args['button'];
1655 + $desc = isset( $args['helper_description'] ) ? $args['helper_description'] : null;
1656 + $help = isset( $args['helper_help'] ) ? $args['helper_help'] : null;
1657 + $warning = isset( $args['helper_warning'] ) ? $args['helper_warning'] : null;
1658 + $id = isset( $button['button_id'] ) ? sanitize_html_class( $button['button_id'] ) : null;
1659 + $class = sanitize_html_class( strip_tags( $button['button_label'] ) );
1660 + $button_style = isset( $button['style'] ) ? 'button-' . sanitize_html_class( $button['style'] ) : 'button-secondary';
1661 +
1662 + if ( ! empty( $help ) ) {
1663 + $help = '<p class="description help ' . $class . '">' . $help['description'] . '</p>';
1664 + }
1665 + if ( ! empty( $desc ) ) {
1666 + $desc = sprintf( '<p class="description help %1$s"><span class="dashicons dashicons-info" aria-hidden="true"></span><strong class="screen-reader-text">%2$s</strong> %3$s</p>', $class, _x( 'Note:', 'screen-reader-text', 'rocket' ), $desc['description'] );
1667 + }
1668 + if ( ! empty( $warning ) ) {
1669 + $warning = sprintf(
1670 + '<p class="description warning file-error %1$s"><span class="dashicons dashicons-warning" aria-hidden="true"></span><strong class="screen-reader-text">%2$s</strong> %3$s</p>',
1671 + $class,
1672 + _x( 'Warning:', 'screen-reader-text', 'rocket' ),
1673 + $warning['description']
1674 + );
1675 + }
1676 + ?>
1677 + <fieldset class="fieldname-<?php echo $class; ?> fieldtype-button">
1678 + <?php
1679 + if ( isset( $button['url'] ) ) {
1680 + echo '<a href="' . esc_url( $button['url'] ) . '" id="' . $id . '" class="' . $button_style . ' rocketicon rocketicon-' . $class . '">' . wp_kses_post( $button['button_label'] ) . '</a>';
1681 + } else {
1682 + echo '<button id="' . $id . '" class="' . $button_style . ' rocketicon rocketicon-' . $class . '">' . wp_kses_post( $button['button_label'] ) . '</button>';
1683 + }
1684 + ?>
1685 +
1686 +
1687 + <?php echo apply_filters( 'rocket_help', $desc, sanitize_key( strip_tags( $button['button_label'] ) ), 'description' ); ?>
1688 + <?php echo apply_filters( 'rocket_help', $help, sanitize_key( strip_tags( $button['button_label'] ) ), 'help' ); ?>
1689 + <?php echo apply_filters( 'rocket_help', $warning, sanitize_key( strip_tags( $button['button_label'] ) ), 'warning' ); ?>
1690 +
1691 + </fieldset>
1692 + <?php
1693 + }
1694 +
1695 + /**
1696 + * Used to display videos buttons on settings form
1697 + *
1698 + * @since 2.2
1699 + *
1700 + * @param array $args An array of arguments to populate the video attributes.
1701 + */
1702 + function rocket_video( $args ) {
1703 + $desc = '<p class="description desc ' . sanitize_html_class( $args['name'] ) . '">' . $args['description'] . '</p>';
1704 + ?>
1705 + <fieldset class="fieldname-<?php echo $args['name']; ?> fieldtype-button">
1706 + <a href="<?php echo esc_url( $args['url'] ); ?>" class="button-secondary fancybox rocketicon rocketicon-video"><?php _e( 'Watch the video', 'rocket' ); ?></a>
1707 + <?php echo apply_filters( 'rocket_help', $desc, $args['name'], 'description' ); ?>
1708 + </fieldset>
1709 + <?php
1710 + }
1711 + }
1712 +
1713 + if ( ! function_exists( 'rocket_display_options' ) ) {
1714 + /**
1715 + * The main settings page constructor using the required functions from WP
1716 + *
1717 + * @since 1.1.0 Add tabs, tools tab and change options severity
1718 + * @since 1.0
1719 + * @deprecated 3.0
1720 + */
1721 + function rocket_display_options() {
1722 + _deprecated_function( __FUNCTION__, '3.0' );
1723 + $modules = array(
1724 + 'api-key',
1725 + 'basic',
1726 + 'advanced',
1727 + 'optimization',
1728 + 'database',
1729 + 'preload',
1730 + 'cloudflare',
1731 + 'cdn',
1732 + 'varnish',
1733 + 'tools',
1734 + 'support',
1735 + );
1736 +
1737 + foreach ( $modules as $module ) {
1738 + require WP_ROCKET_ADMIN_UI_MODULES_PATH . $module . '.php';
1739 + }
1740 +
1741 + $heading_tag = version_compare( $GLOBALS['wp_version'], '4.3' ) >= 0 ? 'h1' : 'h2';
1742 + ?>
1743 +
1744 + <div class="wrap">
1745 +
1746 + <<?php echo $heading_tag; ?>><?php echo WP_ROCKET_PLUGIN_NAME; ?> <small><sup><?php echo WP_ROCKET_VERSION; ?></sup></small></<?php echo $heading_tag; ?>>
1747 + <form action="options.php" id="rocket_options" method="post" enctype="multipart/form-data">
1748 + <?php
1749 + settings_fields( 'wp_rocket' );
1750 +
1751 + rocket_hidden_fields(
1752 + array(
1753 + 'consumer_key',
1754 + 'consumer_email',
1755 + 'secret_key',
1756 + 'license',
1757 + 'secret_cache_key',
1758 + 'minify_css_key',
1759 + 'minify_js_key',
1760 + 'version',
1761 + 'cloudflare_old_settings',
1762 + 'cloudflare_zone_id',
1763 + 'sitemap_preload_url_crawl',
1764 + )
1765 + );
1766 +
1767 + submit_button();
1768 + ?>
1769 + <h2 class="nav-tab-wrapper hide-if-no-js">
1770 + <?php if ( rocket_valid_key() ) { ?>
1771 + <a href="#tab_basic" class="nav-tab"><?php _e( 'Basic', 'rocket' ); ?></a>
1772 + <a href="#tab_optimization" class="nav-tab"><?php _e( 'Static Files', 'rocket' ); ?></a>
1773 + <a href="#tab_cdn" class="nav-tab"><?php _e( 'CDN', 'rocket' ); ?></a>
1774 + <a href="#tab_advanced" class="nav-tab"><?php _e( 'Advanced', 'rocket' ); ?></a>
1775 + <a href="#tab_database" class="nav-tab"><?php _e( 'Database', 'rocket' ); ?></a>
1776 + <a href="#tab_preload" class="nav-tab"><?php _e( 'Preload', 'rocket' ); ?></a>
1777 + <?php if ( get_rocket_option( 'do_cloudflare' ) ) { ?>
1778 + <a href="#tab_cloudflare" class="nav-tab">Cloudflare</a>
1779 + <?php
1780 + }
1781 + /** This filter is documented in inc/admin/ui/modules/vanrish.php */
1782 + if ( apply_filters( 'rocket_display_varnish_options_tab', true ) ) {
1783 + ?>
1784 + <a href="#tab_varnish" class="nav-tab">Varnish</a>
1785 + <?php } ?>
1786 + <a href="#tab_tools" class="nav-tab"><?php _e( 'Tools', 'rocket' ); ?></a>
1787 + <a href="#tab_support" class="nav-tab"><?php _e( 'Support', 'rocket' ); ?></a>
1788 + <?php } else { ?>
1789 + <a href="#tab_apikey" class="nav-tab"><?php _e( 'License', 'rocket' ); ?></a>
1790 + <?php } ?>
1791 + <?php
1792 + do_action( 'rocket_tab', rocket_valid_key() );
1793 + ?>
1794 + </h2>
1795 + <div id="rockettabs">
1796 + <?php if ( rocket_valid_key() ) { ?>
1797 + <div class="rkt-tab" id="tab_basic"><?php do_settings_sections( 'rocket_basic' ); ?></div>
1798 + <div class="rkt-tab" id="tab_optimization"><?php do_settings_sections( 'rocket_optimization' ); ?></div>
1799 + <div class="rkt-tab" id="tab_cdn"><?php do_settings_sections( 'rocket_cdn' ); ?></div>
1800 + <div class="rkt-tab" id="tab_advanced"><?php do_settings_sections( 'rocket_advanced' ); ?></div>
1801 + <div class="rkt-tab" id="tab_database"><?php do_settings_sections( 'rocket_database' ); ?></div>
1802 + <div class="rkt-tab" id="tab_preload"><?php do_settings_sections( 'rocket_preload' ); ?></div>
1803 + <div class="rkt-tab" id="tab_cloudflare" <?php echo get_rocket_option( 'do_cloudflare' ) ? '' : 'style="display:none"'; ?>><?php do_settings_sections( 'rocket_cloudflare' ); ?></div>
1804 + <?php
1805 + /** This filter is documented in inc/admin/ui/modules/vanrish.php */
1806 + if ( apply_filters( 'rocket_display_varnish_options_tab', true ) ) {
1807 + ?>
1808 + <div class="rkt-tab" id="tab_varnish"><?php do_settings_sections( 'rocket_varnish' ); ?></div>
1809 + <?php } ?>
1810 + <div class="rkt-tab" id="tab_tools"><?php do_settings_sections( 'rocket_tools' ); ?></div>
1811 + <div class="rkt-tab rkt-tab-txt" id="tab_support"><?php do_settings_sections( 'rocket_support' ); ?></div>
1812 + <?php } else { ?>
1813 + <div class="rkt-tab" id="tab_apikey"><?php do_settings_sections( 'rocket_apikey' ); ?></div>
1814 + <?php } ?>
1815 + <?php
1816 + do_action( 'rocket_tab_content', rocket_valid_key() );
1817 + ?>
1818 + </div>
1819 + <?php submit_button(); ?>
1820 + </form>
1821 + <?php
1822 + }
1823 + }
1824 +
1825 + if ( ! function_exists( 'rocket_hidden_fields' ) ) {
1826 + /**
1827 + * Function used to print all hidden fields from rocket to avoid the loss of these.
1828 + *
1829 + * @since 2.1
1830 + * @deprecated 3.0
1831 + *
1832 + * @param array $fields An array of fields to add to WP Rocket settings.
1833 + */
1834 + function rocket_hidden_fields( $fields ) {
1835 + _deprecated_function( __FUNCTION__, '3.0', 'WP_Rocket\Admin\Render->render_hidden_fields()' );
1836 + if ( ! is_array( $fields ) ) {
1837 + return;
1838 + }
1839 +
1840 + foreach ( $fields as $field ) {
1841 + echo '<input type="hidden" name="wp_rocket_settings[' . $field . ']" value="' . esc_attr( get_rocket_option( $field ) ) . '" />';
1842 + }
1843 + }
1844 + }
1845 +
1846 + if ( ! function_exists( 'wp_ajax_rocket_new_ticket_support' ) ) {
1847 + /**
1848 + * Open a ticket support.
1849 + *
1850 + * @since 2.6
1851 + * @deprecated 3.0
1852 + */
1853 + function wp_ajax_rocket_new_ticket_support() {
1854 + _deprecated_function( __FUNCTION__, '3.0' );
1855 + // rocket_capability is a typo (should have been rocket_capacity).
1856 + if ( ! isset( $_POST['_wpnonce'], $_POST['summary'], $_POST['description'] ) || ! wp_verify_nonce( $_POST['_wpnonce'], 'wp_rocket-options' ) ||
1857 + ! current_user_can( apply_filters_deprecated( 'rocket_capability', array( 'manage_options' ), '2.8.9', 'rocket_capacity' ) ) ||
1858 + ! current_user_can( apply_filters( 'rocket_capacity', 'manage_options' ) )
1859 + ) {
1860 + return;
1861 + }
1862 +
1863 + $response = wp_remote_post(
1864 + WP_ROCKET_WEB_API . 'support/new-ticket.php',
1865 + array(
1866 + 'timeout' => 10,
1867 + 'body' => array(
1868 + 'data' => array(
1869 + 'user_email' => defined( 'WP_ROCKET_EMAIL' ) ? sanitize_email( WP_ROCKET_EMAIL ) : '',
1870 + 'user_key' => defined( 'WP_ROCKET_KEY' ) ? sanitize_key( WP_ROCKET_KEY ) : '',
1871 + 'user_website' => home_url(),
1872 + 'wp_version' => $GLOBALS['wp_version'],
1873 + 'wp_active_plugins' => rocket_get_active_plugins(),
1874 + 'wp_rocket_version' => WP_ROCKET_VERSION,
1875 + 'wp_rocket_options' => get_option( WP_ROCKET_SLUG ),
1876 + 'support_summary' => $_POST['summary'],
1877 + 'support_description' => $_POST['description'],
1878 + ),
1879 + ),
1880 + )
1881 + );
1882 +
1883 + if ( ! is_wp_error( $response ) ) {
1884 + wp_send_json( wp_remote_retrieve_body( $response ) );
1885 + } else {
1886 + wp_send_json(
1887 + array(
1888 + 'msg' => 'BAD_SERVER',
1889 + )
1890 + );
1891 + }
1892 + }
1893 + }
1894 +
1895 + if ( ! function_exists( 'wp_ajax_rocket_helpscout_live_search' ) ) {
1896 + /**
1897 + * Documentation suggestions based on the summary input from the new ticket support form.
1898 + *
1899 + * @since 2.6
1900 + * @deprecated 3.0
1901 + */
1902 + function wp_ajax_rocket_helpscout_live_search() {
1903 + _deprecated_function( __FUNCTION__, '3.0' );
1904 + if ( current_user_can( apply_filters( 'rocket_capability', 'manage_options' ) ) ) {
1905 + $query = filter_input( INPUT_POST, 'query' );
1906 + $response = wp_remote_post(
1907 + WP_ROCKET_WEB_MAIN . 'tools/wp-rocket/helpscout/livesearch.php',
1908 + array(
1909 + 'timeout' => 10,
1910 + 'body' => array(
1911 + 'query' => esc_html( wp_strip_all_tags( $query, true ) ),
1912 + 'lang' => get_locale(),
1913 + ),
1914 + )
1915 + );
1916 +
1917 + if ( ! is_wp_error( $response ) ) {
1918 + wp_send_json( wp_remote_retrieve_body( $response ) );
1919 + }
1920 + }
1921 + }
1922 + }
1923 +
1924 + if ( ! function_exists( 'rocket_php_warning' ) ) {
1925 + /**
1926 + * Warns if PHP version is less than 5.3 and offers to rollback.
1927 + *
1928 + * @since 2.11
1929 + * @deprecated 3.0
1930 + * @see WP_Rocket_Requirements_check::notice();
1931 + * @author Remy Perona
1932 + */
1933 + function rocket_php_warning() {
1934 + _deprecated_function( __FUNCTION__, '3.0', 'WP_Rocket_Requirements_check::notice()' );
1935 +
1936 + if ( version_compare( PHP_VERSION, '5.3' ) >= 0 ) {
1937 + return;
1938 + }
1939 + /** This filter is documented in inc/admin-bar.php */
1940 + if ( ! current_user_can( apply_filters( 'rocket_capacity', 'manage_options' ) ) ) {
1941 + return;
1942 + }
1943 + // Translators: %1$s = Plugin name, %2$s = Plugin version, %3$s = PHP version required.
1944 + echo '<div class="notice notice-error"><p>' . sprintf( __( '%1$s %2$s requires at least PHP %3$s to function properly. To use this version, please ask your web host how to upgrade your server to PHP %3$s or higher. If you are not able to upgrade, you can rollback to the previous version by using the button below.', 'rocket' ), WP_ROCKET_PLUGIN_NAME, WP_ROCKET_VERSION, '5.3' ) . '</p>
1945 + <p><a href="' . wp_nonce_url( admin_url( 'admin-post.php?action=rocket_rollback' ), 'rocket_rollback' ) . '" class="button">' .
1946 + // Translators: %s = Previous plugin version.
1947 + sprintf( __( 'Re-install version %s', 'rocket' ), WP_ROCKET_LASTVERSION )
1948 + . '</a></p></div>';
1949 + }
1950 + }
1951 +
1952 + if ( ! function_exists( 'rocket_get_home_path' ) ) {
1953 + /**
1954 + * Get the absolute filesystem path to the root of the WordPress installation.
1955 + *
1956 + * @since 2.11.7 copy function get_home_path() from WP core.
1957 + * @since 2.11.5
1958 + * @deprecated 3.0
1959 + *
1960 + * @author Chris Williams
1961 + *
1962 + * @return string Full filesystem path to the root of the WordPress installation.
1963 + */
1964 + function rocket_get_home_path() {
1965 + _deprecated_function( __FUNCTION__, '3.0' );
1966 + $home = set_url_scheme( get_option( 'home' ), 'http' );
1967 + $siteurl = set_url_scheme( get_option( 'siteurl' ), 'http' );
1968 + $home_path = ABSPATH;
1969 +
1970 + if ( ! empty( $home ) && 0 !== strcasecmp( $home, $siteurl ) ) {
1971 + $wp_path_rel_to_home = str_ireplace( $home, '', $siteurl ); /* $siteurl - $home */
1972 + $pos = strripos( str_replace( '\\', '/', $_SERVER['SCRIPT_FILENAME'] ), trailingslashit( $wp_path_rel_to_home ) );
1973 + $home_path = substr( $_SERVER['SCRIPT_FILENAME'], 0, $pos );
1974 + $home_path = trailingslashit( $home_path );
1975 + }
1976 +
1977 + return str_replace( '\\', '/', $home_path );
1978 + }
1979 + }
1980 +
1981 + if ( ! function_exists( 'rocket_clean_cache_after_woocommerce_save_product_variation' ) ) {
1982 + /**
1983 + * Clean product cache on variation update
1984 + *
1985 + * @since 2.9
1986 + * @deprecated 3.1
1987 + * @see WP_Rocket\Third_Party\Plugins\Ecommerce\WooCommerce::clean_cache_after_woocommerce_save_product_variation()
1988 + * @author Remy Perona
1989 + *
1990 + * @param int $variation_id ID of the variation.
1991 + */
1992 + function rocket_clean_cache_after_woocommerce_save_product_variation( $variation_id ) {
1993 + _deprecated_function( __FUNCTION__, '3.1', 'WP_Rocket\Third_Party\Plugins\Ecommerce\WooCommerce::clean_cache_after_woocommerce_save_product_variation()' );
1994 + $product_id = wp_get_post_parent_id( $variation_id );
1995 + if ( $product_id ) {
1996 + rocket_clean_post( $product_id );
1997 + }
1998 + }
1999 + }
2000 +
2001 + if ( ! function_exists( 'rocket_cache_v_query_string' ) ) {
2002 + /**
2003 + * Automatically cache v query string when WC geolocation with cache compatibility option is active
2004 + *
2005 + * @since 2.8.6
2006 + * @deprecated 3.1
2007 + * @see WP_Rocket\Third_Party\Plugins\Ecommerce\WooCommerce::cache_geolocation_query_string()
2008 + * @author Rémy Perona
2009 + *
2010 + * @param array $query_strings list of query strings to cache.
2011 + * @return array Updated list of query strings to cache
2012 + */
2013 + function rocket_cache_v_query_string( $query_strings ) {
2014 + _deprecated_function( __FUNCTION__, '3.1', 'WP_Rocket\Third_Party\Plugins\Ecommerce\WooCommerce::cache_geolocation_query_string()' );
2015 + if ( 'geolocation_ajax' === get_option( 'woocommerce_default_customer_address' ) ) {
2016 + $query_strings[] = 'v';
2017 + }
2018 +
2019 + return $query_strings;
2020 + }
2021 + }
2022 +
2023 + if ( ! function_exists( 'rocket_exclude_woocommerce_pages' ) ) {
2024 + /**
2025 + * Exclude WooCommerce cart, checkout and account pages from caching
2026 + *
2027 + * @since 2.11 Moved to 3rd party
2028 + * @since 2.4
2029 + * @deprecated 3.1
2030 + * @see WP_Rocket\Third_Party\Plugins\Ecommerce\WooCommerce::exclude_pages()
2031 + *
2032 + * @param array $urls An array of excluded pages.
2033 + * @return array Updated array of excluded pages
2034 + */
2035 + function rocket_exclude_woocommerce_pages( $urls ) {
2036 + _deprecated_function( __FUNCTION__, '3.1', 'WP_Rocket\Third_Party\Plugins\Ecommerce\WooCommerce::exclude_pages()' );
2037 + if ( function_exists( 'WC' ) && function_exists( 'wc_get_page_id' ) ) {
2038 + if ( wc_get_page_id( 'checkout' ) && wc_get_page_id( 'checkout' ) !== -1 && wc_get_page_id( 'checkout' ) !== (int) get_option( 'page_on_front' ) ) {
2039 + $checkout_urls = get_rocket_i18n_translated_post_urls( wc_get_page_id( 'checkout' ), 'page', '(.*)' );
2040 + $urls = array_merge( $urls, $checkout_urls );
2041 + }
2042 +
2043 + if ( wc_get_page_id( 'cart' ) && wc_get_page_id( 'cart' ) !== -1 && wc_get_page_id( 'cart' ) !== (int) get_option( 'page_on_front' ) ) {
2044 + $cart_urls = get_rocket_i18n_translated_post_urls( wc_get_page_id( 'cart' ) );
2045 + $urls = array_merge( $urls, $cart_urls );
2046 + }
2047 +
2048 + if ( wc_get_page_id( 'myaccount' ) && wc_get_page_id( 'myaccount' ) !== -1 && wc_get_page_id( 'myaccount' ) !== (int) get_option( 'page_on_front' ) ) {
2049 + $cart_urls = get_rocket_i18n_translated_post_urls( wc_get_page_id( 'myaccount' ), 'page', '(.*)' );
2050 + $urls = array_merge( $urls, $cart_urls );
2051 + }
2052 + }
2053 +
2054 + return $urls;
2055 + }
2056 + }
2057 +
2058 + if ( ! function_exists( 'rocket_activate_woocommerce' ) ) {
2059 + /**
2060 + * Add query string to exclusion when activating the plugin
2061 + *
2062 + * @since 2.8.6
2063 + * @deprecated 3.1
2064 + * @see WP_Rocket\Third_Party\Plugins\Ecommerce\WooCommerce::activate_woocommerce()
2065 + * @author Rémy Perona
2066 + */
2067 + function rocket_activate_woocommerce() {
2068 + _deprecated_function( __FUNCTION__, '3.1', 'WP_Rocket\Third_Party\Plugins\Ecommerce\WooCommerce::activate_woocommerce()' );
2069 + add_filter( 'rocket_cache_reject_uri', 'rocket_exclude_woocommerce_pages' );
2070 + add_filter( 'rocket_cache_query_strings', 'rocket_cache_v_query_string' );
2071 +
2072 + // Update .htaccess file rules.
2073 + flush_rocket_htaccess();
2074 +
2075 + // Regenerate the config file.
2076 + rocket_generate_config_file();
2077 + }
2078 + }
2079 +
2080 + if ( ! function_exists( 'rocket_deactivate_woocommerce' ) ) {
2081 + /**
2082 + * Remove query string from exclusion when deactivating the plugin
2083 + *
2084 + * @since 2.8.6
2085 + * @deprecated 3.1
2086 + * @see WP_Rocket\Third_Party\Plugins\Ecommerce\WooCommerce::deactivate_woocommerce()
2087 + * @author Rémy Perona
2088 + */
2089 + function rocket_deactivate_woocommerce() {
2090 + _deprecated_function( __FUNCTION__, '3.1', 'WP_Rocket\Third_Party\Plugins\Ecommerce\WooCommerce::deactivate_woocommerce()' );
2091 + remove_filter( 'rocket_cache_reject_uri', 'rocket_exclude_woocommerce_pages' );
2092 + remove_filter( 'rocket_cache_query_strings', 'rocket_cache_v_query_string' );
2093 +
2094 + // Update .htaccess file rules.
2095 + flush_rocket_htaccess();
2096 +
2097 + // Regenerate the config file.
2098 + rocket_generate_config_file();
2099 + }
2100 + }
2101 +
2102 + if ( ! function_exists( 'rocket_exclude_wc_rest_api' ) ) {
2103 + /**
2104 + * Exclude WooCommerce REST API URL from cache
2105 + *
2106 + * @since 2.6.5
2107 + * @deprecated 3.1
2108 + * @see WP_Rocket\Third_Party\Plugins\Ecommerce\WooCommerce::exclude_wc_rest_api()
2109 + *
2110 + * @param array $uri URLs to exclude from cache.
2111 + * @return array Updated list of URLs to exclude from cache
2112 + */
2113 + function rocket_exclude_wc_rest_api( $uri ) {
2114 + _deprecated_function( __FUNCTION__, '3.1', 'WP_Rocket\Third_Party\Plugins\Ecommerce\WooCommerce::exclude_wc_rest_api()' );
2115 + /**
2116 + * By default, don't cache the WooCommerce REST API.
2117 + *
2118 + * @since 2.6.5
2119 + *
2120 + * @param bool false will force to cache the WooCommerce REST API
2121 + */
2122 + $rocket_cache_reject_wc_rest_api = apply_filters( 'rocket_cache_reject_wc_rest_api', true );
2123 +
2124 + // Exclude WooCommerce REST API.
2125 + if ( $rocket_cache_reject_wc_rest_api ) {
2126 + $uri[] = rocket_clean_exclude_file( home_url( '/wc-api/v(.*)' ) );
2127 + }
2128 +
2129 + return $uri;
2130 + }
2131 + }
2132 +
2133 + if ( ! function_exists( 'rocket_minify_process' ) ) {
2134 + /**
2135 + * Launch WP Rocket minification process (HTML, CSS and JavaScript)
2136 + *
2137 + * @since 2.10 New process for minification without concatenation
2138 + * @since 1.3.0 This process is called via the new filter rocket_buffer
2139 + * @since 1.1.6 Minify inline CSS and JavaScript
2140 + * @since 1.0
2141 + * @deprecated 3.1
2142 + *
2143 + * @param string $buffer HTML content.
2144 + * @return string Modified HTML content
2145 + */
2146 + function rocket_minify_process( $buffer ) {
2147 + _deprecated_function( __FUNCTION__, '3.1' );
2148 +
2149 + $enable_css = get_rocket_option( 'minify_css' );
2150 + $enable_js = get_rocket_option( 'minify_js' );
2151 + $enable_google_fonts = get_rocket_option( 'minify_google_fonts' );
2152 +
2153 + if ( $enable_css || $enable_js || $enable_google_fonts ) {
2154 + list( $buffer, $conditionals ) = rocket_extract_ie_conditionals( $buffer );
2155 + }
2156 +
2157 + // Minify JavaScript.
2158 + if ( $enable_js && ( ! defined( 'DONOTROCKETOPTIMIZE' ) || ! DONOTROCKETOPTIMIZE ) && ( ! defined( 'DONOTMINIFYJS' ) || ! DONOTMINIFYJS ) && ! is_rocket_post_excluded_option( 'minify_js' ) ) {
2159 + $buffer = rocket_minify_files( $buffer, 'js' );
2160 + }
2161 +
2162 + // Minify CSS.
2163 + if ( $enable_css && ( ! defined( 'DONOTROCKETOPTIMIZE' ) || ! DONOTROCKETOPTIMIZE ) && ( ! defined( 'DONOTMINIFYCSS' ) || ! DONOTMINIFYCSS ) && ! is_rocket_post_excluded_option( 'minify_css' ) ) {
2164 + $buffer = rocket_minify_files( $buffer, 'css' );
2165 + }
2166 +
2167 + // Concatenate Google Fonts.
2168 + if ( $enable_google_fonts ) {
2169 + $buffer = rocket_concatenate_google_fonts( $buffer );
2170 + }
2171 +
2172 + if ( $enable_css || $enable_js || $enable_google_fonts ) {
2173 + $buffer = rocket_inject_ie_conditionals( $buffer, $conditionals );
2174 + }
2175 +
2176 + return $buffer;
2177 + }
2178 + }
2179 +
2180 + if ( ! function_exists( 'rocket_minify_html' ) ) {
2181 + /**
2182 + * Minifies inline HTML
2183 + *
2184 + * @since 2.10 Do the HTML minification independently and hook it later to prevent conflicts
2185 + * @since 1.1.12
2186 + * @deprecated 3.1
2187 + *
2188 + * @param string $buffer HTML content.
2189 + * @return string Updated HTML content
2190 + */
2191 + function rocket_minify_html( $buffer ) {
2192 + _deprecated_function( __FUNCTION__, '3.1' );
2193 +
2194 + if ( ! get_rocket_option( 'minify_html' ) || is_rocket_post_excluded_option( 'minify_html' ) ) {
2195 + return $buffer;
2196 + }
2197 +
2198 + $html_options = array(
2199 + 'cssMinifier' => 'rocket_minify_inline_css',
2200 + );
2201 +
2202 + /**
2203 + * Filter options of minify inline HTML
2204 + *
2205 + * @since 1.1.12
2206 + *
2207 + * @param array $html_options Options of minify inline HTML.
2208 + */
2209 + $html_options = apply_filters( 'rocket_minify_html_options', $html_options );
2210 +
2211 + return Minify_HTML::minify( $buffer, $html_options );
2212 + }
2213 + }
2214 +
2215 + if ( ! function_exists( 'rocket_fix_ssl_minify' ) ) {
2216 + /**
2217 + * Fix issue with SSL and minification
2218 + *
2219 + * @since 2.3
2220 + * @deprecated 3.1
2221 + *
2222 + * @param string $url An url to filter to set the scheme to https if needed.
2223 + * @return string Updated URL
2224 + */
2225 + function rocket_fix_ssl_minify( $url ) {
2226 + _deprecated_function( __FUNCTION__, '3.1' );
2227 +
2228 + if ( is_ssl() && false === strpos( $url, 'https://' ) && ! in_array( rocket_extract_url_component( $url, PHP_URL_HOST ), get_rocket_cnames_host( array( 'all', 'css_js', 'css', 'js' ) ), true ) ) {
2229 + $url = str_replace( 'http://', 'https://', $url );
2230 + }
2231 +
2232 + return $url;
2233 + }
2234 + }
2235 +
2236 + if ( ! function_exists( 'rocket_minify_i18n_multidomain' ) ) {
2237 + /**
2238 + * Compatibility with multilingual plugins & multidomain configuration
2239 + *
2240 + * @since 2.6.13 Regression Fix: Apply CDN on minified CSS and JS files by checking the CNAME host
2241 + * @since 2.6.8
2242 + * @deprecated 3.1
2243 + *
2244 + * @param string $url Minified file URL.
2245 + * @return string Updated minified file URL
2246 + */
2247 + function rocket_minify_i18n_multidomain( $url ) {
2248 + _deprecated_function( __FUNCTION__, '3.1' );
2249 +
2250 + if ( ! rocket_has_i18n() ) {
2251 + return $url;
2252 + }
2253 +
2254 + $url_host = rocket_extract_url_component( $url, PHP_URL_HOST );
2255 + $zone = array( 'all', 'css_and_js' );
2256 + $current_filter = current_filter();
2257 +
2258 + // Add only CSS zone.
2259 + if ( 'rocket_css_url' === $current_filter ) {
2260 + $zone[] = 'css';
2261 + }
2262 +
2263 + // Add only JS zone.
2264 + if ( 'rocket_js_url' === $current_filter ) {
2265 + $zone[] = 'js';
2266 + }
2267 +
2268 + $cnames = get_rocket_cdn_cnames( $zone );
2269 + $cnames = array_map( 'rocket_remove_url_protocol' , $cnames );
2270 +
2271 + if ( $url_host !== $_SERVER['HTTP_HOST'] && in_array( $_SERVER['HTTP_HOST'], get_rocket_i18n_host(), true ) && ! in_array( $url_host, $cnames, true ) ) {
2272 + $url = str_replace( $url_host, $_SERVER['HTTP_HOST'], $url );
2273 + }
2274 +
2275 + return $url;
2276 + }
2277 + }
2278 +
2279 + if ( ! function_exists( 'rocket_get_js_enqueued_in_head' ) ) {
2280 + /**
2281 + * Get all src for JS files already enqueued in head
2282 + *
2283 + * @since 2.10
2284 + * @deprecated 3.1
2285 + * @author Remy Perona
2286 + */
2287 + function rocket_get_js_enqueued_in_head() {
2288 + _deprecated_function( __FUNCTION__, '3.1' );
2289 +
2290 + global $wp_scripts, $rocket_js_enqueued_in_head;
2291 +
2292 + if ( ! (bool) $wp_scripts->done ) {
2293 + return;
2294 + }
2295 +
2296 + foreach ( $wp_scripts->done as $handle ) {
2297 + if ( ! empty( $wp_scripts->registered[ $handle ]->src ) ) {
2298 + $rocket_js_enqueued_in_head[] = str_replace( '#', '\#', rocket_clean_exclude_file( $wp_scripts->registered[ $handle ]->src ) );
2299 + }
2300 + }
2301 + }
2302 + }
2303 +
2304 + if ( ! function_exists( 'get_rocket_exclude_files' ) ) {
2305 + /**
2306 + * Get all files to exclude from minification/concatenation.
2307 + *
2308 + * @since 2.11
2309 + * @deprecated 3.1
2310 + * @author Remy Perona
2311 + *
2312 + * @param string $extension Type of files to exclude.
2313 + * @return array Array of excluded files.
2314 + */
2315 + function get_rocket_exclude_files( $extension ) {
2316 + _deprecated_function( __FUNCTION__, '3.1' );
2317 +
2318 + if ( 'css' === $extension ) {
2319 + $excluded_files = get_rocket_option( 'exclude_css', array() );
2320 + /**
2321 + * Filters CSS files to exclude from minification/concatenation.
2322 + *
2323 + * @since 2.6
2324 + *
2325 + * @param array $excluded_files List of excluded CSS files.
2326 + */
2327 + $excluded_files = apply_filters( 'rocket_exclude_css', $excluded_files );
2328 + } elseif ( 'js' === $extension ) {
2329 + global $wp_scripts;
2330 +
2331 + $excluded_files = get_rocket_option( 'exclude_js', array() );
2332 +
2333 + if ( get_rocket_option( 'defer_all_js', 0 ) && get_rocket_option( 'defer_all_js_safe', 0 ) ) {
2334 + $excluded_files[] = rocket_clean_exclude_file( site_url( $wp_scripts->registered['jquery-core']->src ) );
2335 + }
2336 +
2337 + /**
2338 + * Filter JS files to exclude from minification/concatenation.
2339 + *
2340 + * @since 2.6
2341 + *
2342 + * @param array $js_files List of excluded JS files.
2343 + */
2344 + $excluded_files = apply_filters( 'rocket_exclude_js', $excluded_files );
2345 + }
2346 +
2347 + return $excluded_files;
2348 + }
2349 + }
2350 +
2351 + if ( ! function_exists( 'rocket_concatenate_google_fonts' ) ) {
2352 + /**
2353 + * Concatenates Google Fonts tags (http://fonts.googleapis.com/css?...)
2354 + *
2355 + * @since 2.3
2356 + * @deprecated 3.1
2357 + *
2358 + * @param string $buffer HTML content.
2359 + * @return string Modified HTML content
2360 + */
2361 + function rocket_concatenate_google_fonts( $buffer ) {
2362 + _deprecated_function( __FUNCTION__, '3.1' );
2363 +
2364 + // Get all Google Fonts CSS files.
2365 + $buffer_without_comments = preg_replace( '/<!--(.*)-->/Uis', '', $buffer );
2366 + preg_match_all( '/<link(?:\s+(?:(?!href\s*=\s*)[^>])+)?(?:\s+href\s*=\s*([\'"])((?:https?:)?\/\/fonts\.googleapis\.com\/css(?:(?!\1).)+)\1)(?:\s+[^>]*)?>/iU', $buffer_without_comments, $matches );
2367 +
2368 + if ( ! $matches[2] || 1 === count( $matches ) ) {
2369 + return $buffer;
2370 + }
2371 +
2372 + $fonts = array();
2373 + $subsets = array();
2374 +
2375 + foreach ( $matches[2] as $k => $font ) {
2376 + // Get fonts name.
2377 + $font = str_replace( array( '%7C', '%7c' ), '|', $font );
2378 + $font = explode( 'family=', $font );
2379 + $font = ( isset( $font[1] ) ) ? explode( '&', $font[1] ) : array();
2380 +
2381 + // Add font to the collection.
2382 + $fonts = array_merge( $fonts, explode( '|', reset( $font ) ) );
2383 +
2384 + // Add subset to collection.
2385 + $subset = ( is_array( $font ) ) ? end( $font ) : '';
2386 + if ( false !== strpos( $subset, 'subset=' ) ) {
2387 + $subset = explode( 'subset=', $subset );
2388 + $subsets = array_merge( $subsets, explode( ',', $subset[1] ) );
2389 + }
2390 +
2391 + // Delete the Google Fonts tag.
2392 + $buffer = str_replace( $matches[0][ $k ], '', $buffer );
2393 + }
2394 +
2395 + // Concatenate fonts tag.
2396 + $subsets = ( $subsets ) ? '&subset=' . implode( ',', array_filter( array_unique( $subsets ) ) ) : '';
2397 + $fonts = implode( '|', array_filter( array_unique( $fonts ) ) );
2398 + $fonts = str_replace( '|', '%7C', $fonts );
2399 +
2400 + if ( ! empty( $fonts ) ) {
2401 + $fonts = '<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=' . $fonts . $subsets . '" />';
2402 + $buffer = preg_replace( '/<head(.*)>/U', '<head$1>' . $fonts, $buffer, 1 );
2403 + }
2404 +
2405 + return $buffer;
2406 + }
2407 + }
2408 +
2409 + if ( ! function_exists( 'rocket_minify_inline_css' ) ) {
2410 + /**
2411 + * Minifies inline CSS
2412 + *
2413 + * @since 1.1.6
2414 + * @deprecated 3.1
2415 + *
2416 + * @param string $css HTML content.
2417 + * @return string Updated HTML content
2418 + */
2419 + function rocket_minify_inline_css( $css ) {
2420 + _deprecated_function( __FUNCTION__, '3.1' );
2421 +
2422 + $minify = new Minify\CSS( $css );
2423 + return $minify->minify();
2424 + }
2425 + }
2426 +
2427 + if ( ! function_exists( 'rocket_minify_inline_js' ) ) {
2428 + /**
2429 + * Minifies inline JavaScript
2430 + *
2431 + * @since 1.1.6
2432 + * @deprecated 3.1
2433 + *
2434 + * @param string $js HTML content.
2435 + * @return string Updated HTML content
2436 + */
2437 + function rocket_minify_inline_js( $js ) {
2438 + _deprecated_function( __FUNCTION__, '3.1' );
2439 +
2440 + $minify = new Minify\JS( $js );
2441 + return $minify->minify();
2442 + }
2443 + }
2444 +
2445 + if ( ! function_exists( 'rocket_extract_ie_conditionals' ) ) {
2446 + /**
2447 + * Extracts IE conditionals tags and replace them with placeholders
2448 + *
2449 + * @since 1.0
2450 + * @deprecated 3.1
2451 + *
2452 + * @param string $buffer HTML content.
2453 + * @return string Updated HTML content
2454 + */
2455 + function rocket_extract_ie_conditionals( $buffer ) {
2456 + _deprecated_function( __FUNCTION__, '3.1' );
2457 +
2458 + preg_match_all( '/<!--\[if[^\]]*?\]>.*?<!\[endif\]-->/is', $buffer, $conditionals_match );
2459 + $buffer = preg_replace( '/<!--\[if[^\]]*?\]>.*?<!\[endif\]-->/is', '{{WP_ROCKET_CONDITIONAL}}', $buffer );
2460 +
2461 + $conditionals = array();
2462 + foreach ( $conditionals_match[0] as $conditional ) {
2463 + $conditionals[] = $conditional;
2464 + }
2465 +
2466 + return array( $buffer, $conditionals );
2467 + }
2468 + }
2469 +
2470 + if ( ! function_exists( 'rocket_inject_ie_conditionals' ) ) {
2471 + /**
2472 + * Replaces WP Rocket placeholders with IE conditional tags
2473 + *
2474 + * @since 1.0
2475 + * @deprecated 3.1
2476 + *
2477 + * @param string $buffer HTML content.
2478 + * @param array $conditionals An array of HTML conditional tags.
2479 + * @return string Updated HTML content
2480 + */
2481 + function rocket_inject_ie_conditionals( $buffer, $conditionals ) {
2482 + _deprecated_function( __FUNCTION__, '3.1' );
2483 +
2484 + foreach ( $conditionals as $conditional ) {
2485 + if ( false !== strpos( $buffer, '{{WP_ROCKET_CONDITIONAL}}' ) ) {
2486 + $buffer = preg_replace( '/{{WP_ROCKET_CONDITIONAL}}/', $conditional, $buffer, 1 );
2487 + } else {
2488 + break;
2489 + }
2490 + }
2491 + return $buffer;
2492 + }
2493 + }
2494 +
2495 + if ( ! function_exists( 'rocket_minify_files' ) ) {
2496 + /**
2497 + * Parses the buffer to minify the CSS and JS files
2498 + *
2499 + * @since 2.11
2500 + * @since 2.1
2501 + * @deprecated 3.1
2502 + *
2503 + * @param string $buffer HTML output.
2504 + * @param string $extension Type of files to minify.
2505 + * @return string Updated HTML output.
2506 + */
2507 + function rocket_minify_files( $buffer, $extension ) {
2508 + _deprecated_function( __FUNCTION__, '3.1' );
2509 +
2510 + global $wp_scripts, $rocket_js_enqueued_in_head;
2511 + if ( 'css' === $extension ) {
2512 + $concatenate = get_rocket_option( 'minify_concatenate_css', false ) ? true : false;
2513 + // Get all css files with this regex.
2514 + preg_match_all( apply_filters( 'rocket_minify_css_regex_pattern', '/<link\s*.+href=[\'|"]([^\'|"]+\.css?.+)[\'|"](.+)>/iU' ), $buffer, $tags_match, PREG_SET_ORDER );
2515 + }
2516 +
2517 + if ( 'js' === $extension ) {
2518 + $js_files_in_head = '';
2519 + $concatenate = get_rocket_option( 'minify_concatenate_js', false ) ? true : false;
2520 + if ( $rocket_js_enqueued_in_head && is_array( $rocket_js_enqueued_in_head ) ) {
2521 + $js_files_in_head = implode( '|', $rocket_js_enqueued_in_head );
2522 + }
2523 +
2524 + // Get all js files with this regex.
2525 + preg_match_all( apply_filters( 'rocket_minify_js_regex_pattern', '#<script[^>]+?src=[\'|"]([^\'|"]+\.js?.+)[\'|"].*>(?:<\/script>)#iU' ), $buffer, $tags_match, PREG_SET_ORDER );
2526 + }
2527 +
2528 + $original_buffer = $buffer;
2529 + $files = array();
2530 + $excluded_files = array();
2531 + $external_js_files = array();
2532 +
2533 + foreach ( $tags_match as $tag ) {
2534 + // Don't minify external files.
2535 + if ( is_rocket_external_file( $tag[1], $extension ) ) {
2536 + if ( 'js' === $extension && $concatenate ) {
2537 + $host = rocket_extract_url_component( $tag[1], PHP_URL_HOST );
2538 + $excluded_external_js = get_rocket_minify_excluded_external_js();
2539 + if ( ! isset( $excluded_external_js[ $host ] ) ) {
2540 + $external_js_files[] = $tag[0];
2541 + }
2542 + }
2543 + continue;
2544 + }
2545 +
2546 + // Don't minify excluded files.
2547 + if ( is_rocket_minify_excluded_file( $tag, $extension ) ) {
2548 + if ( $concatenate && 'js' === $extension && get_rocket_option( 'defer_all_js' ) && get_rocket_option( 'defer_all_js_safe' ) && false !== strpos( $tag[1], $wp_scripts->registered['jquery-core']->src ) ) {
2549 + if ( get_rocket_option( 'remove_query_strings' ) ) {
2550 + $external_js_files['jquery-cache-busting'] = str_replace( $tag[1], get_rocket_browser_cache_busting( $tag[1], 'script_loader_src' ), $tag[0] );
2551 + $buffer = str_replace( $tag[0], $external_js_files['jquery-cache-busting'], $buffer );
2552 + } else {
2553 + $external_js_files[] = $tag[0];
2554 + }
2555 +
2556 + continue;
2557 + }
2558 +
2559 + $excluded_files[] = $tag;
2560 + continue;
2561 + }
2562 +
2563 + if ( $concatenate ) {
2564 + if ( 'js' === $extension ) {
2565 + $file_path = rocket_clean_exclude_file( $tag[1] );
2566 +
2567 + if ( ! empty( $js_files_in_head ) && preg_match( '#(' . $js_files_in_head . ')#', $file_path ) ) {
2568 + $files['header'][] = strtok( $tag[1], '?' );
2569 + } else {
2570 + $files['footer'][] = strtok( $tag[1], '?' );
2571 + }
2572 + } else {
2573 + $files[] = strtok( $tag[1], '?' );
2574 + }
2575 +
2576 + $buffer = str_replace( $tag[0], '', $buffer );
2577 + continue;
2578 + }
2579 +
2580 + // Don't minify if file is already minified.
2581 + if ( preg_match( '/(?:-|\.)min.' . $extension . '/iU', $tag[1] ) ) {
2582 + $excluded_files[] = $tag;
2583 + continue;
2584 + }
2585 +
2586 + // Don't minify jQuery included in WP core since it's already minified but without .min in the filename.
2587 + if ( ! empty( $wp_scripts->registered['jquery-core']->src ) && false !== strpos( $tag[1], $wp_scripts->registered['jquery-core']->src ) ) {
2588 + $excluded_files[] = $tag;
2589 + continue;
2590 + }
2591 +
2592 + $files[] = $tag;
2593 + }
2594 +
2595 + if ( get_rocket_option( 'remove_query_strings' ) ) {
2596 + foreach ( $excluded_files as $tag ) {
2597 + if ( 'css' === $extension ) {
2598 + $tag_cache_busting = str_replace( $tag[1], get_rocket_browser_cache_busting( $tag[1], 'style_loader_src' ), $tag[0] );
2599 + }
2600 +
2601 + if ( 'js' === $extension ) {
2602 + $tag_cache_busting = str_replace( $tag[1], get_rocket_browser_cache_busting( $tag[1], 'script_loader_src' ), $tag[0] );
2603 + }
2604 +
2605 + $buffer = str_replace( $tag[0], $tag_cache_busting, $buffer );
2606 + }
2607 + }
2608 +
2609 + if ( empty( $files ) ) {
2610 + return $buffer;
2611 + }
2612 +
2613 + if ( ! $concatenate ) {
2614 + foreach ( $files as $tag ) {
2615 + $minify_url = get_rocket_minify_url( $tag[1], $extension );
2616 +
2617 + if ( ! $minify_url ) {
2618 + continue;
2619 + }
2620 +
2621 + $minify_tag = str_replace( $tag[1], $minify_url, $tag[0] );
2622 +
2623 + if ( 'css' === $extension ) {
2624 + $minify_tag = str_replace( $tag[2], ' data-minify="1" ' . $tag[2], $minify_tag );
2625 + }
2626 +
2627 + if ( 'js' === $extension ) {
2628 + $minify_tag = str_replace( '></script>', ' data-minify="1"></script>', $minify_tag );
2629 + }
2630 +
2631 + $buffer = str_replace( $tag[0], $minify_tag, $buffer );
2632 + }
2633 +
2634 + return $buffer;
2635 + }
2636 +
2637 + if ( 'js' === $extension ) {
2638 + $minify_header_url = get_rocket_minify_url( $files['header'], $extension );
2639 + $minify_url = get_rocket_minify_url( $files['footer'], $extension );
2640 +
2641 + if ( ! $minify_header_url && ! $minify_url ) {
2642 + return $original_buffer;
2643 + }
2644 +
2645 + foreach ( $external_js_files as $external_js_file ) {
2646 + $buffer = str_replace( $external_js_file, '', $buffer );
2647 + }
2648 +
2649 + $minify_header_tag = '<script src="' . $minify_header_url . '" data-minify="1"></script>';
2650 + $buffer = preg_replace( '/<head(.*)>/U', '<head$1>' . implode( '', $external_js_files ) . $minify_header_tag, $buffer, 1 );
2651 +
2652 + $minify_tag = '<script src="' . $minify_url . '" data-minify="1"></script>';
2653 + return str_replace( '</body>', $minify_tag . '</body>', $buffer );
2654 +
2655 + }
2656 +
2657 + if ( 'css' === $extension ) {
2658 + $minify_url = get_rocket_minify_url( $files, $extension );
2659 +
2660 + if ( ! $minify_url ) {
2661 + return $original_buffer;
2662 + }
2663 +
2664 + $minify_tag = '<link rel="stylesheet" href="' . $minify_url . '" data-minify="1" />';
2665 + return preg_replace( '/<head(.*)>/U', '<head$1>' . $minify_tag, $buffer, 1 );
2666 + }
2667 + }
2668 + }
2669 +
2670 + if ( ! function_exists( 'is_rocket_external_file' ) ) {
2671 + /**
2672 + * Determines if the file is external
2673 + *
2674 + * @since 2.11
2675 + * @deprecated 3.1
2676 + * @author Remy Perona
2677 + *
2678 + * @param string $url URL of the file.
2679 + * @param string $extension File extension.
2680 + * @return bool True if external, false otherwise
2681 + */
2682 + function is_rocket_external_file( $url, $extension ) {
2683 + _deprecated_function( __FUNCTION__, '3.1' );
2684 +
2685 + $file = get_rocket_parse_url( $url );
2686 + $wp_content = get_rocket_parse_url( WP_CONTENT_URL );
2687 + $hosts = get_rocket_cnames_host( array( 'all', 'css_and_js', $extension ) );
2688 + $hosts[] = $wp_content['host'];
2689 + $langs = get_rocket_i18n_uri();
2690 +
2691 + // Get host for all langs.
2692 + if ( $langs ) {
2693 + foreach ( $langs as $lang ) {
2694 + $hosts[] = rocket_extract_url_component( $lang, PHP_URL_HOST );
2695 + }
2696 + }
2697 +
2698 + $hosts_index = array_flip( array_unique( $hosts ) );
2699 +
2700 + // URL has domain and domain is not part of the internal domains.
2701 + if ( isset( $file['host'] ) && ! empty( $file['host'] ) && ! isset( $hosts_index[ $file['host'] ] ) ) {
2702 + return true;
2703 + }
2704 +
2705 + // URL has no domain and doesn't contain the WP_CONTENT path or wp-includes.
2706 + if ( ! isset( $file['host'] ) && ! preg_match( '#(' . $wp_content['path'] . '|wp-includes)#', $file['path'] ) ) {
2707 + return true;
2708 + }
2709 +
2710 + return false;
2711 + }
2712 + }
2713 +
2714 + if ( ! function_exists( 'is_rocket_minify_excluded_file' ) ) {
2715 + /**
2716 + * Determines if it is a file excluded from minification
2717 + *
2718 + * @since 2.11
2719 + * @deprecated 3.1
2720 + * @author Remy Perona
2721 + *
2722 + * @param array $tag Array containing the matches from the regex.
2723 + * @param string $extension File extension.
2724 + * @return bool True if it is a file excluded, false otherwise
2725 + */
2726 + function is_rocket_minify_excluded_file( $tag, $extension ) {
2727 + _deprecated_function( __FUNCTION__, '3.1' );
2728 +
2729 + // File should not be minified.
2730 + if ( false !== strpos( $tag[0], 'data-minify=' ) || false !== strpos( $tag[0], 'data-no-minify=' ) ) {
2731 + return true;
2732 + }
2733 +
2734 + if ( 'css' === $extension ) {
2735 + // CSS file media attribute is not all or screen.
2736 + if ( false !== strpos( $tag[0], 'media=' ) && ! preg_match( '/media=["\'](?:["\']|[^"\']*?(all|screen)[^"\']*?["\'])/iU', $tag[0] ) ) {
2737 + return true;
2738 + }
2739 +
2740 + if ( false !== strpos( $tag[0], 'only screen and' ) ) {
2741 + return true;
2742 + }
2743 + }
2744 +
2745 + $file_path = rocket_extract_url_component( $tag[1], PHP_URL_PATH );
2746 +
2747 + // File extension is not .css or .js.
2748 + if ( pathinfo( $file_path, PATHINFO_EXTENSION ) !== $extension ) {
2749 + return true;
2750 + }
2751 +
2752 + $excluded_files = get_rocket_exclude_files( $extension );
2753 +
2754 + if ( ! empty( $excluded_files ) ) {
2755 + foreach ( $excluded_files as $i => $excluded_file ) {
2756 + $excluded_files[ $i ] = str_replace( '#', '\#', $excluded_file );
2757 + }
2758 +
2759 + $excluded_files = implode( '|', $excluded_files );
2760 +
2761 + // File is excluded from minification/concatenation.
2762 + if ( preg_match( '#^(' . $excluded_files . ')$#', $file_path ) ) {
2763 + return true;
2764 + }
2765 + }
2766 +
2767 + return false;
2768 + }
2769 + }
2770 +
2771 + if ( ! function_exists( 'get_rocket_minify_url' ) ) {
2772 + /**
2773 + * Creates the minify URL if the minification is successful
2774 + *
2775 + * @since 2.11
2776 + * @deprecated 3.1
2777 + * @author Remy Perona
2778 + *
2779 + * @param string|array $files Original file(s) URL(s).
2780 + * @param string $extension File(s) extension.
2781 + * @return string|bool The minify URL if successful, false otherwise
2782 + */
2783 + function get_rocket_minify_url( $files, $extension ) {
2784 + _deprecated_function( __FUNCTION__, '3.1' );
2785 +
2786 + if ( empty( $files ) ) {
2787 + return false;
2788 + }
2789 +
2790 + $hosts = get_rocket_cnames_host( array( 'all', 'css_and_js', $extension ) );
2791 + $hosts['home'] = rocket_extract_url_component( home_url(), PHP_URL_HOST );
2792 + $hosts_index = array_flip( $hosts );
2793 + $minify_key = get_rocket_option( 'minify_' . $extension . '_key', create_rocket_uniqid() );
2794 +
2795 + if ( is_string( $files ) ) {
2796 + $file = get_rocket_parse_url( $files );
2797 + $file_path = rocket_url_to_path( strtok( $files, '?' ), $hosts_index );
2798 + $unique_id = md5( $files . $minify_key );
2799 + $filename = preg_replace( '/\.(' . $extension . ')$/', '-' . $unique_id . '.' . $extension, ltrim( rocket_realpath( $file['path'] ), '/' ) );
2800 + } else {
2801 + foreach ( $files as $file ) {
2802 + $file_path[] = rocket_url_to_path( $file, $hosts_index );
2803 + }
2804 +
2805 + $files_hash = implode( ',', $files );
2806 + $filename = md5( $files_hash . $minify_key ) . '.' . $extension;
2807 + }
2808 +
2809 + $minified_file = WP_ROCKET_MINIFY_CACHE_PATH . get_current_blog_id() . '/' . $filename;
2810 +
2811 + if ( ! file_exists( $minified_file ) ) {
2812 + $minified_content = rocket_minify( $file_path, $extension );
2813 +
2814 + if ( ! $minified_content ) {
2815 + return false;
2816 + }
2817 +
2818 + $minify_filepath = rocket_write_minify_file( $minified_content, $minified_file );
2819 +
2820 + if ( ! $minify_filepath ) {
2821 + return false;
2822 + }
2823 + }
2824 +
2825 + $minify_url = get_rocket_cdn_url( WP_ROCKET_MINIFY_CACHE_URL . get_current_blog_id() . '/' . $filename, array( 'all', 'css_and_js', $extension ) );
2826 +
2827 + if ( 'css' === $extension ) {
2828 + /**
2829 + * Filters CSS file URL with CDN hostname
2830 + *
2831 + * @since 2.1
2832 + *
2833 + * @param string $minify_url Minified file URL.
2834 + */
2835 + return apply_filters( 'rocket_css_url', $minify_url );
2836 + }
2837 +
2838 + if ( 'js' === $extension ) {
2839 + /**
2840 + * Filters JavaScript file URL with CDN hostname
2841 + *
2842 + * @since 2.1
2843 + *
2844 + * @param string $minify_url Minified file URL.
2845 + */
2846 + return apply_filters( 'rocket_js_url', $minify_url );
2847 +
2848 + }
2849 + }
2850 + }
2851 +
2852 + if ( ! function_exists( 'rocket_minify' ) ) {
2853 + /**
2854 + * Minifies the content
2855 + *
2856 + * @since 2.11
2857 + * @deprecated 3.1
2858 + * @author Remy Perona
2859 + *
2860 + * @param string|array $files File(s) to minify.
2861 + * @param string $extension File(s) extension.
2862 + * @return string|bool Minified content, false if empty
2863 + */
2864 + function rocket_minify( $files, $extension ) {
2865 + _deprecated_function( __FUNCTION__, '3.1' );
2866 +
2867 + if ( 'css' === $extension ) {
2868 + $minify = new Minify\CSS();
2869 + } elseif ( 'js' === $extension ) {
2870 + $minify = new Minify\JS();
2871 + }
2872 +
2873 + $files = (array) $files;
2874 +
2875 + foreach ( $files as $file ) {
2876 + $file_content = rocket_direct_filesystem()->get_contents( $file );
2877 + if ( 'css' === $extension ) {
2878 + /**
2879 + * Filters the Document Root path to use during CSS minification to rewrite paths
2880 + *
2881 + * @since 2.7
2882 + *
2883 + * @param string The Document Root path.
2884 + */
2885 + $document_root = apply_filters( 'rocket_min_documentRoot', ABSPATH );
2886 +
2887 + $file_content = rocket_cdn_css_properties( Minify_CSS_UriRewriter::rewrite( $file_content, dirname( $file ), $document_root ) );
2888 + }
2889 +
2890 + $minify->add( $file_content );
2891 + }
2892 +
2893 + $minified_content = $minify->minify();
2894 +
2895 + if ( empty( $minified_content ) ) {
2896 + return false;
2897 + }
2898 +
2899 + return $minified_content;
2900 + }
2901 + }
2902 +
2903 + if ( ! function_exists( 'rocket_write_minify_file' ) ) {
2904 + /**
2905 + * Writes the minified content to a file
2906 + *
2907 + * @since 2.11
2908 + * @deprecated 3.1
2909 + * @author Remy Perona
2910 + *
2911 + * @param string $content Minified content.
2912 + * @param string $minified_file Path to the minified file to write in.
2913 + * @return bool True if successful, false otherwise
2914 + */
2915 + function rocket_write_minify_file( $content, $minified_file ) {
2916 + _deprecated_function( __FUNCTION__, '3.1' );
2917 +
2918 + if ( file_exists( $minified_file ) ) {
2919 + return true;
2920 + }
2921 +
2922 + if ( ! rocket_mkdir_p( dirname( $minified_file ) ) ) {
2923 + return false;
2924 + }
2925 +
2926 + return rocket_put_content( $minified_file, $content );
2927 + }
2928 + }
2929 +
2930 + if ( ! function_exists( 'get_rocket_minify_excluded_external_js' ) ) {
2931 + /**
2932 + * Get all JS externals files to exclude of the minification process
2933 + *
2934 + * @since 2.6
2935 + * @deprecated 3.1
2936 + *
2937 + * @return array Array of excluded external JS
2938 + */
2939 + function get_rocket_minify_excluded_external_js() {
2940 + _deprecated_function( __FUNCTION__, '3.1' );
2941 +
2942 + /**
2943 + * Filters JS externals files to exclude from the minification process (do not move into the header)
2944 + *
2945 + * @since 2.2
2946 + *
2947 + * @param array $hostnames Hostname of JS files to exclude.
2948 + */
2949 + $excluded_external_js = apply_filters(
2950 + 'rocket_minify_excluded_external_js', array(
2951 + 'forms.aweber.com',
2952 + 'video.unrulymedia.com',
2953 + 'gist.github.com',
2954 + 'stats.wp.com',
2955 + 'stats.wordpress.com',
2956 + 'www.statcounter.com',
2957 + 'widget.rafflecopter.com',
2958 + 'widget-prime.rafflecopter.com',
2959 + 'widget.supercounters.com',
2960 + 'releases.flowplayer.org',
2961 + 'tools.meetaffiliate.com',
2962 + 'c.ad6media.fr',
2963 + 'cdn.stickyadstv.com',
2964 + 'www.smava.de',
2965 + 'contextual.media.net',
2966 + 'app.getresponse.com',
2967 + 'ap.lijit.com',
2968 + 'adserver.reklamstore.com',
2969 + 's0.wp.com',
2970 + 'wprp.zemanta.com',
2971 + 'files.bannersnack.com',
2972 + 'smarticon.geotrust.com',
2973 + 'js.gleam.io',
2974 + 'script.ioam.de',
2975 + 'ir-na.amazon-adsystem.com',
2976 + 'web.ventunotech.com',
2977 + 'verify.authorize.net',
2978 + 'ads.themoneytizer.com',
2979 + 'embed.finanzcheck.de',
2980 + 'imagesrv.adition.com',
2981 + 'js.juicyads.com',
2982 + 'form.jotformeu.com',
2983 + 'speakerdeck.com',
2984 + 'content.jwplatform.com',
2985 + 'ads.investingchannel.com',
2986 + 'app.ecwid.com',
2987 + 'www.industriejobs.de',
2988 + 's.gravatar.com',
2989 + 'cdn.jsdelivr.net',
2990 + 'cdnjs.cloudflare.com',
2991 + 'code.jquery.com',
2992 + )
2993 + );
2994 +
2995 + return array_flip( $excluded_external_js );
2996 + }
2997 + }
2998 +
2999 + if ( ! function_exists( 'rocket_cache_dynamic_resource' ) ) {
3000 + /**
3001 + * Create a static file for dynamically generated CSS/JS from PHP
3002 + *
3003 + * @since 2.9
3004 + * @deprecated 3.1
3005 + * @author Remy Perona
3006 + *
3007 + * @param string $src dynamic CSS/JS file URL.
3008 + * @return string URL of the generated static file
3009 + */
3010 + function rocket_cache_dynamic_resource( $src ) {
3011 + _deprecated_function( __FUNCTION__, '3.1' );
3012 + global $pagenow;
3013 +
3014 + if ( defined( 'DONOTROCKETOPTIMIZE' ) && DONOTROCKETOPTIMIZE ) {
3015 + return $src;
3016 + }
3017 +
3018 + if ( is_user_logged_in() && ! get_rocket_option( 'cache_logged_user' ) ) {
3019 + return $src;
3020 + }
3021 +
3022 + if ( 'wp-login.php' === $pagenow ) {
3023 + return $src;
3024 + }
3025 +
3026 + if ( false === strpos( $src, '.php' ) ) {
3027 + return $src;
3028 + }
3029 +
3030 + /**
3031 + * Filters files to exclude from static dynamic resources
3032 + *
3033 + * @since 2.9.3
3034 + * @author Remy Perona
3035 + *
3036 + * @param array $excluded_files An array of filepath to exclude.
3037 + */
3038 + $excluded_files = apply_filters( 'rocket_exclude_static_dynamic_resources', array() );
3039 + $excluded_files[] = '/wp-admin/admin-ajax.php';
3040 + $excluded_files = array_flip( $excluded_files );
3041 +
3042 + if ( isset( $excluded_files[ rocket_clean_exclude_file( $src ) ] ) ) {
3043 + return $src;
3044 + }
3045 +
3046 + $full_src = ( substr( $src, 0, 2 ) === '//' ) ? rocket_add_url_protocol( $src ) : $src;
3047 +
3048 + $current_filter = current_filter();
3049 +
3050 + switch ( $current_filter ) {
3051 + case 'script_loader_src':
3052 + $extension = 'js';
3053 + $minify_key = get_rocket_option( 'minify_js_key' );
3054 + break;
3055 + case 'style_loader_src':
3056 + $extension = 'css';
3057 + $minify_key = get_rocket_option( 'minify_css_key' );
3058 + break;
3059 + }
3060 +
3061 + $hosts = get_rocket_cnames_host( array( 'all', 'css_and_js', $extension ) );
3062 + $hosts[] = rocket_extract_url_component( home_url(), PHP_URL_HOST );
3063 + $hosts_index = array_flip( $hosts );
3064 + $file = get_rocket_parse_url( $full_src );
3065 + $file['query'] = remove_query_arg( 'ver', $file['query'] );
3066 +
3067 + if ( $file['query'] ) {
3068 + return $src;
3069 + }
3070 +
3071 + if ( '' === $file['host'] ) {
3072 + $full_src = home_url() . $src;
3073 + }
3074 +
3075 + if ( strpos( $full_src, '://' ) !== false && ! isset( $hosts_index[ $file['host'] ] ) ) {
3076 + return $src;
3077 + }
3078 +
3079 + $relative_src = ltrim( $file['path'], '/' );
3080 + $abspath_src = rocket_url_to_path( strtok( $full_src, '?' ), $hosts_index );
3081 +
3082 + /*
3083 + * Filters the dynamic resource cache filename
3084 + *
3085 + * @since 2.9
3086 + * @author Remy Perona
3087 + *
3088 + * @param string $filename filename for the cache file
3089 + */
3090 + $cache_dynamic_resource_filename = apply_filters( 'rocket_dynamic_resource_cache_filename', preg_replace( '/\.(php)$/', '-' . $minify_key . '.' . $extension, $relative_src ) );
3091 + $cache_busting_paths = rocket_get_cache_busting_paths( $cache_dynamic_resource_filename, $extension );
3092 +
3093 + if ( file_exists( $cache_busting_paths['filepath'] ) && is_readable( $cache_busting_paths['filepath'] ) ) {
3094 + return $cache_busting_paths['url'];
3095 + }
3096 +
3097 + if ( rocket_fetch_and_cache_busting( $full_src, $cache_busting_paths, $abspath_src, $current_filter ) ) {
3098 + return $cache_busting_paths['url'];
3099 + }
3100 +
3101 + return $src;
3102 + }
3103 + }
3104 +
3105 + if ( ! function_exists( 'rocket_browser_cache_busting' ) ) {
3106 + /**
3107 + * Wrapper for get_rocket_browser_cache_busting except when minification is active.
3108 + *
3109 + * @since 2.9
3110 + * @deprecated 3.1
3111 + * @author Remy Perona
3112 + *
3113 + * @param string $src CSS/JS file URL.
3114 + * @return string updated CSS/JS file URL.
3115 + */
3116 + function rocket_browser_cache_busting( $src ) {
3117 + _deprecated_function( __FUNCTION__, '3.1' );
3118 + $current_filter = current_filter();
3119 +
3120 + if ( 'style_loader_src' === $current_filter && get_rocket_option( 'minify_css' ) && ( ! defined( 'DONOTMINIFYCSS' ) || ! DONOTMINIFYCSS ) && ! is_rocket_post_excluded_option( 'minify_css' ) ) {
3121 + return $src;
3122 + }
3123 +
3124 + if ( 'script_loader_src' === $current_filter && get_rocket_option( 'minify_js' ) && ( ! defined( 'DONOTMINIFYJS' ) || ! DONOTMINIFYJS ) && ! is_rocket_post_excluded_option( 'minify_js' ) ) {
3125 + return $src;
3126 + }
3127 +
3128 + return get_rocket_browser_cache_busting( $src, $current_filter );
3129 + }
3130 + }
3131 +
3132 + if ( ! function_exists( 'get_rocket_browser_cache_busting' ) ) {
3133 + /**
3134 + * Create a cache busting file with the version in the filename
3135 + *
3136 + * @since 2.9
3137 + * @deprecated 3.1
3138 + * @author Remy Perona
3139 + *
3140 + * @param string $src CSS/JS file URL.
3141 + * @param string $current_filter Current WordPress filter.
3142 + * @return string updated CSS/JS file URL
3143 + */
3144 + function get_rocket_browser_cache_busting( $src, $current_filter = '' ) {
3145 + _deprecated_function( __FUNCTION__, '3.1' );
3146 + global $pagenow;
3147 +
3148 + if ( defined( 'DONOTROCKETOPTIMIZE' ) && DONOTROCKETOPTIMIZE ) {
3149 + return $src;
3150 + }
3151 +
3152 + if ( ! get_rocket_option( 'remove_query_strings' ) ) {
3153 + return $src;
3154 + }
3155 +
3156 + if ( is_user_logged_in() && ! get_rocket_option( 'cache_logged_user', 0 ) ) {
3157 + return $src;
3158 + }
3159 +
3160 + if ( 'wp-login.php' === $pagenow ) {
3161 + return $src;
3162 + }
3163 +
3164 + if ( false === strpos( $src, '.css' ) && false === strpos( $src, '.js' ) ) {
3165 + return $src;
3166 + }
3167 +
3168 + if ( false !== strpos( $src, 'ver=' . $GLOBALS['wp_version'] ) ) {
3169 + $src = rtrim( str_replace( array( 'ver=' . $GLOBALS['wp_version'], '?&', '&&' ), array( '', '?', '&' ), $src ), '?&' );
3170 + }
3171 +
3172 + /**
3173 + * Filters files to exclude from cache busting
3174 + *
3175 + * @since 2.9.3
3176 + * @author Remy Perona
3177 + *
3178 + * @param array $excluded_files An array of filepath to exclude.
3179 + */
3180 + $excluded_files = apply_filters( 'rocket_exclude_cache_busting', array() );
3181 + $excluded_files = implode( '|', $excluded_files );
3182 +
3183 + if ( preg_match( '#^(' . $excluded_files . ')$#', rocket_clean_exclude_file( $src ) ) ) {
3184 + return $src;
3185 + }
3186 +
3187 + if ( empty( $current_filter ) ) {
3188 + $current_filter = current_filter();
3189 + }
3190 +
3191 + $full_src = ( substr( $src, 0, 2 ) === '//' ) ? rocket_add_url_protocol( $src ) : $src;
3192 +
3193 + switch ( $current_filter ) {
3194 + case 'script_loader_src':
3195 + $extension = 'js';
3196 + break;
3197 + case 'style_loader_src':
3198 + $extension = 'css';
3199 + break;
3200 + }
3201 +
3202 + $hosts = get_rocket_cnames_host( array( 'all', 'css_and_js', $extension ) );
3203 + $hosts['home'] = rocket_extract_url_component( home_url(), PHP_URL_HOST );
3204 + $hosts_index = array_flip( $hosts );
3205 + $file = get_rocket_parse_url( $full_src );
3206 +
3207 + if ( '' === $file['host'] ) {
3208 + $full_src = home_url() . $src;
3209 + }
3210 +
3211 + if ( false !== strpos( $full_src, '://' ) && ! isset( $hosts_index[ $file['host'] ] ) ) {
3212 + return $src;
3213 + }
3214 +
3215 + if ( empty( $file['query'] ) ) {
3216 + return $src;
3217 + }
3218 +
3219 + $relative_src = ltrim( $file['path'] . '?' . $file['query'], '/' );
3220 + $abspath_src = rocket_url_to_path( strtok( $full_src, '?' ), $hosts_index );
3221 + $cache_busting_filename = preg_replace( '/\.(js|css)\?(?:timestamp|ver)=([^&]+)(?:.*)/', '-$2.$1', $relative_src );
3222 +
3223 + if ( $cache_busting_filename === $relative_src ) {
3224 + return $src;
3225 + }
3226 +
3227 + /*
3228 + * Filters the cache busting filename
3229 + *
3230 + * @since 2.9
3231 + * @author Remy Perona
3232 + *
3233 + * @param string $filename filename for the cache busting file
3234 + */
3235 + $cache_busting_filename = apply_filters( 'rocket_cache_busting_filename', $cache_busting_filename );
3236 + $cache_busting_paths = rocket_get_cache_busting_paths( $cache_busting_filename, $extension );
3237 +
3238 + if ( file_exists( $cache_busting_paths['filepath'] ) && is_readable( $cache_busting_paths['filepath'] ) ) {
3239 + return $cache_busting_paths['url'];
3240 + }
3241 +
3242 + if ( rocket_fetch_and_cache_busting( $abspath_src, $cache_busting_paths, $abspath_src, $current_filter ) ) {
3243 + return $cache_busting_paths['url'];
3244 + }
3245 +
3246 + return $src;
3247 + }
3248 + }
3249 +
3250 + if ( ! function_exists( 'rocket_dns_prefetch_buffer' ) ) {
3251 + /**
3252 + * Inserts html code for domain names to DNS prefetch in the buffer before creating the cache file
3253 + *
3254 + * @since 2.0
3255 + * @deprecated 3.1
3256 + * @author Jonathan Buttigieg
3257 + *
3258 + * @param String $buffer HTML content.
3259 + * @return String Updated buffer
3260 + */
3261 + function rocket_dns_prefetch_buffer( $buffer ) {
3262 + _deprecated_function( __FUNCTION__, '3.1' );
3263 + $dns_link_tags = '';
3264 + $domains = rocket_get_dns_prefetch_domains();
3265 +
3266 + if ( (bool) $domains ) {
3267 + foreach ( $domains as $domain ) {
3268 + $dns_link_tags .= '<link rel="dns-prefetch" href="' . esc_url( $domain ) . '" />';
3269 + }
3270 + }
3271 +
3272 + $old_ie_conditional_tag = '';
3273 +
3274 + /**
3275 + * Allow to print an empty IE conditional tag to speed up old IE versions to load CSS & JS files
3276 + *
3277 + * @since 2.6.5
3278 + *
3279 + * @param bool true will print the IE conditional tag
3280 + */
3281 + if ( apply_filters( 'do_rocket_old_ie_prefetch_conditional_tag', true ) ) {
3282 + $old_ie_conditional_tag = '<!--[if IE]><![endif]-->';
3283 + }
3284 +
3285 + // Insert all DNS prefetch tags in head.
3286 + $buffer = preg_replace( '/<head(.*)>/', '<head$1>' . $old_ie_conditional_tag . $dns_link_tags, $buffer, 1 );
3287 +
3288 + return $buffer;
3289 + }
3290 + }
3291 +