Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/wp-rocket/inc/ThirdParty/Hostings/Cloudways.php
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
<?php
2
+
3
+
namespace WP_Rocket\ThirdParty\Hostings;
4
+
5
+
use WP_Rocket\Event_Management\Subscriber_Interface;
6
+
use WP_Rocket\ThirdParty\NullSubscriber;
7
+
8
+
/**
9
+
* Compatibility class for Cloudways Varnish
10
+
*
11
+
* @since 3.5.5
12
+
*/
13
+
class Cloudways extends NullSubscriber implements Subscriber_Interface {
14
+
15
+
/**
16
+
* Array of events this subscriber wants to listen to.
17
+
*
18
+
* @since 3.5.5
19
+
*
20
+
* @return array
21
+
*/
22
+
public static function get_subscribed_events() {
23
+
return [
24
+
'rocket_display_input_varnish_auto_purge' => 'return_false',
25
+
'do_rocket_varnish_http_purge' => 'should_purge',
26
+
'rocket_varnish_field_settings' => 'varnish_addon_title',
27
+
'rocket_varnish_ip' => 'varnish_ip',
28
+
];
29
+
}
30
+
31
+
/**
32
+
* Determine if the Varnish server is up and running.
33
+
*
34
+
* @since 3.6.1
35
+
*/
36
+
private static function is_varnish_running() {
37
+
if ( ! isset( $_SERVER['HTTP_X_VARNISH'] ) ) {
38
+
return false;
39
+
}
40
+
41
+
if ( ! isset( $_SERVER['HTTP_X_APPLICATION'] ) ) {
42
+
return false;
43
+
}
44
+
45
+
return ( 'varnishpass' !== trim( strtolower( $_SERVER['HTTP_X_APPLICATION'] ) ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
46
+
}
47
+
48
+
/**
49
+
* Returns false
50
+
*
51
+
* @since 3.5.5
52
+
*
53
+
* @return bool
54
+
*/
55
+
public function return_false() {
56
+
return false;
57
+
}
58
+
59
+
/**
60
+
* Returns should purge Varnish.
61
+
*
62
+
* @since 3.5.5
63
+
*
64
+
* @return true
65
+
*/
66
+
public function should_purge() {
67
+
return self::is_varnish_running();
68
+
}
69
+
70
+
/**
71
+
* Displays custom title for the Varnish add-on
72
+
*
73
+
* @since 3.5.5
74
+
*
75
+
* @param array $settings Array of settings for Varnish.
76
+
* @return array
77
+
*/
78
+
public function varnish_addon_title( array $settings ) {
79
+
if ( ! self::is_varnish_running() ) {
80
+
$settings['varnish_auto_purge']['title'] = sprintf(
81
+
// Translators: %s = Hosting name.
82
+
__( 'Varnish auto-purge will be automatically enabled once Varnish is enabled on your %s server.', 'rocket' ),
83
+
'Cloudways'
84
+
);
85
+
86
+
return $settings;
87
+
}
88
+
$settings['varnish_auto_purge']['title'] = sprintf(
89
+
// Translators: %s = Hosting name.
90
+
__( 'Your site is hosted on %s, we have enabled Varnish auto-purge for compatibility.', 'rocket' ),
91
+
'Cloudways'
92
+
);
93
+
94
+
return $settings;
95
+
}
96
+
97
+
/**
98
+
* Adds Cloudways Varnish IP to varnish IPs array
99
+
*
100
+
* @since 3.5.5
101
+
*
102
+
* @param mixed $varnish_ip Varnish IP.
103
+
* @return array
104
+
*/
105
+
public function varnish_ip( $varnish_ip ) {
106
+
if ( ! self::is_varnish_running() ) {
107
+
return $varnish_ip;
108
+
}
109
+
110
+
if ( ! is_array( $varnish_ip ) ) {
111
+
$varnish_ip = (array) $varnish_ip;
112
+
}
113
+
114
+
$varnish_ip[] = '127.0.0.1:8080';
115
+
116
+
return $varnish_ip;
117
+
}
118
+
}
119
+