Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/wp-rocket/inc/3rd-party/plugins/nginx-helper.php

Keine Baseline-Datei – Diff nur gegen leer.
Zur Liste
1 -
1 + <?php
2 +
3 + defined( 'ABSPATH' ) || exit;
4 +
5 + global $nginx_helper;
6 +
7 + if ( isset( $nginx_helper ) ) :
8 + global $nginx_purger;
9 +
10 + /**
11 + * Clear WP Rocket cache after the NGINX cache is purged from Nginx Helper.
12 + *
13 + * @since 3.3.0.1
14 + *
15 + * @return void
16 + */
17 + function rocket_clear_cache_after_nginx_helper_purge() {
18 + if ( ! isset( $_GET['nginx_helper_action'] ) ) {
19 + return;
20 + }
21 +
22 + if ( ! check_admin_referer( 'nginx_helper-purge_all' ) ) {
23 + return;
24 + }
25 +
26 + if ( 'done' !== sanitize_text_field( wp_unslash( $_GET['nginx_helper_action'] ) ) ) {
27 + return;
28 + }
29 +
30 + if ( ! current_user_can( 'rocket_purge_cache' ) ) {
31 + return;
32 + }
33 +
34 + // Clear all caching files.
35 + rocket_clean_domain();
36 + }
37 + add_action( 'admin_init', 'rocket_clear_cache_after_nginx_helper_purge' );
38 +
39 + /**
40 + * Clear WP Rocket cache for the current page after the NGINX cache is purged from Nginx Helper.
41 + *
42 + * @since 3.3.0.1
43 + *
44 + * @return void
45 + */
46 + function rocket_clear_current_page_after_nginx_helper_purge() {
47 + if ( ! isset( $_GET['nginx_helper_action'], $_GET['_wpnonce'] ) ) {
48 + return;
49 + }
50 +
51 + if ( ! wp_verify_nonce( sanitize_key( $_GET['_wpnonce'] ), 'nginx_helper-purge_all' ) ) {
52 + return;
53 + }
54 +
55 + if ( is_admin() ) {
56 + return;
57 + }
58 +
59 + if ( ! current_user_can( 'rocket_purge_posts' ) ) {
60 + return;
61 + }
62 +
63 + $referer = wp_get_referer();
64 +
65 + if ( 0 !== strpos( $referer, 'http' ) ) {
66 + $parse_url = get_rocket_parse_url( untrailingslashit( home_url() ) );
67 + $referer = $parse_url['scheme'] . '://' . $parse_url['host'] . $referer;
68 + }
69 +
70 + if ( home_url( '/' ) === $referer ) {
71 + rocket_clean_home();
72 + return;
73 + }
74 +
75 + rocket_clean_files( $referer );
76 + }
77 + add_action( 'init', 'rocket_clear_current_page_after_nginx_helper_purge' );
78 +
79 + /**
80 + * Clears NGINX cache for the homepage URL when using "Purge this URL" from the admin bar on the front end
81 + *
82 + * @since 3.3.0.1
83 + * @author Remy Perona
84 + *
85 + * @param string $root WP Rocket root cache path.
86 + * @param string $lang Current language.
87 + * @return void
88 + */
89 + function rocket_clean_nginx_cache_home( $root = '', $lang = '' ) {
90 + global $nginx_purger;
91 +
92 + if ( ! isset( $nginx_purger ) ) {
93 + return;
94 + }
95 +
96 + $url = get_rocket_i18n_home_url( $lang );
97 +
98 + $nginx_purger->purge_url( $url );
99 + }
100 + add_action( 'after_rocket_clean_home', 'rocket_clean_nginx_cache_home', 10, 2 );
101 +
102 + /**
103 + * Clears NGINX cache for a specific URL when using "Purge this URL" from the admin bar on the front end
104 + *
105 + * @since 3.3.0.1
106 + * @author Remy Perona
107 + *
108 + * @param string $url URL to purge.
109 + * @return void
110 + */
111 + function rocket_clean_nginx_cache_url( $url ) {
112 + global $nginx_purger;
113 +
114 + if ( ! isset( $nginx_purger ) ) {
115 + return;
116 + }
117 +
118 + if ( ! isset( $_GET['type'], $_GET['_wpnonce'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
119 + return;
120 + }
121 +
122 + if ( false !== strpos( $url, 'index.html' ) ) {
123 + return;
124 + }
125 +
126 + if ( 'page' === substr( $url, -4 ) ) {
127 + return;
128 + }
129 +
130 + $url = str_replace( '*', '', $url );
131 +
132 + $nginx_purger->purge_url( $url );
133 + }
134 + add_action( 'after_rocket_clean_file', 'rocket_clean_nginx_cache_url' );
135 +
136 + /**
137 + * Clean the NGINX cache using Nginx Helper after WP Rocket's cache is purged.
138 + *
139 + * @since 3.3.0.1
140 + */
141 + function rocket_clean_nginx_helper_cache() {
142 + if ( isset( $_GET['nginx_helper_action'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
143 + return;
144 + }
145 +
146 + do_action( 'rt_nginx_helper_purge_all' ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
147 + }
148 + add_action( 'rocket_after_clean_domain', 'rocket_clean_nginx_helper_cache' );
149 +
150 + /**
151 + * Clean the NGINX cache after the Used CSS has been generated.
152 + *
153 + * @since 3.12.3
154 + */
155 + add_action( 'rocket_rucss_after_clearing_usedcss', 'rocket_clean_nginx_cache_url' );
156 + add_action( 'rocket_saas_complete_job_status', 'rocket_clean_nginx_helper_cache' );
157 +
158 + endif;
159 +