PluginProbe
Elementor Website Builder – more than just a page builder / 3.6.2
Elementor Website Builder – more than just a page builder v3.6.2
4.3.1 4.3.0 4.3.0-beta3 4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 All 454 releases
elementor / modules / system-info / reporters / server.php

server.php in Elementor Website Builder – more than just a page builder 3.6.2, at modules/system-info/reporters/server.php

405 lines 9.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor\Modules\System_Info\Reporters;
3
4 use Elementor\Api;
5
6 if ( ! defined( 'ABSPATH' ) ) {
7 exit; // Exit if accessed directly.
8 }
9
10 /**
11 * Elementor server environment report.
12 *
13 * Elementor system report handler class responsible for generating a report for
14 * the server environment.
15 *
16 * @since 1.0.0
17 */
18 class Server extends Base {
19
20 /**
21 * Get server environment reporter title.
22 *
23 * Retrieve server environment reporter title.
24 *
25 * @since 1.0.0
26 * @access public
27 *
28 * @return string Reporter title.
29 */
30 public function get_title() {
31 return 'Server Environment';
32 }
33
34 /**
35 * Get server environment report fields.
36 *
37 * Retrieve the required fields for the server environment report.
38 *
39 * @since 1.0.0
40 * @access public
41 *
42 * @return array Required report fields with field ID and field label.
43 */
44 public function get_fields() {
45 return [
46 'os' => 'Operating System',
47 'software' => 'Software',
48 'mysql_version' => 'MySQL version',
49 'php_version' => 'PHP Version',
50 'php_memory_limit' => 'PHP Memory Limit',
51 'php_max_input_vars' => 'PHP Max Input Vars',
52 'php_max_post_size' => 'PHP Max Post Size',
53 'gd_installed' => 'GD Installed',
54 'zip_installed' => 'ZIP Installed',
55 'write_permissions' => 'Write Permissions',
56 'elementor_library' => 'Elementor Library',
57 ];
58 }
59
60 /**
61 * Get server operating system.
62 *
63 * Retrieve the server operating system.
64 *
65 * @since 1.0.0
66 * @access public
67 *
68 * @return array {
69 * Report data.
70 *
71 * @type string $value Server operating system.
72 * }
73 */
74 public function get_os() {
75 return [
76 'value' => PHP_OS,
77 ];
78 }
79
80 /**
81 * Get server software.
82 *
83 * Retrieve the server software.
84 *
85 * @since 1.0.0
86 * @access public
87 *
88 * @return array {
89 * Report data.
90 *
91 * @type string $value Server software.
92 * }
93 */
94 public function get_software() {
95 return [
96 'value' => $_SERVER['SERVER_SOFTWARE'],
97 ];
98 }
99
100 /**
101 * Get PHP version.
102 *
103 * Retrieve the PHP version.
104 *
105 * @since 1.0.0
106 * @access public
107 *
108 * @return array {
109 * Report data.
110 *
111 * @type string $value PHP version.
112 * @type string $recommendation Minimum PHP version recommendation.
113 * @type bool $warning Whether to display a warning.
114 * }
115 */
116 public function get_php_version() {
117 $result = [
118 'value' => PHP_VERSION,
119 ];
120
121 if ( version_compare( $result['value'], '5.4', '<' ) ) {
122 $result['recommendation'] = _x( 'We recommend to use php 5.4 or higher', 'System Info', 'elementor' );
123
124 $result['warning'] = true;
125 }
126
127 return $result;
128 }
129
130 /**
131 * Get PHP memory limit.
132 *
133 * Retrieve the PHP memory limit.
134 *
135 * @return array {
136 * Report data.
137 *
138 * @type string $value PHP memory limit.
139 * @type string $recommendation Recommendation memory limit.
140 * @type bool $warning Whether to display a warning. True if the limit
141 * is below the recommended 128M, False otherwise.
142 * }
143 */
144 public function get_php_memory_limit() {
145 $result = [
146 'value' => (string) get_cfg_var( 'memory_limit' ),
147 ];
148
149 $min_recommended_memory = '128M';
150 $preferred_memory = '256M';
151
152 $memory_limit_bytes = wp_convert_hr_to_bytes( $result['value'] );
153
154 $min_recommended_bytes = wp_convert_hr_to_bytes( $min_recommended_memory );
155
156 if ( $memory_limit_bytes < $min_recommended_bytes ) {
157 $result['recommendation'] = sprintf(
158 /* translators: 1: Minimum recommended_memory, 2: Preferred memory, 3: WordPress wp-config memory documentation. */
159 _x( 'We recommend setting memory to at least %1$s. (%2$sMB or higher is preferred) For more information, read about <a href="%3$s">how to Increase memory allocated to PHP</a>.', 'System Info', 'elementor' ),
160 $min_recommended_memory,
161 $preferred_memory,
162 'https://go.elementor.com/wordpress-wp-config-memory/'
163 );
164
165 $result['warning'] = true;
166 }
167
168 return $result;
169 }
170
171 /**
172 * Get PHP `max_input_vars`.
173 *
174 * Retrieve the value of `max_input_vars` from `php.ini` configuration file.
175 *
176 * @since 1.0.0
177 * @access public
178 *
179 * @return array {
180 * Report data.
181 *
182 * @type string $value PHP `max_input_vars`.
183 * }
184 */
185 public function get_php_max_input_vars() {
186 return [
187 'value' => ini_get( 'max_input_vars' ),
188 ];
189 }
190
191 /**
192 * Get PHP `post_max_size`.
193 *
194 * Retrieve the value of `post_max_size` from `php.ini` configuration file.
195 *
196 * @since 1.0.0
197 * @access public
198 *
199 * @return array {
200 * Report data.
201 *
202 * @type string $value PHP `post_max_size`.
203 * }
204 */
205 public function get_php_max_post_size() {
206 return [
207 'value' => ini_get( 'post_max_size' ),
208 ];
209 }
210
211 /**
212 * Get GD installed.
213 *
214 * Whether the GD extension is installed.
215 *
216 * @since 1.0.0
217 * @access public
218 *
219 * @return array {
220 * Report data.
221 *
222 * @type string $value Yes if the GD extension is installed, No otherwise.
223 * @type bool $warning Whether to display a warning. True if the GD extension is installed, False otherwise.
224 * }
225 */
226 public function get_gd_installed() {
227 $gd_installed = extension_loaded( 'gd' );
228
229 return [
230 'value' => $gd_installed ? 'Yes' : 'No',
231 'warning' => ! $gd_installed,
232 ];
233 }
234
235 /**
236 * Get ZIP installed.
237 *
238 * Whether the ZIP extension is installed.
239 *
240 * @since 2.1.0
241 * @access public
242 *
243 * @return array {
244 * Report data.
245 *
246 * @type string $value Yes if the ZIP extension is installed, No otherwise.
247 * @type bool $warning Whether to display a warning. True if the ZIP extension is installed, False otherwise.
248 * }
249 */
250 public function get_zip_installed() {
251 $zip_installed = extension_loaded( 'zip' );
252
253 return [
254 'value' => $zip_installed ? 'Yes' : 'No',
255 'warning' => ! $zip_installed,
256 ];
257 }
258
259 /**
260 * Get MySQL version.
261 *
262 * Retrieve the MySQL version.
263 *
264 * @since 1.0.0
265 * @access public
266 *
267 * @return array {
268 * Report data.
269 *
270 * @type string $value MySQL version.
271 * }
272 */
273 public function get_mysql_version() {
274 global $wpdb;
275
276 $db_server_version = $wpdb->get_results( "SHOW VARIABLES WHERE `Variable_name` IN ( 'version_comment', 'innodb_version' )", OBJECT_K );
277
278 return [
279 'value' => $db_server_version['version_comment']->Value . ' v' . $db_server_version['innodb_version']->Value,
280 ];
281 }
282
283 /**
284 * Get write permissions.
285 *
286 * Check whether the required folders has writing permissions.
287 *
288 * @since 1.9.0
289 * @access public
290 *
291 * @return array {
292 * Report data.
293 *
294 * @type string $value Writing permissions status.
295 * @type bool $warning Whether to display a warning. True if some required
296 * folders don't have writing permissions, False otherwise.
297 * }
298 */
299 public function get_write_permissions() {
300 $paths_to_check = [
301 ABSPATH => 'WordPress root directory',
302 ];
303
304 $write_problems = [];
305
306 $wp_upload_dir = wp_upload_dir();
307
308 if ( $wp_upload_dir['error'] ) {
309 $write_problems[] = 'WordPress root uploads directory';
310 }
311
312 $elementor_uploads_path = $wp_upload_dir['basedir'] . '/elementor';
313
314 if ( is_dir( $elementor_uploads_path ) ) {
315 $paths_to_check[ $elementor_uploads_path ] = 'Elementor uploads directory';
316 }
317
318 $htaccess_file = ABSPATH . '/.htaccess';
319
320 if ( file_exists( $htaccess_file ) ) {
321 $paths_to_check[ $htaccess_file ] = '.htaccess file';
322 }
323
324 foreach ( $paths_to_check as $dir => $description ) {
325 if ( ! is_writable( $dir ) ) {
326 $write_problems[] = $description;
327 }
328 }
329
330 if ( $write_problems ) {
331 $value = 'There are some writing permissions issues with the following directories/files:' . "\n\t\t - ";
332
333 $value .= implode( "\n\t\t - ", $write_problems );
334 } else {
335 $value = 'All right';
336 }
337
338 return [
339 'value' => $value,
340 'warning' => ! ! $write_problems,
341 ];
342 }
343
344 /**
345 * Check for elementor library connectivity.
346 *
347 * Check whether the remote elementor library is reachable.
348 *
349 * @since 1.0.0
350 * @access public
351 *
352 * @return array {
353 * Report data.
354 *
355 * @type string $value The status of elementor library connectivity.
356 * @type bool $warning Whether to display a warning. True if elementor
357 * * library is not reachable, False otherwise.
358 * }
359 */
360 public function get_elementor_library() {
361 $response = wp_remote_get(
362 Api::$api_info_url, [
363 'timeout' => 5,
364 'body' => [
365 // Which API version is used
366 'api_version' => ELEMENTOR_VERSION,
367 // Which language to return
368 'site_lang' => get_bloginfo( 'language' ),
369 ],
370 ]
371 );
372
373 if ( is_wp_error( $response ) ) {
374 return [
375 'value' => 'Not connected (' . $response->get_error_message() . ')',
376 'warning' => true,
377 ];
378 }
379
380 $http_response_code = wp_remote_retrieve_response_code( $response );
381
382 if ( 200 !== (int) $http_response_code ) {
383 $error_msg = 'HTTP Error (' . $http_response_code . ')';
384
385 return [
386 'value' => 'Not connected (' . $error_msg . ')',
387 'warning' => true,
388 ];
389 }
390
391 $info_data = json_decode( wp_remote_retrieve_body( $response ), true );
392
393 if ( empty( $info_data ) ) {
394 return [
395 'value' => 'Not connected (Returns invalid JSON)',
396 'warning' => true,
397 ];
398 }
399
400 return [
401 'value' => 'Connected',
402 ];
403 }
404 }
405