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

Keine Baseline-Datei – Diff nur gegen leer.
Zur Liste
1 -
1 + <?php
2 + defined( 'ABSPATH' ) || exit;
3 +
4 + /**
5 + * This warning is displayed when the API KEY isn't already set or not valid
6 + *
7 + * @since 1.0
8 + */
9 + function rocket_need_api_key() {
10 + $message = '';
11 + $errors = (array) get_transient( 'rocket_check_key_errors' );
12 +
13 + foreach ( $errors as $error ) {
14 + $message .= '<p>' . $error . '</p>';
15 + }
16 +
17 + ?>
18 + <div class="notice notice-error">
19 + <p><strong><?php echo esc_html( WP_ROCKET_PLUGIN_NAME ); ?></strong>
20 + <?php
21 + echo esc_html( _n( 'There seems to be an issue validating your license. Please see the error message below.', 'There seems to be an issue validating your license. You can see the error messages below.', count( $errors ), 'rocket' ) );
22 + ?>
23 + </p>
24 + <?php echo wp_kses_post( $message ); ?>
25 + </div>
26 + <?php
27 + }
28 +
29 + /**
30 + * Renew all boxes for everyone if $uid is missing
31 + *
32 + * @since 1.1.10
33 + * @modified 2.1 :
34 + * - Better usage of delete_user_meta into delete_metadata
35 + *
36 + * @param (int|null) $uid : a User id, can be null, null = all users.
37 + * @param (string|array) $keep_this : which box have to be kept.
38 + * @return void
39 + */
40 + function rocket_renew_all_boxes( $uid = null, $keep_this = [] ) {
41 + // Delete a user meta for 1 user or all at a time.
42 + delete_metadata( 'user', $uid, 'rocket_boxes', '', ! $uid );
43 +
44 + // $keep_this works only for the current user.
45 + if ( ! empty( $keep_this ) && null !== $uid ) {
46 + if ( ! is_array( $keep_this ) ) {
47 + $keep_this = (array) $keep_this;
48 + }
49 +
50 + foreach ( $keep_this as $kt ) {
51 + rocket_dismiss_box( $kt );
52 + }
53 + }
54 + }
55 +
56 + /**
57 + * Renew a dismissed error box admin side
58 + *
59 + * @since 1.1.10
60 + *
61 + * @param string $function function name.
62 + * @param int $uid User ID.
63 + * @return void
64 + */
65 + function rocket_renew_box( $function, $uid = 0 ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.functionFound
66 + global $current_user;
67 + $uid = 0 === $uid ? $current_user->ID : $uid;
68 + $actual = get_user_meta( $uid, 'rocket_boxes', true );
69 +
70 + if ( $actual && false !== array_search( $function, $actual, true ) ) {
71 + unset( $actual[ array_search( $function, $actual, true ) ] );
72 + update_user_meta( $uid, 'rocket_boxes', $actual );
73 + }
74 + }
75 +
76 + /**
77 + * Dismiss one box.
78 + *
79 + * @since 1.3.0
80 + * @since 3.6 Doesn’t die anymore.
81 + *
82 + * @param string $function Function (box) name.
83 + */
84 + function rocket_dismiss_box( $function ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.functionFound
85 + $actual = get_user_meta( get_current_user_id(), 'rocket_boxes', true );
86 + $actual = array_merge( (array) $actual, [ $function ] );
87 + $actual = array_filter( $actual );
88 + $actual = array_unique( $actual );
89 +
90 + update_user_meta( get_current_user_id(), 'rocket_boxes', $actual );
91 + delete_transient( $function );
92 + }
93 +
94 + /**
95 + * Create a unique id for some Rocket options and functions
96 + *
97 + * @since 2.1
98 + */
99 + function create_rocket_uniqid() { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
100 + return str_replace( '.', '', uniqid( '', true ) );
101 + }
102 +
103 + /**
104 + * Gets names of all active plugins.
105 + *
106 + * @since 2.11 Only get the name
107 + * @since 2.6
108 + *
109 + * @return array An array of active plugins names.
110 + */
111 + function rocket_get_active_plugins() {
112 + $plugins = [];
113 + $active_plugins = array_intersect_key( get_plugins(), array_flip( array_filter( array_keys( get_plugins() ), 'is_plugin_active' ) ) );
114 +
115 + foreach ( $active_plugins as $plugin ) {
116 + $plugins[] = $plugin['Name'];
117 + }
118 +
119 + return $plugins;
120 + }
121 +
122 + /**
123 + * Check if the whole website is on the SSL protocol
124 + *
125 + * @since 3.3.6 Use the superglobal $_SERVER values to detect SSL.
126 + * @since 2.7
127 + */
128 + function rocket_is_ssl_website() {
129 + if ( isset( $_SERVER['HTTPS'] ) ) {
130 + $https = sanitize_text_field( wp_unslash( $_SERVER['HTTPS'] ) );
131 +
132 + if ( 'on' === strtolower( $https ) ) {
133 + return true;
134 + }
135 +
136 + if ( '1' === (string) $https ) {
137 + return true;
138 + }
139 + } elseif ( isset( $_SERVER['SERVER_PORT'] ) && '443' === (string) sanitize_text_field( wp_unslash( $_SERVER['SERVER_PORT'] ) ) ) {
140 + return true;
141 + }
142 +
143 + return false;
144 + }
145 +
146 + /**
147 + * Get the WP Rocket documentation URL
148 + *
149 + * @since 2.7
150 + */
151 + function get_rocket_documentation_url() { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
152 + $langs = [
153 + 'fr_FR' => 'fr.',
154 + ];
155 + $lang = get_locale();
156 + $prefix = isset( $langs[ $lang ] ) ? $langs[ $lang ] : '';
157 + $url = "https://{$prefix}docs.wp-rocket.me/?utm_source=wp_plugin&utm_medium=wp_rocket";
158 +
159 + return $url;
160 + }
161 +
162 + /**
163 + * Get WP Rocket FAQ URL
164 + *
165 + * @since 2.10
166 + * @author Remy Perona
167 + *
168 + * @return string URL in the correct language
169 + */
170 + function get_rocket_faq_url() { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
171 + $langs = [
172 + 'de' => 1,
173 + 'es' => 1,
174 + 'fr' => 1,
175 + 'it' => 1,
176 + ];
177 + $locale = explode( '_', get_locale() );
178 + $lang = isset( $langs[ $locale[0] ] ) ? $locale[0] . '/' : '';
179 + $url = WP_ROCKET_WEB_MAIN . "{$lang}faq/?utm_source=wp_plugin&utm_medium=wp_rocket";
180 +
181 + return $url;
182 + }
183 +
184 + /**
185 + * Get the Activation Link for a given plugin
186 + *
187 + * @since 2.7.3
188 + * @author Geoffrey Crofte
189 + *
190 + * @param string $plugin the given plugin folder/file.php (e.i. "imagify/imagify.php").
191 + * @return string URL to activate the plugin
192 + */
193 + function rocket_get_plugin_activation_link( $plugin ) {
194 + $activation_url = wp_nonce_url( 'plugins.php?action=activate&amp;plugin=' . $plugin . '&amp;plugin_status=all&amp;paged=1&amp;s', 'activate-plugin_' . $plugin );
195 +
196 + return $activation_url;
197 + }
198 +
199 + /**
200 + * Check if a given plugin is installed but not necessarily activated
201 + * Note: get_plugins( $folder ) from WP Core doesn't work
202 + *
203 + * @since 2.7.3
204 + * @author Geoffrey Crofte
205 + *
206 + * @param string $plugin a plugin folder/file.php (e.i. "imagify/imagify.php").
207 + * @return bool True if installed, false otherwise
208 + */
209 + function rocket_is_plugin_installed( $plugin ) {
210 + $installed_plugins = get_plugins();
211 +
212 + return isset( $installed_plugins[ $plugin ] );
213 + }
214 +
215 + /**
216 + * When Woocommerce, EDD, iThemes Exchange, Jigoshop & WP-Shop options are saved or deleted,
217 + * we update .htaccess & config file to get the right checkout page to exclude to the cache.
218 + *
219 + * @since 2.9.3 Support for SF Move Login moved to 3rd party file
220 + * @since 2.6 Add support with SF Move Login & WPS Hide Login to exclude login pages
221 + * @since 2.4
222 + *
223 + * @param array $old_value An array of previous settings values.
224 + * @param array $value An array of submitted settings values.
225 + */
226 + function rocket_after_update_single_options( $old_value, $value ) {
227 + if ( $old_value !== $value ) {
228 + // Update .htaccess file rules.
229 + flush_rocket_htaccess();
230 +
231 + // Update config file.
232 + rocket_generate_config_file();
233 + }
234 + }
235 +
236 + /**
237 + * We need to regenerate the config file + htaccess depending on some plugins
238 + *
239 + * @since 2.9.3 Support for SF Move Login moved to 3rd party file
240 + * @since 2.6.5 Add support with SF Move Login & WPS Hide Login
241 + *
242 + * @param array $old_value An array of previous settings values.
243 + * @param array $value An array of submitted settings values.
244 + */
245 + function rocket_after_update_array_options( $old_value, $value ) {
246 + $options = [
247 + 'purchase_page',
248 + 'jigoshop_cart_page_id',
249 + 'jigoshop_checkout_page_id',
250 + 'jigoshop_myaccount_page_id',
251 + ];
252 +
253 + foreach ( $options as $val ) {
254 + if ( ( ! isset( $old_value[ $val ] ) && isset( $value[ $val ] ) ) ||
255 + ( isset( $old_value[ $val ], $value[ $val ] ) && $old_value[ $val ] !== $value[ $val ] )
256 + ) {
257 + // Update .htaccess file rules.
258 + flush_rocket_htaccess();
259 +
260 + // Update config file.
261 + rocket_generate_config_file();
262 + break;
263 + }
264 + }
265 + }
266 +
267 + /**
268 + * Check if a mobile plugin is active
269 + *
270 + * @since 2.10
271 + * @author Remy Perona
272 + *
273 + * @return bool true if a mobile plugin in the list is active, false otherwise.
274 + **/
275 + function rocket_is_mobile_plugin_active() {
276 + return \WP_Rocket\Subscriber\Third_Party\Plugins\Mobile_Subscriber::is_mobile_plugin_active();
277 + }
278 +
279 + /**
280 + * Allow upload of JSON file.
281 + *
282 + * @since 2.10.7
283 + * @author Remy Perona
284 + *
285 + * @param array $wp_get_mime_types Array of allowed mime types.
286 + * @return array Updated array of allowed mime types
287 + */
288 + function rocket_allow_json_mime_type( $wp_get_mime_types ) {
289 + $wp_get_mime_types['json'] = 'application/json';
290 +
291 + return $wp_get_mime_types;
292 + }
293 +
294 + /**
295 + * Forces the correct file type for JSON file if the WP checks is incorrect
296 + *
297 + * @since 3.2.3.1
298 + * @author Gregory Viguier
299 + *
300 + * @param array $wp_check_filetype_and_ext File data array containing 'ext', 'type', and
301 + * 'proper_filename' keys.
302 + * @param string $file Full path to the file.
303 + * @param string $filename The name of the file (may differ from $file due to
304 + * $file being in a tmp directory).
305 + * @param array $mimes Key is the file extension with value as the mime type.
306 + * @return array
307 + */
308 + function rocket_check_json_filetype( $wp_check_filetype_and_ext, $file, $filename, $mimes ) {
309 + if ( ! empty( $wp_check_filetype_and_ext['ext'] ) && ! empty( $wp_check_filetype_and_ext['type'] ) ) {
310 + return $wp_check_filetype_and_ext;
311 + }
312 +
313 + $wp_filetype = wp_check_filetype( $filename, $mimes );
314 +
315 + if ( 'json' !== $wp_filetype['ext'] ) {
316 + return $wp_check_filetype_and_ext;
317 + }
318 +
319 + if ( empty( $wp_filetype['type'] ) ) {
320 + // In case some other filter messed it up.
321 + $wp_filetype['type'] = 'application/json';
322 + }
323 +
324 + if ( ! extension_loaded( 'fileinfo' ) ) {
325 + return $wp_check_filetype_and_ext;
326 + }
327 +
328 + $finfo = finfo_open( FILEINFO_MIME_TYPE );
329 + $real_mime = finfo_file( $finfo, $file );
330 + finfo_close( $finfo );
331 +
332 + if ( 'text/plain' !== $real_mime ) {
333 + return $wp_check_filetype_and_ext;
334 + }
335 +
336 + $wp_check_filetype_and_ext = array_merge( $wp_check_filetype_and_ext, $wp_filetype );
337 +
338 + return $wp_check_filetype_and_ext;
339 + }
340 +
341 + /**
342 + * Lists Data collected for analytics
343 + *
344 + * @since 2.11
345 + * @author Caspar Hübinger
346 + *
347 + * @return string HTML list table
348 + */
349 + function rocket_data_collection_preview_table() {
350 + $data = rocket_analytics_data();
351 +
352 + if ( ! $data ) {
353 + return;
354 + }
355 +
356 + $html = '<table class="wp-rocket-data-table widefat striped">';
357 + $html .= '<tbody>';
358 +
359 + $html .= '<tr>';
360 + $html .= '<td class="column-primary">';
361 + $html .= sprintf( '<strong>%s</strong>', __( 'Server type:', 'rocket' ) );
362 + $html .= '</td>';
363 + $html .= '<td>';
364 + $html .= sprintf( '<em>%s</em>', $data['web_server'] );
365 + $html .= '</td>';
366 + $html .= '</tr>';
367 +
368 + $html .= '<tr>';
369 + $html .= '<td class="column-primary">';
370 + $html .= sprintf( '<strong>%s</strong>', __( 'PHP version number:', 'rocket' ) );
371 + $html .= '</td>';
372 + $html .= '<td>';
373 + $html .= sprintf( '<em>%s</em>', $data['php_version'] );
374 + $html .= '</td>';
375 + $html .= '</tr>';
376 +
377 + $html .= '<tr>';
378 + $html .= '<td class="column-primary">';
379 + $html .= sprintf( '<strong>%s</strong>', __( 'WordPress version number:', 'rocket' ) );
380 + $html .= '</td>';
381 + $html .= '<td>';
382 + $html .= sprintf( '<em>%s</em>', $data['wordpress_version'] );
383 + $html .= '</td>';
384 + $html .= '</tr>';
385 +
386 + $html .= '<tr>';
387 + $html .= '<td class="column-primary">';
388 + $html .= sprintf( '<strong>%s</strong>', __( 'WordPress multisite:', 'rocket' ) );
389 + $html .= '</td>';
390 + $html .= '<td>';
391 + $html .= sprintf( '<em>%s</em>', $data['multisite'] ? 'true' : 'false' );
392 + $html .= '</td>';
393 + $html .= '</tr>';
394 +
395 + $html .= '<tr>';
396 + $html .= '<td class="column-primary">';
397 + $html .= sprintf( '<strong>%s</strong>', __( 'Current theme:', 'rocket' ) );
398 + $html .= '</td>';
399 + $html .= '<td>';
400 + $html .= sprintf( '<em>%s</em>', $data['current_theme'] );
401 + $html .= '</td>';
402 + $html .= '</tr>';
403 +
404 + $html .= '<tr>';
405 + $html .= '<td class="column-primary">';
406 + $html .= sprintf( '<strong>%s</strong>', __( 'Current site language:', 'rocket' ) );
407 + $html .= '</td>';
408 + $html .= '<td>';
409 + $html .= sprintf( '<em>%s</em>', $data['locale'] );
410 + $html .= '</td>';
411 + $html .= '</tr>';
412 +
413 + $html .= '<tr>';
414 + $html .= '<td class="column-primary">';
415 + $html .= sprintf( '<strong>%s</strong>', __( 'Active plugins:', 'rocket' ) );
416 + $html .= '</td>';
417 + $html .= '<td>';
418 + $html .= sprintf( '<em>%s</em>', __( 'Plugin names of all active plugins', 'rocket' ) );
419 + $html .= '</td>';
420 + $html .= '</tr>';
421 +
422 + $html .= '<tr>';
423 + $html .= '<td class="column-primary">';
424 + $html .= sprintf( '<strong>%s</strong>', __( 'Anonymized WP Rocket settings:', 'rocket' ) );
425 + $html .= '</td>';
426 + $html .= '<td>';
427 + $html .= sprintf( '<em>%s</em>', __( 'Which WP Rocket settings are active', 'rocket' ) );
428 + $html .= '</td>';
429 + $html .= '</tr>';
430 +
431 + $html .= '<tr>';
432 + $html .= '<td class="column-primary">';
433 + $html .= sprintf( '<strong>%s</strong>', __( 'Anonymized WP Rocket statistics:', 'rocket' ) );
434 + $html .= '</td>';
435 + $html .= '<td>';
436 + $html .= sprintf( '<em>%s</em>', __( 'How WP Rocket features function and perform.', 'rocket' ) );
437 + $html .= '</td>';
438 + $html .= '</tr>';
439 +
440 + $html .= '<tr>';
441 + $html .= '<td class="column-primary">';
442 + $html .= sprintf( '<strong>%s</strong>', __( 'WP Rocket license type', 'rocket' ) );
443 + $html .= '</td>';
444 + $html .= '<td>';
445 + $html .= sprintf( '<em>%s</em>', $data['license_type'] );
446 + $html .= '</td>';
447 + $html .= '</tr>';
448 +
449 + $html .= '</tbody>';
450 + $html .= '</table>';
451 +
452 + return $html;
453 + }
454 +
455 + /**
456 + * Adds error message after settings import and redirects.
457 + *
458 + * @since 3.0
459 + * @author Remy Perona
460 + *
461 + * @param string $message Message to display in the error notice.
462 + * @param string $status Status of the error.
463 + * @return void
464 + */
465 + function rocket_settings_import_redirect( $message, $status ) {
466 + add_settings_error( 'general', 'settings_updated', $message, $status );
467 +
468 + set_transient( 'settings_errors', get_settings_errors(), 30 );
469 +
470 + $goback = add_query_arg( 'settings-updated', 'true', wp_get_referer() );
471 + wp_safe_redirect( esc_url_raw( $goback ) );
472 + die();
473 + }
474 +
475 + /**
476 + * Check if WPR options should be displayed.
477 + *
478 + * @return bool
479 + */
480 + function rocket_can_display_options() {
481 + $disallowed_post_status = [
482 + 'draft',
483 + 'trash',
484 + 'private',
485 + 'future',
486 + 'pending',
487 + ];
488 +
489 + $post_status = get_post_status();
490 + if ( in_array( $post_status, $disallowed_post_status, true ) ) {
491 + return false;
492 + }
493 +
494 + if ( function_exists( 'get_current_screen' ) && is_object( get_current_screen() ) && 'add' === get_current_screen()->action ) {
495 + return false;
496 + }
497 +
498 + return true;
499 + }
500 +
501 + /**
502 + * Create a hash from wp rocket options.
503 + *
504 + * @param array $value options.
505 + *
506 + * @return string
507 + */
508 + function rocket_create_options_hash( $value ) {
509 + $removed = [
510 + 'cache_mobile' => true,
511 + 'purge_cron_interval' => true,
512 + 'purge_cron_unit' => true,
513 + 'database_revisions' => true,
514 + 'database_auto_drafts' => true,
515 + 'database_trashed_posts' => true,
516 + 'database_spam_comments' => true,
517 + 'database_trashed_comments' => true,
518 + 'database_all_transients' => true,
519 + 'database_optimize_tables' => true,
520 + 'schedule_automatic_cleanup' => true,
521 + 'automatic_cleanup_frequency' => true,
522 + 'do_cloudflare' => true,
523 + 'cloudflare_email' => true,
524 + 'cloudflare_api_key' => true,
525 + 'cloudflare_zone_id' => true,
526 + 'cloudflare_devmode' => true,
527 + 'cloudflare_auto_settings' => true,
528 + 'cloudflare_old_settings' => true,
529 + 'heartbeat_admin_behavior' => true,
530 + 'heartbeat_editor_behavior' => true,
531 + 'varnish_auto_purge' => true,
532 + 'analytics_enabled' => true,
533 + 'sucury_waf_cache_sync' => true,
534 + 'sucury_waf_api_key' => true,
535 + 'manual_preload' => true,
536 + 'preload_excluded_uri' => true,
537 + 'cache_reject_uri' => true,
538 + 'version' => true,
539 + ];
540 +
541 + // Create 2 arrays to compare.
542 + $value_diff = array_diff_key( $value, $removed );
543 + ksort( $value_diff );
544 +
545 + return md5( wp_json_encode( $value_diff ) );
546 + }
547 +
548 + /**
549 + * This function returns the license type for a customer.
550 + *
551 + * @param object $customer_data customer data as an object.
552 + * @return string the type of the license the user has.
553 + */
554 + function rocket_get_license_type( $customer_data ) {
555 + if ( false === $customer_data
556 + ||
557 + ! isset( $customer_data->licence_account )
558 + ) {
559 + return __( 'Unavailable', 'rocket' );
560 + }
561 +
562 + // The licence name directly from User endpoint.
563 + if ( ! empty( $customer_data->licence->name ) ) {
564 + return esc_html( $customer_data->licence->name );
565 + }
566 +
567 + // Fallback to licence account.
568 + if ( 1 <= $customer_data->licence_account
569 + &&
570 + $customer_data->licence_account < 3
571 + ) {
572 + return 'Single';
573 + } elseif ( -1 === (int) $customer_data->licence_account ) {
574 + return 'Infinite';
575 + }
576 +
577 + return 'Plus';
578 + }
579 +
580 + /**
581 + * Fires callback attached to a deprecated filter hook.
582 + *
583 + * @param string $new_hook The hook that should have been used.
584 + * @param array $args Array of additional function arguments to be passed.
585 + * @param string $version The version of WPR that deprecated the hook.
586 + * @param string $old_hook Name of the original filter hook.
587 + *
588 + * @return mixed The filtered value after all hooked functions are applied to it.
589 + */
590 + function rocket_apply_filter_and_deprecated( string $new_hook, array $args, string $version, string $old_hook ) {
591 + $filtered_value = apply_filters_deprecated( $old_hook, $args, $version, $new_hook );
592 + $args[0] = $filtered_value;
593 +
594 + return apply_filters_ref_array( $new_hook, $args ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
595 + }
596 +
597 + /**
598 + * Fires callback attached to a deprecated action hook.
599 + *
600 + * @param string $new_hook The hook that should have been used.
601 + * @param array $args Array of additional function arguments to be passed.
602 + * @param string $version The version of WPR that deprecated the hook.
603 + * @param string $old_hook The name of the action hook.
604 + *
605 + * @return void
606 + */
607 + function rocket_do_action_and_deprecated( string $new_hook, array $args, string $version, string $old_hook ): void {
608 + do_action_deprecated( $old_hook, $args, $version, $new_hook );
609 + do_action_ref_array( $new_hook, $args ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
610 + }
611 +