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

Keine Baseline-Datei – Diff nur gegen leer.
Zur Liste
1 -
1 + <?php
2 +
3 + defined( 'ABSPATH' ) || exit;
4 +
5 + /**
6 + * Require deprecated classes.
7 + */
8 + require_once __DIR__ . '/DeprecatedClassTrait.php';
9 + require_once __DIR__ . '/Engine/Optimization/QueryString/Remove.php';
10 + require_once __DIR__ . '/Engine/Optimization/QueryString/RemoveSubscriber.php';
11 +
12 + /**
13 + * Class aliases.
14 + */
15 + class_alias( '\WP_Rocket\Engine\Admin\Beacon\ServiceProvider', '\WP_Rocket\ServiceProvider\Beacon' );
16 + class_alias( '\WP_Rocket\Engine\HealthCheck\HealthCheck', '\WP_Rocket\Engine\Admin\HealthCheck' );
17 + class_alias( '\WP_Rocket\Engine\Optimization\ServiceProvider', '\WP_Rocket\ServiceProvider\Optimization_Subscribers' );
18 + class_alias( '\WP_Rocket\Engine\Optimization\IEConditionalSubscriber', '\WP_Rocket\Subscriber\Optimization\IE_Conditionals_Subscriber' );
19 + class_alias( '\WP_Rocket\ThirdParty\Plugins\Smush', '\WP_Rocket\Subscriber\Third_Party\Plugins\Smush_Subscriber' );
20 + class_alias( '\WP_Rocket\Engine\Capabilities\Subscriber', '\WP_Rocket\Subscriber\Plugin\Capabilities_Subscriber' );
21 +
22 + /**
23 + * Generate the content of advanced-cache.php file.
24 + *
25 + * @since 3.6 deprecated
26 + * @since 3.5.5 Uses rocket_get_constant() for constants.
27 + * @since 2.1 Add filter rocket_advanced_cache_file.
28 + * @since 2.0.3
29 + *
30 + * @return string $buffer The content of advanced-cache.php file
31 + */
32 + function get_rocket_advanced_cache_file() { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
33 + _deprecated_function( __FUNCTION__ . '()', '3.6', '\WP_Rocket\Engine\Cache\AdvancedCache::get_advanced_cache_content()' );
34 +
35 + $buffer = "<?php\n";
36 + $buffer .= "defined( 'ABSPATH' ) || exit;\n\n";
37 +
38 + // Add a constant to be sure this is our file.
39 + $buffer .= "define( 'WP_ROCKET_ADVANCED_CACHE', true );\n\n";
40 +
41 + $buffer .= "if ( ! defined( 'WP_ROCKET_CONFIG_PATH' ) ) {\n";
42 + $buffer .= "\tdefine( 'WP_ROCKET_CONFIG_PATH', WP_CONTENT_DIR . '/wp-rocket-config/' );\n";
43 + $buffer .= "}\n\n";
44 +
45 + // Include the Mobile Detect class if we have to create a different caching file for mobile.
46 + if ( is_rocket_generate_caching_mobile_files() ) {
47 + $vendor_path = rocket_get_constant( 'WP_ROCKET_VENDORS_PATH' );
48 +
49 + $buffer .= "if ( file_exists( '" . $vendor_path . "classes/class-rocket-mobile-detect.php' ) && ! class_exists( 'Rocket_Mobile_Detect' ) ) {\n";
50 + $buffer .= "\tinclude_once '" . $vendor_path . "classes/class-rocket-mobile-detect.php';\n";
51 + $buffer .= "}\n\n";
52 + }
53 +
54 + // Register a class autoloader and include the process file.
55 + $buffer .= "if ( version_compare( phpversion(), '" . rocket_get_constant( 'WP_ROCKET_PHP_VERSION' ) . "' ) >= 0 ) {\n\n";
56 +
57 + // Class autoloader.
58 + $autoloader = rocket_direct_filesystem()->get_contents( rocket_get_constant( 'WP_ROCKET_INC_PATH' ) . 'process-autoloader.php' );
59 +
60 + if ( $autoloader ) {
61 + $autoloader = preg_replace( '@^<\?php\s*@', '', $autoloader );
62 + $autoloader = str_replace( [ "\n", "\n\t\n" ], [ "\n\t", "\n\n" ], trim( $autoloader ) );
63 + $autoloader = str_replace( 'WP_ROCKET_PATH', "'" . rocket_get_constant( 'WP_ROCKET_PATH' ) . "'", $autoloader );
64 +
65 + $buffer .= "\t$autoloader\n\n";
66 + }
67 +
68 + // Initialize the Cache class and process.
69 + $buffer .= "\t" . 'if ( ! class_exists( \'\WP_Rocket\Buffer\Cache\' ) ) {
70 + if ( ! defined( \'DONOTROCKETOPTIMIZE\' ) ) {
71 + define( \'DONOTROCKETOPTIMIZE\', true ); // WPCS: prefix ok.
72 + }
73 + return;
74 + }
75 +
76 + $rocket_config_class = new \WP_Rocket\Buffer\Config(
77 + [
78 + \'config_dir_path\' => \'' . rocket_get_constant( 'WP_ROCKET_CONFIG_PATH' ) . '\',
79 + ]
80 + );
81 +
82 + ( new \WP_Rocket\Buffer\Cache(
83 + new \WP_Rocket\Buffer\Tests(
84 + $rocket_config_class
85 + ),
86 + $rocket_config_class,
87 + [
88 + \'cache_dir_path\' => \'' . rocket_get_constant( 'WP_ROCKET_CACHE_PATH' ) . '\',
89 + ]
90 + ) )->maybe_init_process();' . "\n";
91 + $buffer .= "} else {\n";
92 + // Add a constant to provent include issue.
93 + $buffer .= "\tdefine( 'WP_ROCKET_ADVANCED_CACHE_PROBLEM', true );\n";
94 + $buffer .= "}\n";
95 +
96 + /**
97 + * Filter the content of advanced-cache.php file.
98 + *
99 + * @since 2.1
100 + *
101 + * @param string $buffer The content that will be printed in advanced-cache.php.
102 + */
103 + return (string) apply_filters( 'rocket_advanced_cache_file', $buffer );
104 + }
105 +
106 + /**
107 + * This warning is displayed when the advanced-cache.php file isn't writeable
108 + *
109 + * @since 3.6 deprecated
110 + * @since 2.0
111 + */
112 + function rocket_warning_advanced_cache_permissions() {
113 + _deprecated_function( __FUNCTION__ . '()', '3.6', '\WP_Rocket\Engine\Cache\AdvancedCache::notice_permissions()' );
114 +
115 + $advanced_cache_file = WP_CONTENT_DIR . '/advanced-cache.php';
116 +
117 + if ( current_user_can( 'rocket_manage_options' )
118 + && ! rocket_direct_filesystem()->is_writable( $advanced_cache_file )
119 + && ( ! defined( 'WP_ROCKET_ADVANCED_CACHE' ) || ! WP_ROCKET_ADVANCED_CACHE )
120 + && rocket_valid_key() ) {
121 +
122 + $boxes = get_user_meta( get_current_user_id(), 'rocket_boxes', true );
123 +
124 + if ( in_array( __FUNCTION__, (array) $boxes, true ) ) {
125 + return;
126 + }
127 +
128 + $message = rocket_notice_writing_permissions( basename( WP_CONTENT_DIR ) . '/advanced-cache.php' );
129 +
130 + rocket_notice_html(
131 + [
132 + 'status' => 'error',
133 + 'dismissible' => '',
134 + 'message' => $message,
135 + 'dismiss_button' => __FUNCTION__,
136 + 'readonly_content' => get_rocket_advanced_cache_file(),
137 + ]
138 + );
139 + }
140 + }
141 +
142 + /**
143 + * This warning is displayed when the advanced-cache.php file isn't ours
144 + *
145 + * @since 3.6 Deprecated
146 + * @since 2.2
147 + */
148 + function rocket_warning_advanced_cache_not_ours() {
149 + _deprecated_function( __FUNCTION__ . '()', '3.6', '\WP_Rocket\Engine\Cache\AdvancedCache::notice_content_not_ours()' );
150 +
151 + if ( ! ( 'plugins.php' === $GLOBALS['pagenow'] && isset( $_GET['activate'] ) ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended
152 + && current_user_can( 'rocket_manage_options' )
153 + && ! defined( 'WP_ROCKET_ADVANCED_CACHE' )
154 + && ( defined( 'WP_CACHE' ) && WP_CACHE )
155 + && get_rocket_option( 'version' ) === WP_ROCKET_VERSION
156 + && rocket_valid_key() ) {
157 +
158 + $message = rocket_notice_writing_permissions( basename( WP_CONTENT_DIR ) . '/advanced-cache.php' );
159 +
160 + rocket_notice_html(
161 + [
162 + 'status' => 'error',
163 + 'dismissible' => '',
164 + 'message' => $message,
165 + ]
166 + );
167 + }
168 + }
169 +
170 + /**
171 + * Exclude fusion styles from cache busting to prevent cache dir issues
172 + *
173 + * @deprecated 3.6
174 + * @author Remy Perona
175 + *
176 + * @param array $excluded_files An array of excluded files.
177 + * @return array
178 + */
179 + function rocket_exclude_avada_dynamic_css( $excluded_files ) {
180 + _deprecated_function( __FUNCTION__ . '()', '3.6' );
181 +
182 + $upload_dir = wp_upload_dir();
183 +
184 + $excluded_files[] = rocket_clean_exclude_file( $upload_dir['baseurl'] . '/fusion-styles/(.*)' );
185 +
186 + return $excluded_files;
187 + }
188 +
189 + /**
190 + * Excludes Uncode JS files from remove query strings
191 + *
192 + * @deprecated 3.6
193 + * @since 3.3.3
194 + * @author Remy Perona
195 + *
196 + * @param array $exclude_busting Array of CSS and JS filepaths to be excluded.
197 + * @return array
198 + */
199 + function rocket_exclude_busting_uncode( $exclude_busting ) {
200 + _deprecated_function( __FUNCTION__ . '()', '3.6' );
201 +
202 + // CSS files.
203 + $exclude_busting[] = rocket_clean_exclude_file( get_template_directory_uri() . '/library/css/style.css' );
204 + $exclude_busting[] = rocket_clean_exclude_file( get_template_directory_uri() . '/library/css/uncode-icons.css' );
205 + $exclude_busting[] = rocket_clean_exclude_file( get_template_directory_uri() . '/library/css/style-custom.css' );
206 +
207 + // JS files.
208 + $exclude_busting[] = rocket_clean_exclude_file( get_template_directory_uri() . '/library/js/init.js' );
209 + $exclude_busting[] = rocket_clean_exclude_file( get_template_directory_uri() . '/library/js/min/init.min.js' );
210 + $exclude_busting[] = rocket_clean_exclude_file( get_template_directory_uri() . '/library/js/app.js' );
211 + $exclude_busting[] = rocket_clean_exclude_file( get_template_directory_uri() . '/library/js/app.min.js' );
212 + $exclude_busting[] = rocket_clean_exclude_file( get_template_directory_uri() . '/library/js/plugins.js' );
213 + $exclude_busting[] = rocket_clean_exclude_file( get_template_directory_uri() . '/library/js/plugins.min.js' );
214 + return $exclude_busting;
215 + }
216 +
217 + /**
218 + * Purge the cache when the beaver builder layout is updated to update the minified files content & URL
219 + *
220 + * @deprecated 3.6
221 + * @since 2.9 Also clear the cache busting folder
222 + * @since 2.8.6
223 + */
224 + function rocket_beaver_builder_clean_domain() {
225 + _deprecated_function( __FUNCTION__ . '()', '3.6', 'WP_Rocket\ThirdParty\Plugins\PageBuilder\BeaverBuilder::purge_cache' );
226 + rocket_clean_minify();
227 + rocket_clean_domain();
228 + }
229 +
230 + /**
231 + * Returns paths used for cache busting
232 + *
233 + * @since 2.9
234 + * @deprecated 3.6
235 + * @author Remy Perona
236 + *
237 + * @param string $filename name of the cache busting file.
238 + * @param string $extension file extension.
239 + * @return array Array of paths used for cache busting
240 + */
241 + function rocket_get_cache_busting_paths( $filename, $extension ) {
242 + _deprecated_function( __FUNCTION__ . '()', '3.6' );
243 + $blog_id = get_current_blog_id();
244 + $cache_busting_path = WP_ROCKET_CACHE_BUSTING_PATH . $blog_id;
245 + $filename = rocket_realpath( rtrim( str_replace( [ ' ', '%20' ], '-', $filename ) ) );
246 + $cache_busting_filepath = $cache_busting_path . $filename;
247 + $cache_busting_url = WP_ROCKET_CACHE_BUSTING_URL . $blog_id . $filename;
248 +
249 + switch ( $extension ) {
250 + case 'css':
251 + /** This filter is documented in inc/functions/minify.php */
252 + $cache_busting_url = apply_filters( 'rocket_css_url', $cache_busting_url );
253 + break;
254 + case 'js':
255 + /** This filter is documented in inc/functions/minify.php */
256 + $cache_busting_url = apply_filters( 'rocket_js_url', $cache_busting_url );
257 + break;
258 + }
259 +
260 + return [
261 + 'bustingpath' => $cache_busting_path,
262 + 'filepath' => $cache_busting_filepath,
263 + 'url' => $cache_busting_url,
264 + ];
265 + }
266 +
267 + /**
268 + * Caches SCCSS code & remove the default enqueued URL
269 + *
270 + * @since 2.9
271 + * @deprecated 3.6
272 + *
273 + * @author Remy Perona
274 + */
275 + function rocket_cache_sccss() {
276 + _deprecated_function( __FUNCTION__ . '()', '3.6', '\WP_Rocket\ThirdParty\Plugins\SimpleCustomCss::cache_sccss()' );
277 + $sccss = rocket_get_cache_busting_paths( 'sccss.css', 'css' );
278 +
279 + if ( ! file_exists( $sccss['filepath'] ) ) {
280 + rocket_sccss_create_cache_file( $sccss['bustingpath'], $sccss['filepath'] );
281 + }
282 +
283 + if ( file_exists( $sccss['filepath'] ) ) {
284 + wp_enqueue_style( 'scss', $sccss['url'], '', filemtime( $sccss['filepath'] ) );
285 + remove_action( 'wp_enqueue_scripts', 'sccss_register_style', 99 );
286 + }
287 + }
288 +
289 + /**
290 + * Deletes & recreates cache for SCCSS code
291 + *
292 + * @since 2.9
293 + * @deprecated 3.6
294 + *
295 + * @author Remy Perona
296 + */
297 + function rocket_delete_sccss_cache_file() {
298 + _deprecated_function( __FUNCTION__ . '()', '3.6', '\WP_Rocket\ThirdParty\Plugins\SimpleCustomCss::update_cache_file()' );
299 + $sccss = rocket_get_cache_busting_paths( 'sccss.css', 'css' );
300 +
301 + array_map( 'unlink', glob( $sccss['bustingpath'] . 'sccss*.css' ) );
302 + rocket_clean_domain();
303 + rocket_sccss_create_cache_file( $sccss['bustingpath'], $sccss['filepath'] );
304 + }
305 +
306 + /**
307 + * Returns the filename for SCSSS cache file
308 + *
309 + * @since 2.9
310 + * @deprecated 3.6
311 + *
312 + * @author Remy Perona
313 + *
314 + * @param string $filename filename.
315 + * @return string filename
316 + */
317 + function rocket_sccss_cache_busting_filename( $filename ) {
318 + _deprecated_function( __FUNCTION__ . '()', '3.6' );
319 + if ( false !== strpos( $filename, 'sccss' ) ) {
320 + return preg_replace( '/(?:.*)(sccss(?:.*))/i', '$1', $filename );
321 + }
322 +
323 + return $filename;
324 + }
325 +
326 + /**
327 + * Creates the cache file for SCCSS code
328 + *
329 + * @since 2.9
330 + * @deprecated 3.6
331 + *
332 + * @author Remy Perona
333 + *
334 + * @param string $cache_busting_path Path to the cache busting directory.
335 + * @param string $cache_sccss_filepath Path to the sccss cache file.
336 + */
337 + function rocket_sccss_create_cache_file( $cache_busting_path, $cache_sccss_filepath ) {
338 + _deprecated_function( __FUNCTION__ . '()', '3.6', '\WP_Rocket\ThirdParty\Plugins\SimpleCustomCss::create_cache_file()' );
339 + $options = get_option( 'sccss_settings' );
340 + $raw_content = isset( $options['sccss-content'] ) ? $options['sccss-content'] : '';
341 + $content = wp_kses( $raw_content, [ '\'', '\"' ] );
342 + $content = str_replace( '&gt;', '>', $content );
343 +
344 + if ( ! rocket_direct_filesystem()->is_dir( $cache_busting_path ) ) {
345 + rocket_mkdir_p( $cache_busting_path );
346 + }
347 +
348 + rocket_put_content( $cache_sccss_filepath, $content );
349 + }
350 +
351 + /**
352 + * This warning is displayed when the wp-config.php file isn't writable
353 + *
354 + * @since 3.6.1 deprecated
355 + * @since 2.0
356 + */
357 + function rocket_warning_wp_config_permissions() {
358 + _deprecated_function( __FUNCTION__ . '()', '3.6.1', '\WP_Rocket\Engine\Cache\WPCache::notice_wp_config_permissions()' );
359 + $config_file = rocket_find_wpconfig_path();
360 +
361 + if ( ! ( 'plugins.php' === $GLOBALS['pagenow'] && isset( $_GET['activate'] ) ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended
362 +
363 + && current_user_can( 'rocket_manage_options' )
364 + && ( ! rocket_direct_filesystem()->is_writable( $config_file ) && ( ! defined( 'WP_CACHE' ) || ! WP_CACHE ) )
365 + && rocket_valid_key() ) {
366 +
367 + $boxes = get_user_meta( get_current_user_id(), 'rocket_boxes', true );
368 +
369 + if ( in_array( __FUNCTION__, (array) $boxes, true ) ) {
370 + return;
371 + }
372 +
373 + $message = rocket_notice_writing_permissions( 'wp-config.php' );
374 +
375 + rocket_notice_html(
376 + [
377 + 'status' => 'error',
378 + 'dismissible' => '',
379 + 'message' => $message,
380 + 'dismiss_button' => __FUNCTION__,
381 + 'readonly_content' => '/** Enable Cache by ' . WP_ROCKET_PLUGIN_NAME . " */\r\ndefine( 'WP_CACHE', true );\r\n",
382 + ]
383 + );
384 + }
385 + }
386 +
387 + /**
388 + * Try to find the correct wp-config.php file, support one level up in file tree.
389 + *
390 + * @since 3.6 deprecated
391 + * @since 2.1
392 + *
393 + * @return string|bool The path of wp-config.php file or false if not found.
394 + */
395 + function rocket_find_wpconfig_path() {
396 + _deprecated_function( __FUNCTION__ . '()', '3.6.1', '\WP_Rocket\Engine\Cache\WPCache::find_wpconfig_path()' );
397 + /**
398 + * Filter the wp-config's filename.
399 + *
400 + * @since 2.11
401 + *
402 + * @param string $filename The WP Config filename, without the extension.
403 + */
404 + $config_file_name = apply_filters( 'rocket_wp_config_name', 'wp-config' );
405 + $abspath = rocket_get_constant( 'ABSPATH' );
406 + $config_file = "{$abspath}{$config_file_name}.php";
407 + $filesystem = rocket_direct_filesystem();
408 +
409 + if (
410 + $filesystem->exists( $config_file )
411 + &&
412 + $filesystem->is_writable( $config_file )
413 + ) {
414 + return $config_file;
415 + }
416 +
417 + $abspath_parent = dirname( $abspath ) . DIRECTORY_SEPARATOR;
418 + $config_file_alt = "{$abspath_parent}{$config_file_name}.php";
419 +
420 + if (
421 + $filesystem->exists( $config_file_alt )
422 + &&
423 + $filesystem->is_writable( $config_file_alt )
424 + &&
425 + ! $filesystem->exists( "{$abspath_parent}wp-settings.php" )
426 + ) {
427 + return $config_file_alt;
428 + }
429 +
430 + // No writable file found.
431 + return false;
432 + }
433 +
434 + /**
435 + * Define WP_CACHE to true if it's not defined yet.
436 + *
437 + * @since 3.6.1 deprecated
438 + * @since 2.6
439 + */
440 + function rocket_maybe_set_wp_cache_define() {
441 + _deprecated_function( __FUNCTION__ . '()', '3.6.1', '\WP_Rocket\Engine\Cache\WPCache::maybe_set_wp_cache()' );
442 +
443 + if ( defined( 'WP_CACHE' ) && ! WP_CACHE ) {
444 + set_rocket_wp_cache_define( true );
445 + }
446 + }
447 +
448 + /**
449 + * Get all dates archives urls associated to a specific post.
450 + *
451 + * @since 3.6.1 deprecated
452 + * @since 1.0
453 + *
454 + * @param int $post_id The post ID.
455 + *
456 + * @return array $urls List of dates URLs on success; else, an empty [].
457 + */
458 + function get_rocket_post_dates_urls( $post_id ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
459 + _deprecated_function( __FUNCTION__ . '()', '3.6.1', '\WP_Rocket\Engine\Cache\Purge::purge_dates_archives()' );
460 + $time = get_the_time( 'Y-m-d', $post_id );
461 + if ( empty( $time ) ) {
462 + return [];
463 + }
464 +
465 + // Extract and prep the year, month, and day.
466 + $date = explode( '-', $time );
467 + $year = trailingslashit( get_year_link( $date[0] ) );
468 + $month = trailingslashit( get_month_link( $date[0], $date[1] ) );
469 +
470 + $urls = [
471 + "{$year}index.html",
472 + "{$year}index.html_gzip",
473 + $year . $GLOBALS['wp_rewrite']->pagination_base,
474 + "{$month}index.html",
475 + "{$month}index.html_gzip",
476 + $month . $GLOBALS['wp_rewrite']->pagination_base,
477 + get_day_link( $date[0], $date[1], $date[2] ),
478 + ];
479 +
480 + /**
481 + * Filter the list of dates URLs.
482 + *
483 + * @since 1.1.0
484 + *
485 + * @param array $urls List of dates URLs.
486 + */
487 + return (array) apply_filters( 'rocket_post_dates_urls', $urls );
488 + }
489 +
490 + /**
491 + * Added or set the value of the WP_CACHE constant
492 + *
493 + * @since 3.6.1 deprecated
494 + * @since 2.0
495 + *
496 + * @param bool $turn_it_on The value of WP_CACHE constant.
497 + * @return void
498 + */
499 + function set_rocket_wp_cache_define( $turn_it_on ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
500 + _deprecated_function( __FUNCTION__ . '()', '3.6.1', '\WP_Rocket\Engine\Cache\WPCache::set_wp_cache_constant()' );
501 + // If WP_CACHE is already define, return to get a coffee.
502 + if ( ! rocket_valid_key() || ( $turn_it_on && defined( 'WP_CACHE' ) && WP_CACHE ) ) {
503 + return;
504 + }
505 +
506 + if ( defined( 'IS_PRESSABLE' ) && IS_PRESSABLE ) {
507 + return;
508 + }
509 +
510 + // Get path of the config file.
511 + $config_file_path = rocket_find_wpconfig_path();
512 + if ( ! $config_file_path ) {
513 + return;
514 + }
515 +
516 + $filesystem = rocket_direct_filesystem();
517 +
518 + // Get content of the config file.
519 + $config_file_contents = $filesystem->get_contents( $config_file_path );
520 +
521 + // Get the value of WP_CACHE constant.
522 + $turn_it_on = $turn_it_on ? 'true' : 'false';
523 +
524 + /**
525 + * Filter allow to change the value of WP_CACHE constant
526 + *
527 + * @since 2.1
528 + *
529 + * @param string $turn_it_on The value of WP_CACHE constant.
530 + */
531 + $turn_it_on = apply_filters( 'set_rocket_wp_cache_define', $turn_it_on ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
532 +
533 + // Get WP_CACHE constant define.
534 + $constant = "define('WP_CACHE', $turn_it_on); // Added by WP Rocket";
535 +
536 + // Lets find out if the constant WP_CACHE is defined or not.
537 + $wp_cache_found = preg_match( '/^define\(\s*\'WP_CACHE\',(.*)\)/m', $config_file_contents, $matches );
538 +
539 + if ( ! $wp_cache_found ) {
540 + $config_file_contents = preg_replace( '/(<\?php)/i', "<?php\r\n{$constant}\r\n", $config_file_contents );
541 + } elseif ( ! empty( $matches[1] ) && $matches[1] !== $turn_it_on ) {
542 + $config_file_contents = preg_replace( '/^define\(\s*\'WP_CACHE\',(.*)\).+/m', $constant, $config_file_contents );
543 + }
544 +
545 + // Insert the constant in wp-config.php file.
546 + rocket_put_content( $config_file_path, $config_file_contents );
547 + }
548 +
549 + /**
550 + * Get all terms archives urls associated to a specific post
551 + *
552 + * @since 3.6.1 deprecated
553 + * @since 1.0
554 + *
555 + * @param int $post_id The post ID.
556 + * @return array $urls List of taxonomies URLs
557 + */
558 + function get_rocket_post_terms_urls( $post_id ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
559 + _deprecated_function( __FUNCTION__ . '()', '3.6.1', '\WP_Rocket\Engine\Cache\Purge::get_post_terms_urls()' );
560 + $urls = [];
561 + $taxonomies = get_object_taxonomies( get_post_type( $post_id ), 'objects' );
562 +
563 + foreach ( $taxonomies as $taxonomy ) {
564 + if ( ! $taxonomy->public || 'product_shipping_class' === $taxonomy->name ) {
565 + continue;
566 + }
567 +
568 + // Get the terms related to post.
569 + $terms = get_the_terms( $post_id, $taxonomy->name );
570 +
571 + if ( empty( $terms ) ) {
572 + continue;
573 + }
574 + foreach ( $terms as $term ) {
575 + $term_url = get_term_link( $term->slug, $taxonomy->name );
576 + if ( ! is_wp_error( $term_url ) ) {
577 + $urls[] = $term_url;
578 + }
579 + if ( ! is_taxonomy_hierarchical( $taxonomy->name ) ) {
580 + continue;
581 + }
582 + $ancestors = (array) get_ancestors( $term->term_id, $taxonomy->name );
583 + foreach ( $ancestors as $ancestor ) {
584 + $ancestor_object = get_term( $ancestor, $taxonomy->name );
585 + if ( ! $ancestor_object instanceof WP_Term ) {
586 + continue;
587 + }
588 + $ancestor_term_url = get_term_link( $ancestor_object->slug, $taxonomy->name );
589 + if ( ! is_wp_error( $ancestor_term_url ) ) {
590 + $urls[] = $ancestor_term_url;
591 + }
592 + }
593 + }
594 + }
595 +
596 + /**
597 + * Filter the list of taxonomies URLs
598 + *
599 + * @since 1.1.0
600 + *
601 + * @param array $urls List of taxonomies URLs
602 + */
603 + return apply_filters( 'rocket_post_terms_urls', $urls );
604 + }
605 +
606 + /**
607 + * Rules to serve gzip compressed CSS & JS files if they exists and client accepts gzip
608 + *
609 + * @since 3.6.0.3 deprecated
610 + * @since 3.6.0.2 Update rules used to prevent content encoding issue
611 + * @since 3.6
612 + * @author Remy Perona
613 + *
614 + * @return string
615 + */
616 + function rocket_get_compressed_assets_rules() {
617 + _deprecated_function( __FUNCTION__ . '()', '3.6.0.3' );
618 +
619 + $rules = <<<HTACCESS
620 + <IfModule mod_headers.c>
621 + RewriteCond %{HTTP:Accept-Encoding} gzip
622 + RewriteCond %{REQUEST_FILENAME}\.gz -f
623 + RewriteRule \.(css|js)$ %{REQUEST_URI}.gz [L]
624 +
625 + # Prevent mod_deflate double gzip
626 + RewriteRule \.gz$ - [E=no-gzip:1]
627 +
628 + <FilesMatch "\.gz$">
629 +
630 + # Serve correct content types
631 + <IfModule mod_mime.c>
632 + # (1)
633 + RemoveType gz
634 +
635 + # Serve correct content types
636 + AddType text/css css.gz
637 + AddType text/javascript js.gz
638 +
639 + # Serve correct content charset
640 + AddCharset utf-8 .css.gz \
641 + .js.gz
642 + </IfModule>
643 +
644 + # Force proxies to cache gzipped and non-gzipped files separately
645 + Header append Vary Accept-Encoding
646 + </FilesMatch>
647 +
648 + # Serve correct encoding type
649 + AddEncoding gzip .gz
650 + </IfModule>
651 +
652 + HTACCESS;
653 +
654 + return apply_filters( 'rocket_htaccess_compressed_assets', $rules );
655 + }
656 +
657 + /**
658 + * Get list of CSS files to be excluded from async CSS.
659 + *
660 + * @since 3.6.2 deprecated
661 + * @since 2.10
662 + * @author Remy Perona
663 + *
664 + * @return array An array of URLs for the CSS files to be excluded.
665 + */
666 + function get_rocket_exclude_async_css() { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
667 + _deprecated_function( __FUNCTION__ . '()', '3.6.2', '\WP_Rocket\Engine\CriticalPath\CriticalCSS::get_exclude_async_css()' );
668 + /**
669 + * Filter list of async CSS files
670 + *
671 + * @since 2.10
672 + * @author Remy Perona
673 + *
674 + * @param array $exclude_async_css An array of URLs for the CSS files to be excluded.
675 + */
676 + $exclude_async_css = (array) apply_filters( 'rocket_exclude_async_css', [] );
677 + $exclude_async_css = array_filter( $exclude_async_css );
678 + $exclude_async_css = array_flip( array_flip( $exclude_async_css ) );
679 +
680 + return $exclude_async_css;
681 + }
682 +
683 + /**
684 + * Changes the text on the Varnish one-click block.
685 + *
686 + * @deprecated 3.6.1
687 + * @since 3.0
688 + *
689 + * @param array $settings Field settings data.
690 + *
691 + * @return array modified field settings data.
692 + */
693 + function rocket_wpengine_varnish_field( $settings ) {
694 + _deprecated_function( __FUNCTION__ . '()', '3.6.1', '\WP_Rocket\ThirdParty\Hostings\WPEngine::varnish_addon_title' );
695 + $settings['varnish_auto_purge']['title'] = sprintf(
696 + // Translators: %s = Hosting name.
697 + __( 'Your site is hosted on %s, we have enabled Varnish auto-purge for compatibility.', 'rocket' ),
698 + 'WP Engine'
699 + );
700 +
701 + return $settings;
702 + }
703 +
704 + /**
705 + * Conflict with WP Engine caching system.
706 + *
707 + * @deprecated 3.6.1
708 + * @since 2.6.4
709 + *
710 + */
711 + function rocket_stop_generate_caching_files_on_wpengine() {
712 + _deprecated_function( __FUNCTION__ . '()', '3.6.1' );
713 + add_filter( 'do_rocket_generate_caching_files', '__return_false' );
714 + }
715 +
716 + /**
717 + * Run WP Rocket preload bot after purged the Varnish cache via WP Engine Hosting.
718 + *
719 + * @deprecated 3.6.1
720 + * @since 2.6.4
721 + */
722 + function rocket_run_rocket_bot_after_wpengine() {
723 + _deprecated_function( __FUNCTION__ . '()', '3.6.1', '\WP_Rocket\ThirdParty\Hostings\WPEngine::run_rocket_bot_after_wpengine' );
724 + if ( wpe_param( 'purge-all' ) && defined( 'PWP_NAME' ) && check_admin_referer( PWP_NAME . '-config' ) ) {
725 + // Preload cache.
726 + run_rocket_bot();
727 + run_rocket_sitemap_preload();
728 + }
729 + }
730 +
731 + /**
732 + * Call the cache server to purge the cache with WP Engine hosting.
733 + *
734 + * @deprecated 3.6.1
735 + * @since 2.6.4
736 + */
737 + function rocket_clean_wpengine() {
738 + _deprecated_function( __FUNCTION__ . '()', '3.6.1', '\WP_Rocket\ThirdParty\Hostings\WPEngine::clean_wpengine' );
739 + if ( method_exists( 'WpeCommon', 'purge_memcached' ) ) {
740 + WpeCommon::purge_memcached();
741 + }
742 +
743 + if ( method_exists( 'WpeCommon', 'purge_varnish_cache' ) ) {
744 + WpeCommon::purge_varnish_cache();
745 + }
746 + }
747 +
748 + /**
749 + * Gets WP Engine CDN Domain.
750 + *
751 + * @deprecated 3.6.1
752 + * @since 2.8.6
753 + *
754 + * return string $cdn_domain the WP Engine CDN Domain.
755 + */
756 + function rocket_get_wp_engine_cdn_domain() {
757 + _deprecated_function( __FUNCTION__ . '()', '3.6.1' );
758 + global $wpe_netdna_domains, $wpe_netdna_domains_secure;
759 +
760 + $cdn_domain = '';
761 + $is_ssl = '';
762 +
763 + if ( isset( $_SERVER['HTTPS'] ) ) {
764 + $is_ssl = sanitize_text_field( wp_unslash( $_SERVER['HTTPS'] ) );
765 + }
766 +
767 + if ( preg_match( '/^[oO][fF]{2}$/', $is_ssl ) ) {
768 + $is_ssl = false; // have seen this!
769 + }
770 +
771 + $native_schema = $is_ssl ? 'https' : 'http';
772 +
773 + $domains = $wpe_netdna_domains;
774 + // Determine the CDN, if any.
775 + if ( $is_ssl ) {
776 + $domains = $wpe_netdna_domains_secure;
777 + }
778 +
779 + $wpengine = WpeCommon::instance();
780 + $cdn_domain = $wpengine->get_cdn_domain( $domains, home_url(), $is_ssl );
781 +
782 + if ( ! empty( $cdn_domain ) ) {
783 + $cdn_domain = $native_schema . '://' . $cdn_domain;
784 + }
785 +
786 + return $cdn_domain;
787 + }
788 +
789 + /**
790 + * Add WP Rocket footprint on Buffer.
791 + *
792 + * @deprecated 3.6.1
793 + * @since 3.3.2
794 + *
795 + * @param string $buffer HTML content.
796 + *
797 + * @return string HTML with WP Rocket footprint.
798 + */
799 + function rocket_wpengine_add_footprint( $buffer ) {
800 + _deprecated_function( __FUNCTION__ . '()', '3.6.1', '\WP_Rocket\ThirdParty\Hostings\WPEngine::add_footprint' );
801 + if ( ! preg_match( '/<\/html>/i', $buffer ) ) {
802 + return $buffer;
803 + }
804 +
805 + $footprint = defined( 'WP_ROCKET_WHITE_LABEL_FOOTPRINT' )
806 + ? "\n" . '<!-- Optimized for great performance'
807 + : "\n" . '<!-- This website is like a Rocket, isn\'t it? Performance optimized by ' . WP_ROCKET_PLUGIN_NAME . '. Learn more: https://wp-rocket.me';
808 + $footprint .= ' -->';
809 +
810 + return $buffer . $footprint;
811 + }
812 +
813 + /**
814 + * Tell WP what to do when plugin is deactivated.
815 + *
816 + * @since 3.6.3 deprecated
817 + * @since 1.0
818 + */
819 + function rocket_deactivation() {
820 + _deprecated_function( __FUNCTION__ . '()', '3.6.3', '\WP_Rocket\Engine\Deactivation\Deactivation::deactivate_plugin' );
821 + global $is_apache;
822 +
823 + $filesystem = rocket_direct_filesystem();
824 + $wp_cache = new WPCache( $filesystem );
825 +
826 + if ( ! isset( $_GET['rocket_nonce'] ) || ! wp_verify_nonce( sanitize_key( $_GET['rocket_nonce'] ), 'force_deactivation' ) ) {
827 + $causes = [];
828 +
829 + // .htaccess problem.
830 + if ( $is_apache && ! $filesystem->is_writable( get_home_path() . '.htaccess' ) ) {
831 + $causes[] = 'htaccess';
832 + }
833 +
834 + // wp-config problem.
835 + if (
836 + ! $wp_cache->find_wpconfig_path()
837 + &&
838 + // This filter is documented in inc/Engine/Cache/WPCache.php.
839 + (bool) apply_filters( 'rocket_set_wp_cache_constant', true )
840 + ) {
841 + $causes[] = 'wpconfig';
842 + }
843 +
844 + if ( count( $causes ) ) {
845 + set_transient( get_current_user_id() . '_donotdeactivaterocket', $causes );
846 + wp_safe_redirect( wp_get_referer() );
847 + die();
848 + }
849 + }
850 +
851 + // Delete config files.
852 + rocket_delete_config_file();
853 +
854 + if ( ! count( glob( WP_ROCKET_CONFIG_PATH . '*.php' ) ) ) {
855 + // Delete All WP Rocket rules of the .htaccess file.
856 + flush_rocket_htaccess( true );
857 +
858 + // Remove WP_CACHE constant in wp-config.php.
859 + $wp_cache->set_wp_cache_constant( false );
860 +
861 + // Delete content of advanced-cache.php.
862 + rocket_put_content( WP_CONTENT_DIR . '/advanced-cache.php', '' );
863 + }
864 +
865 + // Update customer key & licence.
866 + wp_remote_get(
867 + WP_ROCKET_WEB_API . 'pause-licence.php',
868 + [
869 + 'blocking' => false,
870 + ]
871 + );
872 +
873 + // Delete transients.
874 + delete_transient( 'rocket_check_licence_30' );
875 + delete_transient( 'rocket_check_licence_1' );
876 + delete_site_transient( 'update_wprocket_response' );
877 +
878 + // Unschedule WP Cron events.
879 + wp_clear_scheduled_hook( 'rocket_facebook_tracking_cache_update' );
880 + wp_clear_scheduled_hook( 'rocket_google_tracking_cache_update' );
881 + wp_clear_scheduled_hook( 'rocket_cache_dir_size_check' );
882 +
883 + /**
884 + * WP Rocket deactivation.
885 + *
886 + * @since 3.1.5
887 + * @author Grégory Viguier
888 + */
889 + do_action( 'rocket_deactivation' );
890 +
891 + ( new Capabilities_Subscriber() )->remove_rocket_capabilities();
892 + }
893 +
894 + /**
895 + * Tell WP what to do when plugin is activated.
896 + *
897 + * @since 3.6.3
898 + * @since 1.1.0
899 + */
900 + function rocket_activation() {
901 + _deprecated_function( __FUNCTION__ . '()', '3.6.3', '\WP_Rocket\Engine\Activation\Activation::deactivate_plugin' );
902 + ( new Capabilities_Subscriber() )->add_rocket_capabilities();
903 +
904 + $filesystem = rocket_direct_filesystem();
905 + $wp_cache = new WPCache( $filesystem );
906 +
907 + // Last constants.
908 + define( 'WP_ROCKET_PLUGIN_NAME', 'WP Rocket' );
909 + define( 'WP_ROCKET_PLUGIN_SLUG', sanitize_key( WP_ROCKET_PLUGIN_NAME ) );
910 +
911 + if ( defined( 'SUNRISE' ) && SUNRISE === 'on' && function_exists( 'domain_mapping_siteurl' ) ) {
912 + require WP_ROCKET_INC_PATH . 'domain-mapping.php';
913 + }
914 +
915 + require WP_ROCKET_FUNCTIONS_PATH . 'options.php';
916 + require WP_ROCKET_FUNCTIONS_PATH . 'formatting.php';
917 + require WP_ROCKET_FUNCTIONS_PATH . 'i18n.php';
918 + require WP_ROCKET_FUNCTIONS_PATH . 'htaccess.php';
919 +
920 + if ( rocket_valid_key() ) {
921 + // Add All WP Rocket rules of the .htaccess file.
922 + flush_rocket_htaccess();
923 +
924 + // Add WP_CACHE constant in wp-config.php.
925 + $wp_cache->set_wp_cache_constant( true );
926 + }
927 +
928 + // Create the cache folders (wp-rocket & min).
929 + rocket_init_cache_dir();
930 +
931 + // Create the config folder (wp-rocket-config).
932 + rocket_init_config_dir();
933 +
934 + // Create advanced-cache.php file.
935 + rocket_generate_advanced_cache_file( new AdvancedCache( WP_ROCKET_PATH . 'views/cache/', $filesystem ) );
936 +
937 + /**
938 + * WP Rocket activation.
939 + *
940 + * @since 3.1.5
941 + * @author Grégory Viguier
942 + */
943 + do_action( 'rocket_activation' );
944 +
945 + // Update customer key & licence.
946 + wp_remote_get(
947 + WP_ROCKET_WEB_API . 'activate-licence.php',
948 + [
949 + 'blocking' => false,
950 + ]
951 + );
952 +
953 + wp_remote_get(
954 + home_url(),
955 + [
956 + 'timeout' => 0.01,
957 + 'blocking' => false,
958 + 'user-agent' => 'WP Rocket/Homepage Preload',
959 + 'sslverify' => apply_filters( 'https_local_ssl_verify', false ), // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
960 + ]
961 + );
962 + }
963 +
964 + /**
965 + * Excludes Divi's Salvatorre script from JS minification
966 + *
967 + * Exclude it to prevent an error after minification/concatenation
968 + *
969 + * @since 3.6.3 deprecated
970 + * @since 2.9
971 + * @author Remy Perona
972 + *
973 + * @param Array $excluded_js An array of JS paths to be excluded.
974 + * @return Array the updated array of paths
975 + */
976 + function rocket_exclude_js_divi( $excluded_js ) {
977 + _deprecated_function( __FUNCTION__ . '()', '3.6.3', '\WP_Rocket\ThirdParty\Themes\Divi::exclude_js' );
978 + if ( defined( 'ET_BUILDER_URI' ) ) {
979 + $excluded_js[] = str_replace( home_url(), '', ET_BUILDER_URI ) . '/scripts/salvattore.min.js';
980 + }
981 +
982 + return $excluded_js;
983 + }
984 +
985 + /**
986 + * Changes the text on the Varnish one-click block.
987 + *
988 + * @since 3.1
989 + *
990 + * @param array $settings Field settings data.
991 + *
992 + * @return array modified field settings data.
993 + */
994 + function rocket_o2switch_varnish_field( $settings ) {
995 + _deprecated_function( __FUNCTION__ . '()', '3.6.3', '\WP_Rocket\ThirdParty\Hostings\O2Switch::varnish_addon_title' );
996 + // Translators: %s = Hosting name.
997 + $settings['varnish_auto_purge']['title'] = sprintf( __( 'Your site is hosted on %s, we have enabled Varnish auto-purge for compatibility.', 'rocket' ), 'o2switch' );
998 +
999 + return $settings;
1000 + }
1001 +
1002 + /**
1003 + * Purge all the domain.
1004 + *
1005 + * @since 3.1
1006 + *
1007 + * @param string $root The path of home cache file.
1008 + * @param string $lang The current lang to purge.
1009 + * @param string $url The home url.
1010 + */
1011 + function rocket_o2switch_varnish_clean_domain( $root, $lang, $url ) {
1012 + _deprecated_function( __FUNCTION__ . '()', '3.6.3', '\WP_Rocket\ThirdParty\Hostings\O2Switch::varnish_clean_domain' );
1013 + rocket_o2switch_varnish_http_purge( trailingslashit( $url ) . '?vregex' );
1014 + }
1015 +
1016 + /**
1017 + * Purge a specific page.
1018 + *
1019 + * @since 3.1
1020 + *
1021 + * @param string $url The url to purge.
1022 + */
1023 + function rocket_o2switch_varnish_clean_file( $url ) {
1024 + _deprecated_function( __FUNCTION__ . '()', '3.6.3', '\WP_Rocket\ThirdParty\Hostings\O2Switch::varnish_clean_file' );
1025 + rocket_o2switch_varnish_http_purge( trailingslashit( $url ) . '?vregex' );
1026 + }
1027 +
1028 + /**
1029 + * Purge the homepage and its pagination.
1030 + *
1031 + * @since 3.1
1032 + *
1033 + * @param string $root The path of home cache file.
1034 + * @param string $lang The current lang to purge.
1035 + */
1036 + function rocket_o2switch_varnish_clean_home( $root, $lang ) {
1037 + _deprecated_function( __FUNCTION__ . '()', '3.6.3', '\WP_Rocket\ThirdParty\Hostings\O2Switch::varnish_clean_home' );
1038 + $home_url = trailingslashit( get_rocket_i18n_home_url( $lang ) );
1039 + $home_pagination_url = $home_url . trailingslashit( $GLOBALS['wp_rewrite']->pagination_base ) . '?vregex';
1040 +
1041 + rocket_o2switch_varnish_http_purge( $home_url );
1042 + rocket_o2switch_varnish_http_purge( $home_pagination_url );
1043 + }
1044 +
1045 + /**
1046 + * Send data to Varnish.
1047 + *
1048 + * @since 3.1
1049 + *
1050 + * @param string $url The URL to purge.
1051 + */
1052 + function rocket_o2switch_varnish_http_purge( $url ) {
1053 + _deprecated_function( __FUNCTION__ . '()', '3.6.3', '\WP_Rocket\ThirdParty\Hostings\O2Switch::varnish_http_purge' );
1054 + $parse_url = get_rocket_parse_url( $url );
1055 +
1056 + // This filter is documented in inc/functions/varnish.php.
1057 + $headers = apply_filters(
1058 + 'rocket_varnish_purge_headers',
1059 + [
1060 + /**
1061 + * Filters the host value passed in the request headers
1062 + *
1063 + * @since 2.8.15
1064 + * @param string The host
1065 + */
1066 + 'host' => apply_filters( 'rocket_varnish_purge_request_host', $parse_url['host'] ),
1067 + 'X-VC-Purge-Key' => O2SWITCH_VARNISH_PURGE_KEY,
1068 + ]
1069 + );
1070 +
1071 + if ( 'vregex' === $parse_url['query'] ) {
1072 + $headers['X-Purge-Regex'] = '.*';
1073 + }
1074 +
1075 + /**
1076 + * Filter the Varnish IP to call
1077 + *
1078 + * @since 2.6.8
1079 + *
1080 + * @param string The Varnish IP
1081 + */
1082 + $varnish_ip = apply_filters( 'rocket_varnish_ip', [] );
1083 +
1084 + if ( defined( 'WP_ROCKET_VARNISH_IP' ) && ! $varnish_ip ) {
1085 + $varnish_ip = WP_ROCKET_VARNISH_IP;
1086 + }
1087 +
1088 + /**
1089 + * Filter the HTTP protocol (scheme)
1090 + *
1091 + * @since 2.7.3
1092 + *
1093 + * @param string The HTTP protocol
1094 + */
1095 + $scheme = apply_filters( 'rocket_varnish_http_purge_scheme', $parse_url['scheme'] );
1096 +
1097 + $parse_url['host'] = ( $varnish_ip ) ? $varnish_ip : $parse_url['host'];
1098 + $purgeme = $scheme . '://' . $parse_url['host'] . $parse_url['path'];
1099 +
1100 + wp_remote_request(
1101 + $purgeme,
1102 + [
1103 + 'method' => 'PURGE',
1104 + 'blocking' => false,
1105 + 'redirection' => 0,
1106 + 'headers' => $headers,
1107 + ]
1108 + );
1109 + }
1110 +
1111 + /**
1112 + * Remove expiration on HTML to prevent issue with Varnish cache.
1113 + *
1114 + * @since 3.1
1115 + *
1116 + * @param string $rules htaccess rules.
1117 + *
1118 + * @return string Updated htaccess rules.
1119 + */
1120 + function rocket_o2switch_remove_html_expire( $rules ) {
1121 + _deprecated_function( __FUNCTION__ . '()', '3.6.3', '\WP_Rocket\ThirdParty\Hostings\O2Switch::remove_html_expire' );
1122 + $rules = preg_replace( '@\s*#\s*Your document html@', '', $rules );
1123 + $rules = preg_replace( '@\s*ExpiresByType text/html\s*"access plus \d+ (seconds|minutes|hour|week|month|year)"@', '', $rules );
1124 +
1125 + return $rules;
1126 + }
1127 +