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

414 lines 9.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 /**
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 $db_server_version_string = $db_server_version['version_comment']->Value . ' v';
279
280 // On some hosts, `innodb_version` is empty, in PHP 8.1.
281 if ( isset( $db_server_version['innodb_version'] ) ) {
282 $db_server_version_string .= $db_server_version['innodb_version']->Value;
283 } else {
284 $db_server_version_string .= $wpdb->get_var( 'SELECT VERSION() AS version' );
285 }
286
287 return [
288 'value' => $db_server_version_string,
289 ];
290 }
291
292 /**
293 * Get write permissions.
294 *
295 * Check whether the required folders has writing permissions.
296 *
297 * @since 1.9.0
298 * @access public
299 *
300 * @return array {
301 * Report data.
302 *
303 * @type string $value Writing permissions status.
304 * @type bool $warning Whether to display a warning. True if some required
305 * folders don't have writing permissions, False otherwise.
306 * }
307 */
308 public function get_write_permissions() {
309 $paths_to_check = [
310 ABSPATH => 'WordPress root directory',
311 ];
312
313 $write_problems = [];
314
315 $wp_upload_dir = wp_upload_dir();
316
317 if ( $wp_upload_dir['error'] ) {
318 $write_problems[] = 'WordPress root uploads directory';
319 }
320
321 $elementor_uploads_path = $wp_upload_dir['basedir'] . '/elementor';
322
323 if ( is_dir( $elementor_uploads_path ) ) {
324 $paths_to_check[ $elementor_uploads_path ] = 'Elementor uploads directory';
325 }
326
327 $htaccess_file = ABSPATH . '/.htaccess';
328
329 if ( file_exists( $htaccess_file ) ) {
330 $paths_to_check[ $htaccess_file ] = '.htaccess file';
331 }
332
333 foreach ( $paths_to_check as $dir => $description ) {
334 if ( ! is_writable( $dir ) ) {
335 $write_problems[] = $description;
336 }
337 }
338
339 if ( $write_problems ) {
340 $value = 'There are some writing permissions issues with the following directories/files:' . "\n\t\t - ";
341
342 $value .= implode( "\n\t\t - ", $write_problems );
343 } else {
344 $value = 'All right';
345 }
346
347 return [
348 'value' => $value,
349 'warning' => ! ! $write_problems,
350 ];
351 }
352
353 /**
354 * Check for elementor library connectivity.
355 *
356 * Check whether the remote elementor library is reachable.
357 *
358 * @since 1.0.0
359 * @access public
360 *
361 * @return array {
362 * Report data.
363 *
364 * @type string $value The status of elementor library connectivity.
365 * @type bool $warning Whether to display a warning. True if elementor
366 * * library is not reachable, False otherwise.
367 * }
368 */
369 public function get_elementor_library() {
370 $response = wp_remote_get(
371 Api::$api_info_url, [
372 'timeout' => 5,
373 'body' => [
374 // Which API version is used
375 'api_version' => ELEMENTOR_VERSION,
376 // Which language to return
377 'site_lang' => get_bloginfo( 'language' ),
378 ],
379 ]
380 );
381
382 if ( is_wp_error( $response ) ) {
383 return [
384 'value' => 'Not connected (' . $response->get_error_message() . ')',
385 'warning' => true,
386 ];
387 }
388
389 $http_response_code = wp_remote_retrieve_response_code( $response );
390
391 if ( 200 !== (int) $http_response_code ) {
392 $error_msg = 'HTTP Error (' . $http_response_code . ')';
393
394 return [
395 'value' => 'Not connected (' . $error_msg . ')',
396 'warning' => true,
397 ];
398 }
399
400 $info_data = json_decode( wp_remote_retrieve_body( $response ), true );
401
402 if ( empty( $info_data ) ) {
403 return [
404 'value' => 'Not connected (Returns invalid JSON)',
405 'warning' => true,
406 ];
407 }
408
409 return [
410 'value' => 'Connected',
411 ];
412 }
413 }
414