PluginProbe
Elementor Website Builder – more than just a page builder / 3.19.2
Elementor Website Builder – more than just a page builder v3.19.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.19.2, at modules/system-info/reporters/server.php

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