PluginProbe
Elementor Website Builder – more than just a page builder / 3.8.0-beta1
Elementor Website Builder – more than just a page builder v3.8.0-beta1
4.3.4 4.3.3 4.3.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 All 457 releases
elementor / modules / system-info / reporters / server.php

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

477 lines 11.3 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'], '5.4', '<' ) ) {
128 $result['recommendation'] = _x( 'We recommend to use php 5.4 or higher', 'System Info', 'elementor' );
129
130 $result['warning'] = true;
131 }
132
133 return $result;
134 }
135
136 /**
137 * Get PHP memory limit.
138 *
139 * Retrieve the PHP memory limit.
140 *
141 * @return array {
142 * Report data.
143 *
144 * @type string $value PHP memory limit.
145 * @type string $recommendation Recommendation memory limit.
146 * @type bool $warning Whether to display a warning. True if the limit
147 * is below the recommended 128M, False otherwise.
148 * }
149 */
150 public function get_php_memory_limit() {
151 $result = [
152 'value' => (string) get_cfg_var( 'memory_limit' ),
153 ];
154
155 $min_recommended_memory = '128M';
156 $preferred_memory = '256M';
157
158 $memory_limit_bytes = wp_convert_hr_to_bytes( $result['value'] );
159
160 $min_recommended_bytes = wp_convert_hr_to_bytes( $min_recommended_memory );
161
162 if ( $memory_limit_bytes < $min_recommended_bytes ) {
163 $result['recommendation'] = sprintf(
164 /* translators: 1: Minimum recommended_memory, 2: Preferred memory, 3: WordPress wp-config memory documentation. */
165 _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' ),
166 $min_recommended_memory,
167 $preferred_memory,
168 'https://go.elementor.com/wordpress-wp-config-memory/'
169 );
170
171 $result['warning'] = true;
172 }
173
174 return $result;
175 }
176
177 /**
178 * Get PHP `max_input_vars`.
179 *
180 * Retrieve the value of `max_input_vars` from `php.ini` configuration file.
181 *
182 * @since 1.0.0
183 * @access public
184 *
185 * @return array {
186 * Report data.
187 *
188 * @type string $value PHP `max_input_vars`.
189 * }
190 */
191 public function get_php_max_input_vars() {
192 return [
193 'value' => ini_get( 'max_input_vars' ),
194 ];
195 }
196
197 /**
198 * Get PHP `post_max_size`.
199 *
200 * Retrieve the value of `post_max_size` from `php.ini` configuration file.
201 *
202 * @since 1.0.0
203 * @access public
204 *
205 * @return array {
206 * Report data.
207 *
208 * @type string $value PHP `post_max_size`.
209 * }
210 */
211 public function get_php_max_post_size() {
212 return [
213 'value' => ini_get( 'post_max_size' ),
214 ];
215 }
216
217 /**
218 * Get GD installed.
219 *
220 * Whether the GD extension is installed.
221 *
222 * @since 1.0.0
223 * @access public
224 *
225 * @return array {
226 * Report data.
227 *
228 * @type string $value Yes if the GD extension is installed, No otherwise.
229 * @type bool $warning Whether to display a warning. True if the GD extension is installed, False otherwise.
230 * }
231 */
232 public function get_gd_installed() {
233 $gd_installed = extension_loaded( 'gd' );
234
235 return [
236 'value' => $gd_installed ? 'Yes' : 'No',
237 'warning' => ! $gd_installed,
238 ];
239 }
240
241 /**
242 * Get ZIP installed.
243 *
244 * Whether the ZIP extension is installed.
245 *
246 * @since 2.1.0
247 * @access public
248 *
249 * @return array {
250 * Report data.
251 *
252 * @type string $value Yes if the ZIP extension is installed, No otherwise.
253 * @type bool $warning Whether to display a warning. True if the ZIP extension is installed, False otherwise.
254 * }
255 */
256 public function get_zip_installed() {
257 $zip_installed = extension_loaded( 'zip' );
258
259 return [
260 'value' => $zip_installed ? 'Yes' : 'No',
261 'warning' => ! $zip_installed,
262 ];
263 }
264
265 /**
266 * Get MySQL version.
267 *
268 * Retrieve the MySQL version.
269 *
270 * @since 1.0.0
271 * @access public
272 *
273 * @return array {
274 * Report data.
275 *
276 * @type string $value MySQL version.
277 * }
278 */
279 public function get_mysql_version() {
280 global $wpdb;
281
282 $db_server_version = $wpdb->get_results( "SHOW VARIABLES WHERE `Variable_name` IN ( 'version_comment', 'innodb_version' )", OBJECT_K );
283
284 $db_server_version_string = $db_server_version['version_comment']->Value . ' v';
285
286 // On some hosts, `innodb_version` is empty, in PHP 8.1.
287 if ( isset( $db_server_version['innodb_version'] ) ) {
288 $db_server_version_string .= $db_server_version['innodb_version']->Value;
289 } else {
290 $db_server_version_string .= $wpdb->get_var( 'SELECT VERSION() AS version' );
291 }
292
293 return [
294 'value' => $db_server_version_string,
295 ];
296 }
297
298 /**
299 * Get write permissions.
300 * Check whether the required paths for have writing permissions.
301 *
302 * @since 1.9.0
303 * @access public
304 *
305 * @return array {
306 * Report data.
307 *
308 * @type string $value Writing permissions status.
309 * @type bool $warning Whether to display a warning. True if some required
310 * folders don't have writing permissions, False otherwise.
311 * }
312 */
313 public function get_write_permissions() : array {
314 $paths_messages = [
315 static::KEY_PATH_WP_ROOT_DIR => 'WordPress root directory',
316 static::KEY_PATH_HTACCESS_FILE => '.htaccess file',
317 static::KEY_PATH_UPLOADS_DIR => 'WordPress uploads directory',
318 static::KEY_PATH_ELEMENTOR_UPLOADS_DIR => 'Elementor uploads directory',
319 ];
320
321 $paths_to_check = [
322 static::KEY_PATH_WP_ROOT_DIR => $this->get_system_path( static::KEY_PATH_WP_ROOT_DIR ),
323 static::KEY_PATH_HTACCESS_FILE => $this->get_system_path( static::KEY_PATH_HTACCESS_FILE ),
324 static::KEY_PATH_UPLOADS_DIR => $this->get_system_path( static::KEY_PATH_UPLOADS_DIR ),
325 static::KEY_PATH_ELEMENTOR_UPLOADS_DIR => $this->get_system_path( static::KEY_PATH_ELEMENTOR_UPLOADS_DIR ),
326 ];
327
328 $paths_permissions = $this->get_paths_permissions( $paths_to_check );
329
330 $write_problems = [];
331
332 foreach ( $paths_permissions as $key_path => $path_permissions ) {
333 if ( ! $path_permissions['write'] ) {
334 $write_problems[] = $paths_messages[ $key_path ];
335 }
336 }
337
338 if ( $write_problems ) {
339 $value = 'There are some writing permissions issues with the following directories/files:' . "\n\t\t - ";
340
341 $value .= implode( "\n\t\t - ", $write_problems );
342 } else {
343 $value = 'All right';
344 }
345
346 return [
347 'value' => $value,
348 'warning' => ! ! $write_problems,
349 ];
350 }
351
352 /**
353 * Check for elementor library connectivity.
354 *
355 * Check whether the remote elementor library is reachable.
356 *
357 * @since 1.0.0
358 * @access public
359 *
360 * @return array {
361 * Report data.
362 *
363 * @type string $value The status of elementor library connectivity.
364 * @type bool $warning Whether to display a warning. True if elementor
365 * * library is not reachable, False otherwise.
366 * }
367 */
368 public function get_elementor_library() {
369 $response = wp_remote_get(
370 Api::$api_info_url, [
371 'timeout' => 5,
372 'body' => [
373 // Which API version is used
374 'api_version' => ELEMENTOR_VERSION,
375 // Which language to return
376 'site_lang' => get_bloginfo( 'language' ),
377 ],
378 ]
379 );
380
381 if ( is_wp_error( $response ) ) {
382 return [
383 'value' => 'Not connected (' . $response->get_error_message() . ')',
384 'warning' => true,
385 ];
386 }
387
388 $http_response_code = wp_remote_retrieve_response_code( $response );
389
390 if ( 200 !== (int) $http_response_code ) {
391 $error_msg = 'HTTP Error (' . $http_response_code . ')';
392
393 return [
394 'value' => 'Not connected (' . $error_msg . ')',
395 'warning' => true,
396 ];
397 }
398
399 $info_data = json_decode( wp_remote_retrieve_body( $response ), true );
400
401 if ( empty( $info_data ) ) {
402 return [
403 'value' => 'Not connected (Returns invalid JSON)',
404 'warning' => true,
405 ];
406 }
407
408 return [
409 'value' => 'Connected',
410 ];
411 }
412
413 /**
414 * @param $paths [] Paths to check permissions.
415 * @return array []{read: bool, write: bool, execute: bool}
416 */
417 public function get_paths_permissions( $paths ) : array {
418 $permissions = [];
419
420 foreach ( $paths as $key_path => $path ) {
421 $permissions[ $key_path ] = $this->get_path_permissions( $path );
422 }
423
424 return $permissions;
425 }
426
427 /**
428 * Get path by path key.
429 *
430 * @param $path_key
431 * @return string
432 */
433 public function get_system_path( $path_key ) : string {
434 switch ( $path_key ) {
435 case static::KEY_PATH_WP_ROOT_DIR:
436 return ABSPATH;
437
438 case static::KEY_PATH_WP_CONTENT_DIR:
439 return WP_CONTENT_DIR;
440
441 case static::KEY_PATH_HTACCESS_FILE:
442 return file_exists( ABSPATH . '/.htaccess' ) ? ABSPATH . '/.htaccess' : '';
443
444 case static::KEY_PATH_UPLOADS_DIR:
445 return wp_upload_dir()['basedir'] ?? '';
446
447 case static::KEY_PATH_ELEMENTOR_UPLOADS_DIR:
448 return ! empty( wp_upload_dir()['basedir'] ) ? wp_upload_dir()['basedir'] . '/elementor' : '';
449
450 default:
451 return '';
452 }
453 }
454
455 /**
456 * Check the permissions of a path.
457 *
458 * @param $path
459 * @return array{read: bool, write: bool, execute: bool}
460 */
461 public function get_path_permissions( $path ) : array {
462 if ( empty( $path ) ) {
463 return [
464 'read' => false,
465 'write' => false,
466 'execute' => false,
467 ];
468 }
469
470 return [
471 'read' => is_readable( $path ),
472 'write' => is_writeable( $path ),
473 'execute' => is_executable( $path ),
474 ];
475 }
476 }
477