← All changes
|
modules/system-info/reporters/server.php
+30
-38
4.2.0-dev2
→
3.8.0-beta1
View file →
| @@ -1,9 +1,8 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | namespace Elementor\Modules\System_Info\Reporters; |
| 3 | 3 | |
| 4 | 4 | use Elementor\Api; |
| 5 | -use Elementor\Utils; | |
| 6 | 5 | |
| 7 | 6 | if ( ! defined( 'ABSPATH' ) ) { |
| 8 | 7 | exit; // Exit if accessed directly. |
| 9 | 8 | } |
| @@ -17,8 +16,9 @@ | ||
| 17 | 16 | * @since 1.0.0 |
| 18 | 17 | */ |
| 19 | 18 | class Server extends Base { |
| 20 | 19 | |
| 20 | + const KEY_PATH_WP_ROOT_DIR = 'wp_root'; | |
| 21 | 21 | const KEY_PATH_WP_CONTENT_DIR = 'wp_content'; |
| 22 | 22 | const KEY_PATH_UPLOADS_DIR = 'uploads'; |
| 23 | 23 | const KEY_PATH_ELEMENTOR_UPLOADS_DIR = 'elementor_uploads'; |
| 24 | 24 | const KEY_PATH_HTACCESS_FILE = '.htaccess'; |
| @@ -98,9 +98,9 @@ | ||
| 98 | 98 | * } |
| 99 | 99 | */ |
| 100 | 100 | public function get_software() { |
| 101 | 101 | return [ |
| 102 | - 'value' => Utils::get_super_global_value( $_SERVER, 'SERVER_SOFTWARE' ), | |
| 102 | + 'value' => $_SERVER['SERVER_SOFTWARE'], | |
| 103 | 103 | ]; |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | /** |
| @@ -122,16 +122,11 @@ | ||
| 122 | 122 | public function get_php_version() { |
| 123 | 123 | $result = [ |
| 124 | 124 | 'value' => PHP_VERSION, |
| 125 | 125 | ]; |
| 126 | - $recommended_php_version = '7.4'; | |
| 127 | 126 | |
| 128 | - if ( version_compare( $result['value'], $recommended_php_version, '<' ) ) { | |
| 129 | - $result['recommendation'] = sprintf( | |
| 130 | - /* translators: %s: Recommended PHP version. */ | |
| 131 | - esc_html__( 'We recommend using PHP version %s or higher.', 'elementor' ), | |
| 132 | - $recommended_php_version | |
| 133 | - ); | |
| 127 | + if ( version_compare( $result['value'], '5.4', '<' ) ) { | |
| 128 | + $result['recommendation'] = _x( 'We recommend to use php 5.4 or higher', 'System Info', 'elementor' ); | |
| 134 | 129 | |
| 135 | 130 | $result['warning'] = true; |
| 136 | 131 | } |
| 137 | 132 | |
| @@ -153,9 +148,9 @@ | ||
| 153 | 148 | * } |
| 154 | 149 | */ |
| 155 | 150 | public function get_php_memory_limit() { |
| 156 | 151 | $result = [ |
| 157 | - 'value' => (string) ini_get( 'memory_limit' ), | |
| 152 | + 'value' => (string) get_cfg_var( 'memory_limit' ), | |
| 158 | 153 | ]; |
| 159 | 154 | |
| 160 | 155 | $min_recommended_memory = '128M'; |
| 161 | 156 | $preferred_memory = '256M'; |
| @@ -165,10 +160,10 @@ | ||
| 165 | 160 | $min_recommended_bytes = wp_convert_hr_to_bytes( $min_recommended_memory ); |
| 166 | 161 | |
| 167 | 162 | if ( $memory_limit_bytes < $min_recommended_bytes ) { |
| 168 | 163 | $result['recommendation'] = sprintf( |
| 169 | - /* translators: 1: Minimum recommended_memory, 2: Preferred memory, 3: WordPress wp-config memory documentation. */ | |
| 170 | - __( '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' ), | |
| 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' ), | |
| 171 | 166 | $min_recommended_memory, |
| 172 | 167 | $preferred_memory, |
| 173 | 168 | 'https://go.elementor.com/wordpress-wp-config-memory/' |
| 174 | 169 | ); |
| @@ -314,10 +309,18 @@ | ||
| 314 | 309 | * @type bool $warning Whether to display a warning. True if some required |
| 315 | 310 | * folders don't have writing permissions, False otherwise. |
| 316 | 311 | * } |
| 317 | 312 | */ |
| 318 | - public function get_write_permissions(): array { | |
| 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 | + | |
| 319 | 321 | $paths_to_check = [ |
| 322 | + static::KEY_PATH_WP_ROOT_DIR => $this->get_system_path( static::KEY_PATH_WP_ROOT_DIR ), | |
| 320 | 323 | static::KEY_PATH_HTACCESS_FILE => $this->get_system_path( static::KEY_PATH_HTACCESS_FILE ), |
| 321 | 324 | static::KEY_PATH_UPLOADS_DIR => $this->get_system_path( static::KEY_PATH_UPLOADS_DIR ), |
| 322 | 325 | static::KEY_PATH_ELEMENTOR_UPLOADS_DIR => $this->get_system_path( static::KEY_PATH_ELEMENTOR_UPLOADS_DIR ), |
| 323 | 326 | ]; |
| @@ -325,20 +328,14 @@ | ||
| 325 | 328 | $paths_permissions = $this->get_paths_permissions( $paths_to_check ); |
| 326 | 329 | |
| 327 | 330 | $write_problems = []; |
| 328 | 331 | |
| 329 | - if ( ! $paths_permissions[ static::KEY_PATH_UPLOADS_DIR ]['write'] ) { | |
| 330 | - $write_problems[] = 'WordPress uploads directory'; | |
| 332 | + foreach ( $paths_permissions as $key_path => $path_permissions ) { | |
| 333 | + if ( ! $path_permissions['write'] ) { | |
| 334 | + $write_problems[] = $paths_messages[ $key_path ]; | |
| 335 | + } | |
| 331 | 336 | } |
| 332 | 337 | |
| 333 | - if ( $paths_permissions[ self::KEY_PATH_ELEMENTOR_UPLOADS_DIR ]['exists'] && ! $paths_permissions[ self::KEY_PATH_ELEMENTOR_UPLOADS_DIR ]['write'] ) { | |
| 334 | - $write_problems[] = 'Elementor uploads directory'; | |
| 335 | - } | |
| 336 | - | |
| 337 | - if ( $paths_permissions[ self::KEY_PATH_HTACCESS_FILE ]['exists'] && ! $paths_permissions[ self::KEY_PATH_HTACCESS_FILE ]['write'] ) { | |
| 338 | - $write_problems[] = '.htaccess file'; | |
| 339 | - } | |
| 340 | - | |
| 341 | 338 | if ( $write_problems ) { |
| 342 | 339 | $value = 'There are some writing permissions issues with the following directories/files:' . "\n\t\t - "; |
| 343 | 340 | |
| 344 | 341 | $value .= implode( "\n\t\t - ", $write_problems ); |
| @@ -347,9 +344,9 @@ | ||
| 347 | 344 | } |
| 348 | 345 | |
| 349 | 346 | return [ |
| 350 | 347 | 'value' => $value, |
| 351 | - 'warning' => (bool) $write_problems, | |
| 348 | + 'warning' => ! ! $write_problems, | |
| 352 | 349 | ]; |
| 353 | 350 | } |
| 354 | 351 | |
| 355 | 352 | /** |
| @@ -414,11 +411,11 @@ | ||
| 414 | 411 | } |
| 415 | 412 | |
| 416 | 413 | /** |
| 417 | 414 | * @param $paths [] Paths to check permissions. |
| 418 | - * @return array []{exists: bool, read: bool, write: bool, execute: bool} | |
| 415 | + * @return array []{read: bool, write: bool, execute: bool} | |
| 419 | 416 | */ |
| 420 | - public function get_paths_permissions( $paths ): array { | |
| 417 | + public function get_paths_permissions( $paths ) : array { | |
| 421 | 418 | $permissions = []; |
| 422 | 419 | |
| 423 | 420 | foreach ( $paths as $key_path => $path ) { |
| 424 | 421 | $permissions[ $key_path ] = $this->get_path_permissions( $path ); |
| @@ -432,10 +429,13 @@ | ||
| 432 | 429 | * |
| 433 | 430 | * @param $path_key |
| 434 | 431 | * @return string |
| 435 | 432 | */ |
| 436 | - public function get_system_path( $path_key ): string { | |
| 433 | + public function get_system_path( $path_key ) : string { | |
| 437 | 434 | switch ( $path_key ) { |
| 435 | + case static::KEY_PATH_WP_ROOT_DIR: | |
| 436 | + return ABSPATH; | |
| 437 | + | |
| 438 | 438 | case static::KEY_PATH_WP_CONTENT_DIR: |
| 439 | 439 | return WP_CONTENT_DIR; |
| 440 | 440 | |
| 441 | 441 | case static::KEY_PATH_HTACCESS_FILE: |
| @@ -444,16 +444,10 @@ | ||
| 444 | 444 | case static::KEY_PATH_UPLOADS_DIR: |
| 445 | 445 | return wp_upload_dir()['basedir'] ?? ''; |
| 446 | 446 | |
| 447 | 447 | case static::KEY_PATH_ELEMENTOR_UPLOADS_DIR: |
| 448 | - if ( empty( wp_upload_dir()['basedir'] ) ) { | |
| 449 | - return ''; | |
| 450 | - } | |
| 448 | + return ! empty( wp_upload_dir()['basedir'] ) ? wp_upload_dir()['basedir'] . '/elementor' : ''; | |
| 451 | 449 | |
| 452 | - $elementor_uploads_dir = wp_upload_dir()['basedir'] . '/elementor'; | |
| 453 | - | |
| 454 | - return is_dir( $elementor_uploads_dir ) ? $elementor_uploads_dir : ''; | |
| 455 | - | |
| 456 | 450 | default: |
| 457 | 451 | return ''; |
| 458 | 452 | } |
| 459 | 453 | } |
| @@ -461,14 +455,13 @@ | ||
| 461 | 455 | /** |
| 462 | 456 | * Check the permissions of a path. |
| 463 | 457 | * |
| 464 | 458 | * @param $path |
| 465 | - * @return array{exists: bool, read: bool, write: bool, execute: bool} | |
| 459 | + * @return array{read: bool, write: bool, execute: bool} | |
| 466 | 460 | */ |
| 467 | - public function get_path_permissions( $path ): array { | |
| 461 | + public function get_path_permissions( $path ) : array { | |
| 468 | 462 | if ( empty( $path ) ) { |
| 469 | 463 | return [ |
| 470 | - 'exists' => false, | |
| 471 | 464 | 'read' => false, |
| 472 | 465 | 'write' => false, |
| 473 | 466 | 'execute' => false, |
| 474 | 467 | ]; |
| @@ -474,9 +467,8 @@ | ||
| 474 | 467 | ]; |
| 475 | 468 | } |
| 476 | 469 | |
| 477 | 470 | return [ |
| 478 | - 'exists' => true, | |
| 479 | 471 | 'read' => is_readable( $path ), |
| 480 | 472 | 'write' => is_writeable( $path ), |
| 481 | 473 | 'execute' => is_executable( $path ), |
| 482 | 474 | ]; |