| 1 |
<?php |
| 2 |
defined('ABSPATH') or die('Unauthorized Access'); |
| 3 |
|
| 4 |
global $wpdb; |
| 5 |
|
| 6 |
function phpinfowp_fmt_bytes(int $bytes): string { |
| 7 |
if ($bytes >= GB_IN_BYTES) return round($bytes / GB_IN_BYTES, 2) . ' GB'; |
| 8 |
if ($bytes >= MB_IN_BYTES) return round($bytes / MB_IN_BYTES, 1) . ' MB'; |
| 9 |
if ($bytes >= KB_IN_BYTES) return round($bytes / KB_IN_BYTES, 1) . ' KB'; |
| 10 |
return $bytes . ' B'; |
| 11 |
} |
| 12 |
|
| 13 |
function phpinfowp_dirsize_safe(string $path): string { |
| 14 |
if (!is_dir($path)) return '—'; |
| 15 |
$size = get_dirsize($path); |
| 16 |
return $size ? phpinfowp_fmt_bytes((int)$size) : '—'; |
| 17 |
} |
| 18 |
|
| 19 |
// EOL status for the PHP badge |
| 20 |
$eol = Phpinfo_WP_EOL::status(); |
| 21 |
$eol_colors = ['ok' => '#00a32a', 'warning' => '#996800', 'eol' => '#d63638', 'unknown' => '#666']; |
| 22 |
$eol_color = $eol_colors[$eol['status']] ?? '#666'; |
| 23 |
|
| 24 |
// Memory |
| 25 |
$mem_limit = ini_get('memory_limit'); |
| 26 |
$mem_used = memory_get_usage(true); |
| 27 |
$mem_limit_b = wp_convert_hr_to_bytes($mem_limit); |
| 28 |
$mem_pct = $mem_limit_b > 0 ? round($mem_used / $mem_limit_b * 100) : 0; |
| 29 |
|
| 30 |
// DB |
| 31 |
$db_version = $wpdb->get_var('SELECT VERSION()') ?? '—'; |
| 32 |
$db_size_raw = $wpdb->get_var($wpdb->prepare( |
| 33 |
"SELECT SUM(data_length + index_length) FROM information_schema.tables WHERE table_schema = %s", |
| 34 |
DB_NAME |
| 35 |
)); |
| 36 |
$db_size = $db_size_raw ? phpinfowp_fmt_bytes((int)$db_size_raw) : '—'; |
| 37 |
|
| 38 |
// cURL |
| 39 |
$curl_ver = function_exists('curl_version') ? (curl_version()['version'] ?? '—') : __('not loaded', 'phpinfo-wp'); |
| 40 |
|
| 41 |
// Server |
| 42 |
$server_soft = $_SERVER['SERVER_SOFTWARE'] ?? '—'; |
| 43 |
?> |
| 44 |
|
| 45 |
<div class="phpinfowp-info-page"> |
| 46 |
|
| 47 |
<div class="phpinfowp-page-header"> |
| 48 |
<div> |
| 49 |
<h1><?php _e('Server Overview', 'phpinfo-wp'); ?></h1> |
| 50 |
<p class="phpinfowp-page-subtitle"><?php _e('PHP, WordPress, server, and database environment at a glance', 'phpinfo-wp'); ?></p> |
| 51 |
</div> |
| 52 |
</div> |
| 53 |
|
| 54 |
<div class="phpinfowp-info-grid"> |
| 55 |
|
| 56 |
<!-- PHP --> |
| 57 |
<div class="phpinfowp-info-card" style="border-top:3px solid <?php echo $eol_color; ?>"> |
| 58 |
<div class="phpinfowp-info-card-label"><?php _e('PHP Version', 'phpinfo-wp'); ?></div> |
| 59 |
<div class="phpinfowp-info-card-value"><?php echo esc_html(PHP_VERSION); ?></div> |
| 60 |
<div class="phpinfowp-info-card-sub"> |
| 61 |
<span style="display:inline-block;padding:2px 7px;border-radius:3px;font-size:10px;font-weight:700;letter-spacing:.4px;background:<?php echo $eol_color; ?>;color:#fff"> |
| 62 |
<?php |
| 63 |
if ($eol['status'] === 'eol') echo esc_html__('END OF LIFE', 'phpinfo-wp'); |
| 64 |
elseif ($eol['status'] === 'warning') echo esc_html__('EOL SOON', 'phpinfo-wp'); |
| 65 |
else echo esc_html__('SUPPORTED', 'phpinfo-wp'); |
| 66 |
?> |
| 67 |
</span> |
| 68 |
<div style="margin-top:4px;color:<?php echo $eol_color; ?>"> |
| 69 |
<?php |
| 70 |
if ($eol['status'] === 'eol') echo esc_html__('Upgrade immediately', 'phpinfo-wp'); |
| 71 |
elseif ($eol['status'] === 'warning') printf(esc_html__('EOL in %sd — %s', 'phpinfo-wp'), $eol['days'], $eol['eol']); |
| 72 |
elseif ($eol['status'] === 'ok') printf(esc_html__('Until %s', 'phpinfo-wp'), $eol['eol']); |
| 73 |
else echo esc_html__('EOL date unknown', 'phpinfo-wp'); |
| 74 |
?> |
| 75 |
</div> |
| 76 |
</div> |
| 77 |
</div> |
| 78 |
|
| 79 |
<!-- WordPress --> |
| 80 |
<div class="phpinfowp-info-card" style="border-top:3px solid #2271b1"> |
| 81 |
<div class="phpinfowp-info-card-label"><?php _e('WordPress', 'phpinfo-wp'); ?></div> |
| 82 |
<div class="phpinfowp-info-card-value"><?php echo esc_html(get_bloginfo('version')); ?></div> |
| 83 |
<div class="phpinfowp-info-card-sub"> |
| 84 |
<?php echo is_multisite() ? esc_html__('Multisite network', 'phpinfo-wp') : esc_html__('Single site', 'phpinfo-wp'); ?><br> |
| 85 |
<?php |
| 86 |
$active_plugins_count = count(get_option('active_plugins')); |
| 87 |
printf( |
| 88 |
_n('%s active plugin', '%s active plugins', $active_plugins_count, 'phpinfo-wp'), |
| 89 |
number_format_i18n($active_plugins_count) |
| 90 |
); |
| 91 |
?> |
| 92 |
</div> |
| 93 |
</div> |
| 94 |
|
| 95 |
<!-- Memory --> |
| 96 |
<div class="phpinfowp-info-card" style="border-top:3px solid <?php echo $mem_pct > 85 ? '#d63638' : '#777BB3'; ?>"> |
| 97 |
<div class="phpinfowp-info-card-label"><?php _e('Memory Usage', 'phpinfo-wp'); ?></div> |
| 98 |
<div class="phpinfowp-info-card-value"><?php echo esc_html(phpinfowp_fmt_bytes($mem_used)); ?></div> |
| 99 |
<div class="phpinfowp-info-card-sub"> |
| 100 |
<?php printf( |
| 101 |
/* translators: 1: memory limit, 2: percentage value */ |
| 102 |
__('of %1$s limit (%2$s%%)', 'phpinfo-wp'), |
| 103 |
esc_html($mem_limit), |
| 104 |
$mem_pct |
| 105 |
); ?> |
| 106 |
<div class="phpinfowp-mini-bar-wrap"> |
| 107 |
<div class="phpinfowp-mini-bar" style="width:<?php echo min(100,$mem_pct); ?>%;background:<?php echo $mem_pct > 85 ? '#d63638' : '#777BB3'; ?>"></div> |
| 108 |
</div> |
| 109 |
</div> |
| 110 |
</div> |
| 111 |
|
| 112 |
<!-- Database --> |
| 113 |
<div class="phpinfowp-info-card" style="border-top:3px solid #00a32a"> |
| 114 |
<div class="phpinfowp-info-card-label"><?php _e('Database', 'phpinfo-wp'); ?></div> |
| 115 |
<div class="phpinfowp-info-card-value" style="font-size:18px"><?php echo esc_html($db_version); ?></div> |
| 116 |
<div class="phpinfowp-info-card-sub"> |
| 117 |
<?php echo esc_html(DB_NAME); ?><br> |
| 118 |
<?php printf(esc_html__('%s total size', 'phpinfo-wp'), esc_html($db_size)); ?> |
| 119 |
</div> |
| 120 |
</div> |
| 121 |
|
| 122 |
</div> |
| 123 |
|
| 124 |
<h2 class="phpinfowp-section-heading"><?php _e('Environment Details', 'phpinfo-wp'); ?></h2> |
| 125 |
<table class="wp-list-table widefat fixed striped phpinfowp-info-table"> |
| 126 |
<tbody> |
| 127 |
|
| 128 |
<tr><th colspan="2" class="phpinfowp-info-section-head"><?php _e('WordPress', 'phpinfo-wp'); ?></th></tr> |
| 129 |
<tr><td><?php _e('Site URL', 'phpinfo-wp'); ?></td><td><code><?php echo esc_html(get_site_url()); ?></code></td></tr> |
| 130 |
<tr><td><?php _e('Home URL', 'phpinfo-wp'); ?></td><td><code><?php echo esc_html(get_home_url()); ?></code></td></tr> |
| 131 |
<tr><td><?php _e('WP Version', 'phpinfo-wp'); ?></td><td><?php echo esc_html(get_bloginfo('version')); ?></td></tr> |
| 132 |
<tr><td><?php _e('Active Theme', 'phpinfo-wp'); ?></td><td><?php echo esc_html(wp_get_theme()->get('Name')); ?> <?php echo esc_html(wp_get_theme()->get('Version')); ?></td></tr> |
| 133 |
<tr><td><?php _e('Active Plugins', 'phpinfo-wp'); ?></td><td> |
| 134 |
<?php |
| 135 |
$active_count = count(get_option('active_plugins')); |
| 136 |
$installed_count = count(get_plugins()); |
| 137 |
printf( |
| 138 |
/* translators: 1: active plugins count, 2: installed plugins count */ |
| 139 |
__('%1$s of %2$s installed', 'phpinfo-wp'), |
| 140 |
$active_count, |
| 141 |
$installed_count |
| 142 |
); |
| 143 |
?> |
| 144 |
</td></tr> |
| 145 |
<tr><td><?php _e('Active Themes', 'phpinfo-wp'); ?></td><td> |
| 146 |
<?php |
| 147 |
$themes_count = count(wp_get_themes()); |
| 148 |
printf( |
| 149 |
_n('%s installed', '%s installed', $themes_count, 'phpinfo-wp'), |
| 150 |
number_format_i18n($themes_count) |
| 151 |
); |
| 152 |
?> |
| 153 |
</td></tr> |
| 154 |
<tr><td><?php _e('Debug Mode', 'phpinfo-wp'); ?></td> |
| 155 |
<td><?php if (defined('WP_DEBUG') && WP_DEBUG): ?> |
| 156 |
<span style="color:#d63638;font-weight:600"><?php _e('ON', 'phpinfo-wp'); ?></span> — <?php _e('disable in production', 'phpinfo-wp'); ?> |
| 157 |
<?php else: ?> |
| 158 |
<span style="color:#00a32a"><?php _e('Off', 'phpinfo-wp'); ?></span> |
| 159 |
<?php endif; ?></td></tr> |
| 160 |
<tr><td><?php _e('Admin Email', 'phpinfo-wp'); ?></td><td><?php echo esc_html(get_option('admin_email')); ?></td></tr> |
| 161 |
|
| 162 |
<tr><th colspan="2" class="phpinfowp-info-section-head"><?php _e('PHP', 'phpinfo-wp'); ?></th></tr> |
| 163 |
<tr><td><?php _e('PHP Version', 'phpinfo-wp'); ?></td><td><?php echo esc_html(PHP_VERSION); ?></td></tr> |
| 164 |
<tr><td><?php _e('PHP SAPI', 'phpinfo-wp'); ?></td><td><?php echo esc_html(PHP_SAPI); ?></td></tr> |
| 165 |
<tr><td><?php _e('Memory Limit', 'phpinfo-wp'); ?></td><td><?php echo esc_html(ini_get('memory_limit')); ?></td></tr> |
| 166 |
<tr><td><?php _e('Max Execution Time', 'phpinfo-wp'); ?></td><td><?php echo esc_html(ini_get('max_execution_time')); ?>s</td></tr> |
| 167 |
<tr><td><?php _e('Upload Max Filesize', 'phpinfo-wp'); ?></td><td><?php echo esc_html(ini_get('upload_max_filesize')); ?></td></tr> |
| 168 |
<tr><td><?php _e('Post Max Size', 'phpinfo-wp'); ?></td><td><?php echo esc_html(ini_get('post_max_size')); ?></td></tr> |
| 169 |
<tr><td><?php _e('Max Input Vars', 'phpinfo-wp'); ?></td><td><?php echo esc_html(ini_get('max_input_vars')); ?></td></tr> |
| 170 |
<tr><td><?php _e('Display Errors', 'phpinfo-wp'); ?></td><td><?php echo ini_get('display_errors') ? '<span style="color:#d63638">' . __('On', 'phpinfo-wp') . '</span>' : '<span style="color:#00a32a">' . __('Off', 'phpinfo-wp') . '</span>'; ?></td></tr> |
| 171 |
<tr><td><?php _e('cURL Version', 'phpinfo-wp'); ?></td><td><?php echo esc_html($curl_ver); ?></td></tr> |
| 172 |
<tr><td><?php _e('Loaded Extensions', 'phpinfo-wp'); ?></td><td><?php echo count(get_loaded_extensions()); ?></td></tr> |
| 173 |
|
| 174 |
<tr><th colspan="2" class="phpinfowp-info-section-head"><?php _e('Server', 'phpinfo-wp'); ?></th></tr> |
| 175 |
<tr><td><?php _e('Server Software', 'phpinfo-wp'); ?></td><td><?php echo esc_html($server_soft); ?></td></tr> |
| 176 |
<tr><td><?php _e('Server Name', 'phpinfo-wp'); ?></td><td><?php echo esc_html($_SERVER['SERVER_NAME'] ?? '—'); ?></td></tr> |
| 177 |
<tr><td><?php _e('Document Root', 'phpinfo-wp'); ?></td><td><code><?php echo esc_html($_SERVER['DOCUMENT_ROOT'] ?? ABSPATH); ?></code></td></tr> |
| 178 |
<tr><td><?php _e('Operating System', 'phpinfo-wp'); ?></td><td><?php echo esc_html(PHP_OS_FAMILY . ' ' . php_uname('r')); ?></td></tr> |
| 179 |
<tr><td><?php _e('Hostname', 'phpinfo-wp'); ?></td><td><?php echo esc_html(gethostname() ?: '—'); ?></td></tr> |
| 180 |
|
| 181 |
<tr><th colspan="2" class="phpinfowp-info-section-head"><?php _e('Database', 'phpinfo-wp'); ?></th></tr> |
| 182 |
<tr><td><?php _e('MySQL Version', 'phpinfo-wp'); ?></td><td><?php echo esc_html($db_version); ?></td></tr> |
| 183 |
<tr><td><?php _e('Database Name', 'phpinfo-wp'); ?></td><td><?php echo esc_html(DB_NAME); ?></td></tr> |
| 184 |
<tr><td><?php _e('Database Host', 'phpinfo-wp'); ?></td><td><?php echo esc_html(DB_HOST); ?></td></tr> |
| 185 |
<tr><td><?php _e('Table Prefix', 'phpinfo-wp'); ?></td><td><code><?php echo esc_html($wpdb->prefix); ?></code></td></tr> |
| 186 |
<tr><td><?php _e('Database Size', 'phpinfo-wp'); ?></td><td><?php echo esc_html($db_size); ?></td></tr> |
| 187 |
<tr><td><?php _e('Charset', 'phpinfo-wp'); ?></td><td><?php echo esc_html(DB_CHARSET); ?></td></tr> |
| 188 |
|
| 189 |
<tr><th colspan="2" class="phpinfowp-info-section-head"><?php _e('Disk', 'phpinfo-wp'); ?></th></tr> |
| 190 |
<tr><td><?php _e('Root Directory', 'phpinfo-wp'); ?></td><td><?php echo esc_html(phpinfowp_dirsize_safe(ABSPATH)); ?></td></tr> |
| 191 |
<tr><td><?php _e('Uploads Directory', 'phpinfo-wp'); ?></td><td><?php echo esc_html(phpinfowp_dirsize_safe(WP_CONTENT_DIR . '/uploads')); ?></td></tr> |
| 192 |
|
| 193 |
</tbody> |
| 194 |
</table> |
| 195 |
</div> |