3.11.php
7.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
<?php
/**
* Add Yoast SEO sitemap option to WP Rocket default options
*
* @since 2.8
* @since 3.11.1 deprecated
*
* @author Remy Perona
*
* @param array $options WP Rocket options array.
* @return array Updated WP Rocket options array
*/
function rocket_add_yoast_seo_sitemap_option( $options ) {
_deprecated_function( __FUNCTION__ . '()', '3.11.1' );
$options['yoast_xml_sitemap'] = 0;
return $options;
}
/**
* Sanitize Yoast SEO sitemap option value
*
* @since 2.8
* @since 3.11.1 deprecated
*
* @author Remy Perona
*
* @param array $inputs WP Rocket inputs array.
* @return array Sanitized WP Rocket inputs array
*/
function rocket_yoast_seo_sitemap_option_sanitize( $inputs ) {
_deprecated_function( __FUNCTION__ . '()', '3.11.1' );
$inputs['yoast_xml_sitemap'] = ! empty( $inputs['yoast_xml_sitemap'] ) ? 1 : 0;
return $inputs;
}
/**
* Add Yoast SEO sitemap URL to the sitemaps to preload
*
* @since 2.8
* @since 3.11.1 deprecated
*
* @author Remy Perona
*
* @param array $sitemaps Sitemaps to preload.
* @return array Updated Sitemaps to preload
*/
function rocket_add_yoast_seo_sitemap( $sitemaps ) {
_deprecated_function( __FUNCTION__ . '()', '3.11.1' );
if ( get_rocket_option( 'yoast_xml_sitemap', false ) ) {
$sitemaps[] = WPSEO_Sitemaps_Router::get_base_url( 'sitemap_index.xml' );
}
return $sitemaps;
}
/**
* Add Yoast SEO option to WP Rocket settings
*
* @since 2.8
* @since 3.11.1 deprecated
*
* @author Remy Perona
*
* @param array $options WP Rocket settings array.
* @return array Updated WP Rocket settings array
*/
function rocket_sitemap_preload_yoast_seo_option( $options ) {
_deprecated_function( __FUNCTION__ . '()', '3.11.1' );
$options['yoast_xml_sitemap'] = [
'type' => 'checkbox',
'container_class' => [
'wpr-field--children',
],
'label' => __( 'Yoast SEO XML sitemap', 'rocket' ),
// translators: %s = Name of the plugin.
'description' => sprintf( __( 'We automatically detected the sitemap generated by the %s plugin. You can check the option to preload it.', 'rocket' ), 'Yoast SEO' ),
'parent' => 'sitemap_preload',
'section' => 'preload_section',
'page' => 'preload',
'default' => 0,
'sanitize_callback' => 'sanitize_checkbox',
];
return $options;
}
/**
* Clear Kinsta cache when clearing WP Rocket cache
*
* @since 3.0
* @author Remy Perona
*
* @return void
*/
function rocket_clean_kinsta_cache() {
global $kinsta_cache;
_deprecated_function( __FUNCTION__ . '()', '3.11.1' );
if ( ! empty( $kinsta_cache->kinsta_cache_purge ) ) {
$kinsta_cache->kinsta_cache_purge->purge_complete_caches();
}
}
/**
* Partially clear Kinsta cache when partially clearing WP Rocket cache
*
* @since 3.0
* @author Remy Perona
*
* @param object $post Post object.
* @return void
*/
function rocket_clean_kinsta_post_cache( $post ) {
_deprecated_function( __FUNCTION__ . '()', '3.11.1' );
global $kinsta_cache;
$kinsta_cache->kinsta_cache_purge->initiate_purge( $post->ID, 'post' );
}
/**
* Clears Kinsta cache for the homepage URL when using "Purge this URL" from the admin bar on the front end
*
* @since 3.0.4
* @author Remy Perona
*
* @param string $root WP Rocket root cache path.
* @param string $lang Current language.
* @return void
*/
function rocket_clean_kinsta_cache_home( $root = '', $lang = '' ) {
_deprecated_function( __FUNCTION__ . '()', '3.11.1' );
$url = get_rocket_i18n_home_url( $lang );
$url = trailingslashit( $url ) . 'kinsta-clear-cache/';
wp_remote_get(
$url,
[
'blocking' => false,
'timeout' => 0.01,
]
);
}
/**
* Clears Kinsta cache for a specific URL when using "Purge this URL" from the admin bar on the front end
*
* @since 3.0.4
* @author Remy Perona
*
* @param string $url URL to purge.
* @return void
*/
function rocket_clean_kinsta_cache_url( $url ) {
_deprecated_function( __FUNCTION__ . '()', '3.11.1' );
$url = trailingslashit( $url ) . 'kinsta-clear-cache/';
wp_remote_get(
$url,
[
'blocking' => false,
'timeout' => 0.01,
]
);
}
/**
* Remove WP Rocket functions on WP core action hooks to prevent triggering a double cache clear.
*
* @since 3.0
* @author Remy Perona
*
* @return void
*/
function rocket_remove_partial_purge_hooks() {
_deprecated_function( __FUNCTION__ . '()', '3.11.1' );
// WP core action hooks rocket_clean_post() gets hooked into.
$clean_post_hooks = [
// Disables the refreshing of partial cache when content is edited.
'wp_trash_post',
'delete_post',
'clean_post_cache',
'wp_update_comment_count',
];
// Remove rocket_clean_post() from core action hooks.
array_map(
function( $hook ) {
remove_action( $hook, 'rocket_clean_post' );
},
$clean_post_hooks
);
remove_filter( 'rocket_clean_files', 'rocket_clean_files_users' );
}
/**
* Do the rollback
*
* @since 3.11.5 deprecated
* @since 2.4
*/
function rocket_rollback() {
_deprecated_function( __FUNCTION__ . '()', '3.11.5' );
if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( $_GET['_wpnonce'] ), 'rocket_rollback' ) ) {
wp_nonce_ays( '' );
}
/**
* Fires before doing the rollback
*/
do_action( 'rocket_before_rollback' );
$plugin_transient = get_site_transient( 'update_plugins' );
$plugin_folder = plugin_basename( dirname( WP_ROCKET_FILE ) );
$plugin = $plugin_folder . '/' . basename( WP_ROCKET_FILE );
$plugin_transient->response[ $plugin ] = (object) [
'slug' => $plugin_folder,
'new_version' => WP_ROCKET_LASTVERSION,
'url' => 'https://wp-rocket.me',
'package' => sprintf( 'https://wp-rocket.me/%s/wp-rocket_%s.zip', get_rocket_option( 'consumer_key' ), WP_ROCKET_LASTVERSION ),
];
set_site_transient( 'update_plugins', $plugin_transient );
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
// translators: %s is the plugin name.
$title = sprintf( __( '%s Update Rollback', 'rocket' ), WP_ROCKET_PLUGIN_NAME );
$nonce = 'upgrade-plugin_' . $plugin;
$url = 'update.php?action=upgrade-plugin&plugin=' . rawurlencode( $plugin );
$upgrader_skin = new Plugin_Upgrader_Skin( compact( 'title', 'nonce', 'url', 'plugin' ) );
$upgrader = new Plugin_Upgrader( $upgrader_skin );
remove_filter( 'site_transient_update_plugins', 'rocket_check_update', 1 );
add_filter( 'update_plugin_complete_actions', 'rocket_rollback_add_return_link' );
rocket_put_content( WP_CONTENT_DIR . '/advanced-cache.php', '' );
$upgrader->upgrade( $plugin );
wp_die(
'',
// translators: %s is the plugin name.
esc_html( sprintf( __( '%s Update Rollback', 'rocket' ), WP_ROCKET_PLUGIN_NAME ) ),
[
'response' => 200,
]
);
}
/**
* After a rollback has been done, replace the "return to" link by a link pointing to WP Rocket's tools page.
* A link to the plugins page is kept in case the plugin is not reactivated correctly.
*
* @since 3.11.5 deprecated
* @since 3.2.4
* @author Grégory Viguier
* @author Arun Basil Lal
*
* @param array $update_actions Array of plugin action links.
* @return array The array of links where the "return to" link has been replaced.
*/
function rocket_rollback_add_return_link( $update_actions ) {
_deprecated_function( __FUNCTION__ . '()', '3.11.5' );
if ( ! isset( $update_actions['plugins_page'] ) ) {
return $update_actions;
}
$update_actions['plugins_page'] = sprintf(
/* translators: 1 and 3 are link openings, 2 is a link closing. */
__( '%1$sReturn to WP Rocket%2$s or %3$sgo to Plugins page%2$s', 'rocket' ),
'<a href="' . esc_url( admin_url( 'options-general.php?page=' . WP_ROCKET_PLUGIN_SLUG ) . '#tools' ) . '" target="_parent">',
'</a>',
'<a href="' . esc_url( admin_url( 'plugins.php' ) ) . '" target="_parent">'
);
return $update_actions;
}