| @@ -1,14 +1,16 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -namespace PXLBSAdminify\Inc\Classes; | |
| 3 | +namespace WPAdminify\Inc\Classes; | |
| 4 | 4 | |
| 5 | +use WPAdminify\Inc\Utils; | |
| 6 | + | |
| 5 | 7 | // no direct access allowed |
| 6 | 8 | if (!defined('ABSPATH')) { |
| 7 | 9 | exit; |
| 8 | 10 | } |
| 9 | 11 | /** |
| 10 | - * PXLBSAdminify | |
| 12 | + * WPAdminify | |
| 11 | 13 | * Admin Menu: Server Info |
| 12 | 14 | * |
| 13 | 15 | * @author Jewel Theme <support@jeweltheme.com> |
| 14 | 16 | */ |
| @@ -37,14 +39,14 @@ | ||
| 37 | 39 | $checks = []; |
| 38 | 40 | foreach ([0, 1] as $i) { |
| 39 | 41 | $cmd = '/proc/stat'; |
| 40 | 42 | $lines = []; |
| 41 | - $fh = fopen($cmd, 'r'); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fopen -- reading the /proc special path not supported by WP_Filesystem. | |
| 43 | + $fh = fopen($cmd, 'r'); | |
| 42 | 44 | if ($fh) { |
| 43 | 45 | while ($line = fgets($fh)) { |
| 44 | 46 | $lines[] = $line; |
| 45 | 47 | } |
| 46 | - fclose($fh); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose -- closing the /proc special path not supported by WP_Filesystem. | |
| 48 | + fclose($fh); | |
| 47 | 49 | } |
| 48 | 50 | foreach ($lines as $line) { |
| 49 | 51 | $ma = []; |
| 50 | 52 | if (!preg_match('/^cpu (\d+) (\d+) (\d+) (\d+) (\d+) (\d+) (\d+) (\d+) (\d+) (\d+)$/', $line, $ma)) { |
| @@ -115,9 +117,8 @@ | ||
| 115 | 117 | $memory_limit = '-1 / ' . esc_html__('Unlimited', 'adminify') . ' (' . (int) WP_MEMORY_LIMIT . ' MB)'; |
| 116 | 118 | } |
| 117 | 119 | |
| 118 | 120 | if ((int) WP_MEMORY_LIMIT < (int) @ini_get('memory_limit') && WP_MEMORY_LIMIT != '-1' || (int) WP_MEMORY_LIMIT < (int) @ini_get('memory_limit') && @ini_get('memory_limit') != '-1') { |
| 119 | - /* translators: %s: Server PHP memory limit, e.g. "256 MB" */ | |
| 120 | 121 | $memory_limit .= ' <span class="warning"><span class="dashicons dashicons-warning"></span> ' . sprintf(__('The WP PHP Memory Limit is less than the %s Server PHP Memory Limit', 'adminify'), (int) @ini_get('memory_limit') . ' MB') . '!</span>'; |
| 121 | 122 | } |
| 122 | 123 | |
| 123 | 124 | return $memory_limit; |
| @@ -138,9 +139,8 @@ | ||
| 138 | 139 | $php_version = PHP_VERSION; |
| 139 | 140 | } |
| 140 | 141 | |
| 141 | 142 | if ($php_version != 'N/A' && version_compare($php_version, '7.3', '<')) { |
| 142 | - /* translators: 1: Current PHP version, 2: Link to WordPress requirements page */ | |
| 143 | 143 | $php_version = '<span class="warning"><span class="dashicons dashicons-warning"></span> ' . sprintf(__('%1$s - Recommend PHP version of 7.3. See: %2$s', 'adminify'), esc_html($php_version), '<a href="https://wordpress.org/about/requirements/" target="_blank" rel="noopener">' . __('WordPress Requirements', 'adminify') . '</a>') . '</span>'; |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | return $php_version; |
| @@ -192,9 +192,9 @@ | ||
| 192 | 192 | |
| 193 | 193 | // Short Version |
| 194 | 194 | // $db_version = $wpdb->db_server_info(); |
| 195 | 195 | |
| 196 | - $db_version_dump = $wpdb->get_var('SELECT VERSION() AS version from DUAL'); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- direct query required for reading the live MySQL server version; not cached intentionally. | |
| 196 | + $db_version_dump = $wpdb->get_var('SELECT VERSION() AS version from DUAL'); | |
| 197 | 197 | if (preg_match('/\d+(?:\.\d+)+/', $db_version_dump, $matches)) { |
| 198 | 198 | $db_version = $matches[0]; // returning the first match |
| 199 | 199 | } else { |
| 200 | 200 | $db_version = __('N/A', 'adminify'); |
| @@ -210,9 +210,9 @@ | ||
| 210 | 210 | */ |
| 211 | 211 | public function get_db_software() |
| 212 | 212 | { |
| 213 | 213 | global $wpdb; |
| 214 | - $db_software_query = $wpdb->get_row("SHOW VARIABLES LIKE 'version_comment'"); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- direct query required for reading the live MySQL server variable; not cached intentionally. | |
| 214 | + $db_software_query = $wpdb->get_row("SHOW VARIABLES LIKE 'version_comment'"); | |
| 215 | 215 | $db_software_dump = $db_software_query->Value; |
| 216 | 216 | if (!empty($db_software_dump)) { |
| 217 | 217 | $db_soft_array = explode(' ', trim($db_software_dump)); |
| 218 | 218 | $db_software = $db_soft_array[0]; |
| @@ -285,9 +285,9 @@ | ||
| 285 | 285 | $result = 0; |
| 286 | 286 | |
| 287 | 287 | // Linux server |
| 288 | 288 | if ($os == 'Linux') { |
| 289 | - $fh = fopen('/proc/meminfo', 'r'); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fopen -- reading the /proc special path not supported by WP_Filesystem. | |
| 289 | + $fh = fopen('/proc/meminfo', 'r'); | |
| 290 | 290 | if ($fh) { |
| 291 | 291 | while ($line = fgets($fh)) { |
| 292 | 292 | $pieces = []; |
| 293 | 293 | if (preg_match('/^MemTotal:\s+(\d+)\skB$/', $line, $pieces)) { |
| @@ -296,9 +296,9 @@ | ||
| 296 | 296 | $result = round($result / 1024 / 1024, 2); |
| 297 | 297 | break; |
| 298 | 298 | } |
| 299 | 299 | } |
| 300 | - fclose($fh); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose -- closing the /proc special path not supported by WP_Filesystem. | |
| 300 | + fclose($fh); | |
| 301 | 301 | return $result; |
| 302 | 302 | } |
| 303 | 303 | } |
| 304 | 304 | |
| @@ -319,9 +319,9 @@ | ||
| 319 | 319 | $result = 0; |
| 320 | 320 | |
| 321 | 321 | // Linux server |
| 322 | 322 | if ($os == 'Linux') { |
| 323 | - $fh = fopen('/proc/meminfo', 'r'); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fopen -- reading the /proc special path not supported by WP_Filesystem. | |
| 323 | + $fh = fopen('/proc/meminfo', 'r'); | |
| 324 | 324 | if ($fh) { |
| 325 | 325 | while ($line = fgets($fh)) { |
| 326 | 326 | $pieces = []; |
| 327 | 327 | if (preg_match('/^MemFree:\s+(\d+)\skB$/', $line, $pieces)) { |
| @@ -329,9 +329,9 @@ | ||
| 329 | 329 | $result = round($pieces[1] / 1024 / 1024, 2); |
| 330 | 330 | break; |
| 331 | 331 | } |
| 332 | 332 | } |
| 333 | - fclose($fh); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose -- closing the /proc special path not supported by WP_Filesystem. | |
| 333 | + fclose($fh); | |
| 334 | 334 | |
| 335 | 335 | return $result; |
| 336 | 336 | } |
| 337 | 337 | } |
| @@ -354,9 +354,9 @@ | ||
| 354 | 354 | if ($os == 'Linux') { |
| 355 | 355 | |
| 356 | 356 | $ram_data = ''; |
| 357 | 357 | // Check if it readable |
| 358 | - $fh = fopen('/proc/meminfo', 'r'); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fopen -- reading the /proc special path not supported by WP_Filesystem. | |
| 358 | + $fh = fopen('/proc/meminfo', 'r'); | |
| 359 | 359 | if ($fh) { |
| 360 | 360 | foreach (file('/proc/meminfo') as $ri) { |
| 361 | 361 | $m[strtok($ri, ':')] = strtok(''); |
| 362 | 362 | } |
| @@ -405,24 +405,14 @@ | ||
| 405 | 405 | * WP Memory Usage |
| 406 | 406 | */ |
| 407 | 407 | public function get_wp_memory_usage() |
| 408 | 408 | { |
| 409 | - // Get PHP memory limit | |
| 410 | - $php_memory_limit = ini_get('memory_limit'); | |
| 411 | - | |
| 412 | - // Get WordPress memory limit if defined | |
| 413 | - $wordpress_memory_limit = defined('WP_MEMORY_LIMIT') ? WP_MEMORY_LIMIT : null; | |
| 414 | - | |
| 415 | - // Determine the effective memory limit with PHP memory limit taking priority | |
| 416 | - $get_memory_limit = $php_memory_limit ? $php_memory_limit : $wordpress_memory_limit; | |
| 417 | - | |
| 418 | - | |
| 419 | 409 | // Get WP Memory Limit |
| 420 | - // $get_memory_limit = WP_MEMORY_LIMIT; | |
| 421 | - // if ((int) WP_MEMORY_LIMIT > (int) @ini_get('memory_limit')) { | |
| 422 | - // // WP Limit can't be greater than Server Limiit | |
| 423 | - // $get_memory_limit = @ini_get('memory_limit'); | |
| 424 | - // } | |
| 410 | + $get_memory_limit = WP_MEMORY_LIMIT; | |
| 411 | + if ((int) WP_MEMORY_LIMIT > (int) @ini_get('memory_limit')) { | |
| 412 | + // WP Limit can't be greater than Server Limiit | |
| 413 | + $get_memory_limit = @ini_get('memory_limit'); | |
| 414 | + } | |
| 425 | 415 | |
| 426 | 416 | $memory_limit_convert = $this->convert_memory_size($get_memory_limit); |
| 427 | 417 | $memory_limit_format = size_format($memory_limit_convert); |
| 428 | 418 | $memory_limit = $memory_limit_convert; |
| @@ -501,9 +491,9 @@ | ||
| 501 | 491 | return 'N/A'; |
| 502 | 492 | } |
| 503 | 493 | |
| 504 | 494 | |
| 505 | - public static function memory_usage_percentage() | |
| 495 | + public static function wp_memory_usage_percentage() | |
| 506 | 496 | { |
| 507 | 497 | $memory_usage = (new ServerInfo())->get_wp_memory_usage(); |
| 508 | 498 | $memory_usage_percentage = $memory_usage['MemUsageCalc']; |
| 509 | 499 | return $memory_usage_percentage; |
| @@ -530,12 +520,9 @@ | ||
| 530 | 520 | $result['free'] = 0; |
| 531 | 521 | $result['used'] = 0; |
| 532 | 522 | |
| 533 | 523 | $lines = null; |
| 534 | - // $path defaults to '/'. Escape it before composing the shell | |
| 535 | - // command so any future caller-supplied path can't break out | |
| 536 | - // into additional commands. | |
| 537 | - exec( sprintf( 'df /P %s', escapeshellarg( $path ) ), $lines ); | |
| 524 | + exec(sprintf('df /P %s', $path), $lines); | |
| 538 | 525 | |
| 539 | 526 | foreach ($lines as $index => $line) { |
| 540 | 527 | if ($index != 1) { |
| 541 | 528 | continue; |