PluginProbe
Elementor Website Builder – more than just a page builder / 3.10.0-dev1
Elementor Website Builder – more than just a page builder v3.10.0-dev1
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 4.1.0-beta1 4.1.0-dev1 All 452 releases
elementor / modules / system-info / reporters / server.php

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

492 lines 11.7 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 const KEY_PATH_WP_ROOT_DIR = 'wp_root';
21 const KEY_PATH_WP_CONTENT_DIR = 'wp_content';
22 const KEY_PATH_UPLOADS_DIR = 'uploads';
23 const KEY_PATH_ELEMENTOR_UPLOADS_DIR = 'elementor_uploads';
24 const KEY_PATH_HTACCESS_FILE = '.htaccess';
25
26 /**
27 * Get server environment reporter title.
28 *
29 * Retrieve server environment reporter title.
30 *
31 * @since 1.0.0
32 * @access public
33 *
34 * @return string Reporter title.
35 */
36 public function get_title() {
37 return 'Server Environment';
38 }
39
40 /**
41 * Get server environment report fields.
42 *
43 * Retrieve the required fields for the server environment report.
44 *
45 * @since 1.0.0
46 * @access public
47 *
48 * @return array Required report fields with field ID and field label.
49 */
50 public function get_fields() {
51 return [
52 'os' => 'Operating System',
53 'software' => 'Software',
54 'mysql_version' => 'MySQL version',
55 'php_version' => 'PHP Version',
56 'php_memory_limit' => 'PHP Memory Limit',
57 'php_max_input_vars' => 'PHP Max Input Vars',
58 'php_max_post_size' => 'PHP Max Post Size',
59 'gd_installed' => 'GD Installed',
60 'zip_installed' => 'ZIP Installed',
61 'write_permissions' => 'Write Permissions',
62 'elementor_library' => 'Elementor Library',
63 ];
64 }
65
66 /**
67 * Get server operating system.
68 *
69 * Retrieve the server operating system.
70 *
71 * @since 1.0.0
72 * @access public
73 *
74 * @return array {
75 * Report data.
76 *
77 * @type string $value Server operating system.
78 * }
79 */
80 public function get_os() {
81 return [
82 'value' => PHP_OS,
83 ];
84 }
85
86 /**
87 * Get server software.
88 *
89 * Retrieve the server software.
90 *
91 * @since 1.0.0
92 * @access public
93 *
94 * @return array {
95 * Report data.
96 *
97 * @type string $value Server software.
98 * }
99 */
100 public function get_software() {
101 return [
102 'value' => $_SERVER['SERVER_SOFTWARE'],
103 ];
104 }
105
106 /**
107 * Get PHP version.
108 *
109 * Retrieve the PHP version.
110 *
111 * @since 1.0.0
112 * @access public
113 *
114 * @return array {
115 * Report data.
116 *
117 * @type string $value PHP version.
118 * @type string $recommendation Minimum PHP version recommendation.
119 * @type bool $warning Whether to display a warning.
120 * }
121 */
122 public function get_php_version() {
123 $result = [
124 'value' => PHP_VERSION,
125 ];
126
127 if ( version_compare( $result['value'], '7.4', '<' ) ) {
128 $result['recommendation'] = sprintf(
129 /* translators: %s: Recommended PHP version. */
130 esc_html_x( 'We recommend using PHP version %s or higher.', 'System Info', 'elementor' ),
131 '7.4'
132 );
133
134 $result['warning'] = true;
135 }
136
137 return $result;
138 }
139
140 /**
141 * Get PHP memory limit.
142 *
143 * Retrieve the PHP memory limit.
144 *
145 * @return array {
146 * Report data.
147 *
148 * @type string $value PHP memory limit.
149 * @type string $recommendation Recommendation memory limit.
150 * @type bool $warning Whether to display a warning. True if the limit
151 * is below the recommended 128M, False otherwise.
152 * }
153 */
154 public function get_php_memory_limit() {
155 $result = [
156 'value' => (string) get_cfg_var( 'memory_limit' ),
157 ];
158
159 $min_recommended_memory = '128M';
160 $preferred_memory = '256M';
161
162 $memory_limit_bytes = wp_convert_hr_to_bytes( $result['value'] );
163
164 $min_recommended_bytes = wp_convert_hr_to_bytes( $min_recommended_memory );
165
166 if ( $memory_limit_bytes < $min_recommended_bytes ) {
167 $result['recommendation'] = sprintf(
168 /* translators: 1: Minimum recommended_memory, 2: Preferred memory, 3: WordPress wp-config memory documentation. */
169 _x( 'We recommend setting memory to at least %1$s. (%2$s or higher is preferred) For more information, read about <a href="%3$s">how to increase memory allocated to PHP</a>.', 'System Info', 'elementor' ),
170 $min_recommended_memory,
171 $preferred_memory,
172 'https://go.elementor.com/wordpress-wp-config-memory/'
173 );
174
175 $result['warning'] = true;
176 }
177
178 return $result;
179 }
180
181 /**
182 * Get PHP `max_input_vars`.
183 *
184 * Retrieve the value of `max_input_vars` from `php.ini` configuration file.
185 *
186 * @since 1.0.0
187 * @access public
188 *
189 * @return array {
190 * Report data.
191 *
192 * @type string $value PHP `max_input_vars`.
193 * }
194 */
195 public function get_php_max_input_vars() {
196 return [
197 'value' => ini_get( 'max_input_vars' ),
198 ];
199 }
200
201 /**
202 * Get PHP `post_max_size`.
203 *
204 * Retrieve the value of `post_max_size` from `php.ini` configuration file.
205 *
206 * @since 1.0.0
207 * @access public
208 *
209 * @return array {
210 * Report data.
211 *
212 * @type string $value PHP `post_max_size`.
213 * }
214 */
215 public function get_php_max_post_size() {
216 return [
217 'value' => ini_get( 'post_max_size' ),
218 ];
219 }
220
221 /**
222 * Get GD installed.
223 *
224 * Whether the GD extension is installed.
225 *
226 * @since 1.0.0
227 * @access public
228 *
229 * @return array {
230 * Report data.
231 *
232 * @type string $value Yes if the GD extension is installed, No otherwise.
233 * @type bool $warning Whether to display a warning. True if the GD extension is installed, False otherwise.
234 * }
235 */
236 public function get_gd_installed() {
237 $gd_installed = extension_loaded( 'gd' );
238
239 return [
240 'value' => $gd_installed ? 'Yes' : 'No',
241 'warning' => ! $gd_installed,
242 ];
243 }
244
245 /**
246 * Get ZIP installed.
247 *
248 * Whether the ZIP extension is installed.
249 *
250 * @since 2.1.0
251 * @access public
252 *
253 * @return array {
254 * Report data.
255 *
256 * @type string $value Yes if the ZIP extension is installed, No otherwise.
257 * @type bool $warning Whether to display a warning. True if the ZIP extension is installed, False otherwise.
258 * }
259 */
260 public function get_zip_installed() {
261 $zip_installed = extension_loaded( 'zip' );
262
263 return [
264 'value' => $zip_installed ? 'Yes' : 'No',
265 'warning' => ! $zip_installed,
266 ];
267 }
268
269 /**
270 * Get MySQL version.
271 *
272 * Retrieve the MySQL version.
273 *
274 * @since 1.0.0
275 * @access public
276 *
277 * @return array {
278 * Report data.
279 *
280 * @type string $value MySQL version.
281 * }
282 */
283 public function get_mysql_version() {
284 global $wpdb;
285
286 $db_server_version = $wpdb->get_results( "SHOW VARIABLES WHERE `Variable_name` IN ( 'version_comment', 'innodb_version' )", OBJECT_K );
287
288 $db_server_version_string = $db_server_version['version_comment']->Value . ' v';
289
290 // On some hosts, `innodb_version` is empty, in PHP 8.1.
291 if ( isset( $db_server_version['innodb_version'] ) ) {
292 $db_server_version_string .= $db_server_version['innodb_version']->Value;
293 } else {
294 $db_server_version_string .= $wpdb->get_var( 'SELECT VERSION() AS version' );
295 }
296
297 return [
298 'value' => $db_server_version_string,
299 ];
300 }
301
302 /**
303 * Get write permissions.
304 * Check whether the required paths for have writing permissions.
305 *
306 * @since 1.9.0
307 * @access public
308 *
309 * @return array {
310 * Report data.
311 *
312 * @type string $value Writing permissions status.
313 * @type bool $warning Whether to display a warning. True if some required
314 * folders don't have writing permissions, False otherwise.
315 * }
316 */
317 public function get_write_permissions() : array {
318 $paths_to_check = [
319 static::KEY_PATH_WP_ROOT_DIR => $this->get_system_path( static::KEY_PATH_WP_ROOT_DIR ),
320 static::KEY_PATH_HTACCESS_FILE => $this->get_system_path( static::KEY_PATH_HTACCESS_FILE ),
321 static::KEY_PATH_UPLOADS_DIR => $this->get_system_path( static::KEY_PATH_UPLOADS_DIR ),
322 static::KEY_PATH_ELEMENTOR_UPLOADS_DIR => $this->get_system_path( static::KEY_PATH_ELEMENTOR_UPLOADS_DIR ),
323 ];
324
325 $paths_permissions = $this->get_paths_permissions( $paths_to_check );
326
327 $write_problems = [];
328
329 if ( ! $paths_permissions[ static::KEY_PATH_WP_ROOT_DIR ]['write'] ) {
330 $write_problems[] = 'WordPress root directory';
331 }
332
333 if ( ! $paths_permissions[ static::KEY_PATH_UPLOADS_DIR ]['write'] ) {
334 $write_problems[] = 'WordPress uploads directory';
335 }
336
337 if ( $paths_permissions[ self::KEY_PATH_ELEMENTOR_UPLOADS_DIR ]['exists'] && ! $paths_permissions[ self::KEY_PATH_ELEMENTOR_UPLOADS_DIR ]['write'] ) {
338 $write_problems[] = 'Elementor uploads directory';
339 }
340
341 if ( $paths_permissions[ self::KEY_PATH_HTACCESS_FILE ]['exists'] && ! $paths_permissions[ self::KEY_PATH_HTACCESS_FILE ]['write'] ) {
342 $write_problems[] = '.htaccess file';
343 }
344
345 if ( $write_problems ) {
346 $value = 'There are some writing permissions issues with the following directories/files:' . "\n\t\t - ";
347
348 $value .= implode( "\n\t\t - ", $write_problems );
349 } else {
350 $value = 'All right';
351 }
352
353 return [
354 'value' => $value,
355 'warning' => ! ! $write_problems,
356 ];
357 }
358
359 /**
360 * Check for elementor library connectivity.
361 *
362 * Check whether the remote elementor library is reachable.
363 *
364 * @since 1.0.0
365 * @access public
366 *
367 * @return array {
368 * Report data.
369 *
370 * @type string $value The status of elementor library connectivity.
371 * @type bool $warning Whether to display a warning. True if elementor
372 * * library is not reachable, False otherwise.
373 * }
374 */
375 public function get_elementor_library() {
376 $response = wp_remote_get(
377 Api::$api_info_url, [
378 'timeout' => 5,
379 'body' => [
380 // Which API version is used
381 'api_version' => ELEMENTOR_VERSION,
382 // Which language to return
383 'site_lang' => get_bloginfo( 'language' ),
384 ],
385 ]
386 );
387
388 if ( is_wp_error( $response ) ) {
389 return [
390 'value' => 'Not connected (' . $response->get_error_message() . ')',
391 'warning' => true,
392 ];
393 }
394
395 $http_response_code = wp_remote_retrieve_response_code( $response );
396
397 if ( 200 !== (int) $http_response_code ) {
398 $error_msg = 'HTTP Error (' . $http_response_code . ')';
399
400 return [
401 'value' => 'Not connected (' . $error_msg . ')',
402 'warning' => true,
403 ];
404 }
405
406 $info_data = json_decode( wp_remote_retrieve_body( $response ), true );
407
408 if ( empty( $info_data ) ) {
409 return [
410 'value' => 'Not connected (Returns invalid JSON)',
411 'warning' => true,
412 ];
413 }
414
415 return [
416 'value' => 'Connected',
417 ];
418 }
419
420 /**
421 * @param $paths [] Paths to check permissions.
422 * @return array []{exists: bool, read: bool, write: bool, execute: bool}
423 */
424 public function get_paths_permissions( $paths ) : array {
425 $permissions = [];
426
427 foreach ( $paths as $key_path => $path ) {
428 $permissions[ $key_path ] = $this->get_path_permissions( $path );
429 }
430
431 return $permissions;
432 }
433
434 /**
435 * Get path by path key.
436 *
437 * @param $path_key
438 * @return string
439 */
440 public function get_system_path( $path_key ) : string {
441 switch ( $path_key ) {
442 case static::KEY_PATH_WP_ROOT_DIR:
443 return ABSPATH;
444
445 case static::KEY_PATH_WP_CONTENT_DIR:
446 return WP_CONTENT_DIR;
447
448 case static::KEY_PATH_HTACCESS_FILE:
449 return file_exists( ABSPATH . '/.htaccess' ) ? ABSPATH . '/.htaccess' : '';
450
451 case static::KEY_PATH_UPLOADS_DIR:
452 return wp_upload_dir()['basedir'] ?? '';
453
454 case static::KEY_PATH_ELEMENTOR_UPLOADS_DIR:
455 if ( empty( wp_upload_dir()['basedir'] ) ) {
456 return '';
457 }
458
459 $elementor_uploads_dir = wp_upload_dir()['basedir'] . '/elementor';
460
461 return is_dir( $elementor_uploads_dir ) ? $elementor_uploads_dir : '';
462
463 default:
464 return '';
465 }
466 }
467
468 /**
469 * Check the permissions of a path.
470 *
471 * @param $path
472 * @return array{exists: bool, read: bool, write: bool, execute: bool}
473 */
474 public function get_path_permissions( $path ) : array {
475 if ( empty( $path ) ) {
476 return [
477 'exists' => false,
478 'read' => false,
479 'write' => false,
480 'execute' => false,
481 ];
482 }
483
484 return [
485 'exists' => true,
486 'read' => is_readable( $path ),
487 'write' => is_writeable( $path ),
488 'execute' => is_executable( $path ),
489 ];
490 }
491 }
492