class-wpml-support-info-ui.php
8.76 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
<?php
/**
* @author OnTheGo Systems
*/
class WPML_Support_Info_UI {
/** @var WPML_Support_Info */
private $support_info;
/** @var IWPML_Template_Service */
private $template_service;
function __construct( WPML_Support_Info $support_info, IWPML_Template_Service $template_service ) {
$this->support_info = $support_info;
$this->template_service = $template_service;
}
/**
* @return string
*/
public function show() {
$model = $this->get_model();
return $this->template_service->show( $model, 'main.twig' );
}
/** @return array */
private function get_model() {
$minimum_required_memory = '128M';
$minimum_required_php_version = '5.6';
$minimum_recommended_php_version = '7.3';
$minimum_required_wp_version = '3.9.0';
$php_version = $this->support_info->get_php_version();
$php_memory_limit = $this->support_info->get_php_memory_limit();
$memory_usage = $this->support_info->get_memory_usage();
$max_execution_time = $this->support_info->get_max_execution_time();
$max_input_vars = $this->support_info->get_max_input_vars();
$blocks = array(
'php' => array(
'strings' => array(
'title' => __( 'PHP', 'sitepress' ),
),
'data' => array(
'version' => array(
'label' => __( 'Version', 'sitepress' ),
'value' => $php_version,
'url' => 'http://php.net/supported-versions.php',
'messages' => array(
sprintf( __( 'PHP %1$s and above are recommended. PHP %2$s is the minimum requirement.', 'sitepress' ), $minimum_recommended_php_version, $minimum_required_php_version ) => 'https://wpml.org/home/minimum-requirements/?utm_source=plugin&utm_medium=gui&utm_campaign=wpmlcore',
__( 'Find how you can update PHP.', 'sitepress' ) => 'http://www.wpupdatephp.com/update/',
),
'is_error' => $this->support_info->is_version_less_than( $minimum_required_php_version, $php_version ),
'is_warning' => $this->support_info->is_version_less_than( $minimum_recommended_php_version, $php_version ),
),
'memory_limit' => array(
'label' => __( 'Memory limit', 'sitepress' ),
'value' => $php_memory_limit,
'url' => 'http://php.net/manual/ini.core.php#ini.memory-limit',
'messages' => array(
sprintf( __( 'A memory limit of at least %s is required.', 'sitepress' ), $minimum_required_memory ) => 'https://wpml.org/home/minimum-requirements/?utm_source=plugin&utm_medium=gui&utm_campaign=wpmlcore',
),
'is_error' => $this->support_info->is_memory_less_than( $minimum_required_memory, $php_memory_limit ),
),
'memory_usage' => array(
'label' => __( 'Memory usage', 'sitepress' ),
'value' => $memory_usage,
'url' => 'http://php.net/memory-get-usage',
),
'max_execution_time' => array(
'label' => __( 'Max execution time', 'sitepress' ),
'value' => $max_execution_time,
'url' => 'http://php.net/manual/info.configuration.php#ini.max-execution-time',
),
'max_input_vars' => array(
'label' => __( 'Max input vars', 'sitepress' ),
'value' => $max_input_vars,
'url' => 'http://php.net/manual/info.configuration.php#ini.max-input-vars',
),
'utf8mb4_charset' => array(
'label' => __( 'Utf8mb4 charset', 'sitepress' ),
'value' => $this->support_info->is_utf8mb4_charset_supported() ? __( 'Yes' ) : __( 'No' ),
'url' => 'https://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8mb4.html',
'messages' => array(
__( 'Some features related to String Translations may not work correctly without utf8mb4 character.', 'sitepress' ) => 'https://wpml.org/home/minimum-requirements/?utm_source=plugin&utm_medium=gui&utm_campaign=wpmlcore',
),
'is_error' => ! $this->support_info->is_utf8mb4_charset_supported(),
) ,
),
),
'wp' => array(
'strings' => array(
'title' => __( 'WordPress', 'sitepress' ),
),
'data' => array(
'wp_version' => array(
'label' => __( 'Version', 'sitepress' ),
'value' => $this->support_info->get_wp_version(),
'messages' => array(
__( 'WordPress 3.9 or later is required.', 'sitepress' ) => 'https://wpml.org/home/minimum-requirements/?utm_source=plugin&utm_medium=gui&utm_campaign=wpmlcore',
),
'is_error' => $this->support_info->is_version_less_than( $minimum_required_wp_version, $this->support_info->get_wp_version() ),
),
'multisite' => array(
'label' => __( 'Multisite', 'sitepress' ),
'value' => $this->support_info->get_wp_multisite() ? __( 'Yes' ) : __( 'No' ),
),
'memory_limit' => array(
'label' => __( 'Memory limit', 'sitepress' ),
'value' => $this->support_info->get_wp_memory_limit(),
'url' => 'https://codex.wordpress.org/Editing_wp-config.php#Increasing_memory_allocated_to_PHP',
'messages' => array(
__( 'A memory limit of at least 128MB is required.', 'sitepress' ) => 'https://wpml.org/home/minimum-requirements/?utm_source=plugin&utm_medium=gui&utm_campaign=wpmlcore',
),
'is_error' => $this->support_info->is_memory_less_than( $minimum_required_memory, $this->support_info->get_wp_memory_limit() ),
),
'max_memory_limit' => array(
'label' => __( 'Max memory limit', 'sitepress' ),
'value' => $this->support_info->get_wp_max_memory_limit(),
'url' => 'https://codex.wordpress.org/Editing_wp-config.php#Increasing_memory_allocated_to_PHP',
'messages' => array(
__( 'A memory limit of at least 128MB is required.', 'sitepress' ) => 'https://wpml.org/home/minimum-requirements/?utm_source=plugin&utm_medium=gui&utm_campaign=wpmlcore',
),
'is_error' => $this->support_info->is_memory_less_than( $minimum_required_memory, $this->support_info->get_wp_max_memory_limit() ),
),
'rest_enabled' => array(
'label' => __( 'REST enabled', 'sitepress' ),
'value' => wpml_is_rest_enabled() ? __( 'Yes' ) : __( 'No' ),
'url' => 'https://wpml.org/home/minimum-requirements/?utm_source=plugin&utm_medium=gui&utm_campaign=wpmlcore',
'messages' => array(
__( 'REST API is disabled, blocking some features of WPML', 'sitepress' ) => 'https://wpml.org/documentation/support/rest-api-dependencies/?utm_source=plugin&utm_medium=gui&utm_campaign=wpmlcore',
),
'is_error' => ! wpml_is_rest_enabled(),
),
),
),
);
if ( $this->support_info->is_suhosin_active() ) {
$blocks['php']['data']['eval_suhosin'] = array(
'label' => __( 'eval() availability from Suhosin', 'sitepress' ),
'value' => $this->support_info->eval_disabled_by_suhosin() ? __( 'Not available', 'sitepress' ) : __( 'Available', 'sitepress' ),
'url' => 'https://suhosin.org/stories/configuration.html#suhosin-executor-disable-eval',
'messages' => array(
__( 'The eval() PHP function must be enabled.', 'sitepress' ) => 'https://wpml.org/home/minimum-requirements/?utm_source=plugin&utm_medium=gui&utm_campaign=wpmlcore#eval-usage',
),
'is_error' => $this->support_info->eval_disabled_by_suhosin(),
);
}
/**
* Allows to extend the data shown in the WPML > Support > Info
*
* This filter is for internal use.
* You can add items to the `$blocks` array, however, it is strongly
* recommended to not modify existing data.
*
* You can see how `$block` is structured by scrolling at the beginning of this method.
*
* The "messages" array can contain just a string (the message) or a string (the message)
* and an URL (message linked to that URL).
* That is, you can have:
* ```
* 'messages' => array(
* 'Some message A' => 'https://domain.tld',
* 'Some message B' => 'https://domain.tld',
* 'Some message C',
* ),
* ```
*
* @since 3.8.0
*
* @param array $blocks
*/
$blocks = apply_filters( 'wpml_support_info_blocks', $blocks );
$this->set_has_messages( $blocks, 'is_error' );
$this->set_has_messages( $blocks, 'is_warning' );
$model = array(
'title' => __( 'Info', 'sitepress' ),
'blocks' => $blocks,
);
return $model;
}
/**
* @param array $blocks
* @param string $type
*/
private function set_has_messages( array &$blocks, $type ) {
/**
* @var string $id
* @var array $content
*/
foreach ( $blocks as $id => $content ) {
if ( ! array_key_exists( 'has_messages', $content ) ) {
$content['has_messages'] = false;
}
foreach ( (array) $content['data'] as $key => $item_data ) {
if ( array_key_exists( $type, $item_data ) && (bool) $item_data[ $type ] ) {
$content['has_messages'] = true;
break;
}
}
$blocks[ $id ] = $content;
}
}
}