// Helper aman
if (!function_exists(‘convert_to_mb’)) {
function convert_to_mb($val) {
$val = trim($val);
if ($val === ” || $val === ‘-1’) return 0; $last = strtolower($val[strlen($val)-1]); $num = (float) $val; switch($last) { case 'g': $num *= 1024; break; case 'k': $num /= 1024; break; } return $num; }
}
add_action(‘wp_dashboard_setup’, function () {
wp_add_dashboard_widget(
‘ram_usage_widget’,
‘Monitor RAM Server (Lite)’,
‘ram_usage_widget_display’
);
});
function ram_usage_widget_display() {if (!is_admin() || !current_user_can('manage_options')) { return; } $memory_limit_raw = ini_get('memory_limit') ?: '0'; $limit_mb = convert_to_mb($memory_limit_raw); $memory_used = memory_get_usage(true); $memory_peak = memory_get_peak_usage(true); $used_mb = round($memory_used / 1048576, 2); $peak_mb = round($memory_peak / 1048576, 2); $percent = $limit_mb > 0 ? round(($used_mb / $limit_mb) * 100, 2) : 0; // Biar tidak lebih dari 100% $percent = min($percent, 100); // Warna $color = 'green'; if ($percent > 80) { $color = 'red'; } elseif ($percent > 60) { $color = 'orange'; } ?> <div style="padding:10px;"> <div style="width:100%; background:#eee; border-radius:10px; overflow:hidden; margin-bottom:10px;"> <div style="width:<?php echo esc_attr($percent); ?>%; background:<?php echo esc_attr($color); ?>; color:white; padding:6px; text-align:center;"> <?php echo esc_html($percent); ?>% </div> </div> <p><strong>PHP Memory Limit:</strong> <?php echo esc_html($memory_limit_raw); ?></p> <p><strong>Digunakan:</strong> <?php echo esc_html($used_mb); ?> MB</p> <p><strong>Puncak:</strong> <?php echo esc_html($peak_mb); ?> MB</p> <?php if ($limit_mb == 0): ?> <p style="color:blue;"><strong>ℹ️ Unlimited Memory</strong></p> <?php endif; ?> <hr> <p style="color:green; font-weight:bold;"> ✅ Super ringan — tanpa beban server </p> </div> <?php
}

