Files
roi-theme/wp-content/plugins/wp-debug/inc/admin-menu.php

225 lines
8.8 KiB
PHP

<?php
/**
* Admin Menu
*
* @package WP_Debug
* @since 1.0.0
*/
// Exit if accessed directly
if (!defined('ABSPATH')) {
exit;
}
/**
* WP_Debug_Admin_Menu class
*/
class WP_Debug_Admin_Menu {
/**
* Initialize admin menu
*/
public static function init() {
// Add menu page under Tools
add_management_page(
__('WP Debug', 'wp-debug'), // Page title
__('WP Debug', 'wp-debug'), // Menu title
'manage_options', // Capability
'wp-debug', // Menu slug
array(__CLASS__, 'render_dashboard'), // Callback
99 // Position
);
// Enqueue admin styles and scripts
add_action('admin_enqueue_scripts', array(__CLASS__, 'enqueue_admin_assets'));
}
/**
* Render dashboard page
*/
public static function render_dashboard() {
// Check user capabilities
if (!current_user_can('manage_options')) {
return;
}
?>
<div class="wrap wp-debug-dashboard">
<h1><?php echo esc_html(get_admin_page_title()); ?></h1>
<div class="wp-debug-header">
<p><?php _e('Sistema avanzado de debug y diagnóstico para WordPress', 'wp-debug'); ?></p>
<p><strong><?php _e('Versión:', 'wp-debug'); ?></strong> <?php echo esc_html(WP_DEBUG_VERSION); ?></p>
</div>
<div class="wp-debug-cards">
<!-- Status Card -->
<div class="wp-debug-card">
<h2><?php _e('Estado del Sistema', 'wp-debug'); ?></h2>
<p>
<strong><?php _e('Debug Activo:', 'wp-debug'); ?></strong>
<?php echo get_option('wp_debug_enabled', true) ? '<span class="status-active">✓ Activo</span>' : '<span class="status-inactive">✗ Inactivo</span>'; ?>
</p>
<p>
<strong><?php _e('WordPress:', 'wp-debug'); ?></strong>
<?php echo esc_html(get_bloginfo('version')); ?>
</p>
<p>
<strong><?php _e('PHP:', 'wp-debug'); ?></strong>
<?php echo esc_html(phpversion()); ?>
</p>
<p>
<strong><?php _e('Tema Activo:', 'wp-debug'); ?></strong>
<?php echo esc_html(wp_get_theme()->get('Name')); ?>
</p>
</div>
<!-- Modules Card -->
<div class="wp-debug-card">
<h2><?php _e('Módulos Instalados', 'wp-debug'); ?></h2>
<?php
$modules = WP_Debug_Autoloader::get_modules();
foreach ($modules as $module_name => $module_data) {
$enabled = get_option('wp_debug_module_' . $module_name, $module_data['enabled']);
$status_class = $enabled ? 'status-active' : 'status-inactive';
$status_text = $enabled ? '✓ Activo' : '✗ Inactivo';
echo '<p><strong>' . esc_html(ucwords(str_replace('_', ' ', $module_name))) . ':</strong> <span class="' . esc_attr($status_class) . '">' . esc_html($status_text) . '</span></p>';
}
?>
</div>
<!-- Quick Actions Card -->
<div class="wp-debug-card">
<h2><?php _e('Acciones Rápidas', 'wp-debug'); ?></h2>
<p><a href="#" class="button button-secondary" onclick="alert('Panel de logs próximamente')">📋 Ver Logs</a></p>
<p><a href="#" class="button button-secondary" onclick="alert('Monitor de hooks próximamente')">🔌 Hooks Monitor</a></p>
<p><a href="#" class="button button-secondary" onclick="alert('Template tracer próximamente')">📄 Templates</a></p>
<p><a href="#" class="button button-secondary" onclick="alert('Asset tracker próximamente')">📦 Assets</a></p>
<p><a href="#" class="button button-secondary" onclick="alert('Performance profiler próximamente')">⚡ Performance</a></p>
<p><a href="#" class="button button-secondary" onclick="alert('Query analyzer próximamente')">🗄️ Queries</a></p>
</div>
<!-- WP-CLI Commands Card -->
<div class="wp-debug-card">
<h2><?php _e('Comandos WP-CLI', 'wp-debug'); ?></h2>
<code>wp debug status</code><br>
<code>wp debug hooks</code><br>
<code>wp debug templates</code><br>
<code>wp debug export</code><br>
<code>wp debug clear</code>
<p><small><?php _e('Ejecuta estos comandos desde la terminal para diagnóstico avanzado', 'wp-debug'); ?></small></p>
</div>
</div>
<div class="wp-debug-info">
<h3><?php _e('Información del Plugin', 'wp-debug'); ?></h3>
<p><?php _e('WP Debug es un sistema de diagnóstico avanzado que te permite:', 'wp-debug'); ?></p>
<ul>
<li>✓ <?php _e('Monitorear hooks de WordPress en tiempo real', 'wp-debug'); ?></li>
<li>✓ <?php _e('Rastrear templates y template-parts cargados', 'wp-debug'); ?></li>
<li>✓ <?php _e('Analizar assets CSS/JS con dependencias', 'wp-debug'); ?></li>
<li>✓ <?php _e('Medir performance y detectar bottlenecks', 'wp-debug'); ?></li>
<li>✓ <?php _e('Analizar queries SQL y detectar problemas N+1', 'wp-debug'); ?></li>
<li>✓ <?php _e('Panel visual flotante en frontend (solo admins)', 'wp-debug'); ?></li>
<li>✓ <?php _e('Comandos WP-CLI para diagnóstico desde terminal', 'wp-debug'); ?></li>
</ul>
</div>
</div>
<style>
.wp-debug-dashboard {
max-width: 1200px;
}
.wp-debug-header {
background: #f0f0f1;
padding: 20px;
margin: 20px 0;
border-left: 4px solid #2271b1;
}
.wp-debug-cards {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 20px;
margin: 20px 0;
}
.wp-debug-card {
background: #fff;
border: 1px solid #c3c4c7;
padding: 20px;
box-shadow: 0 1px 1px rgba(0,0,0,0.04);
}
.wp-debug-card h2 {
margin-top: 0;
font-size: 1.2em;
border-bottom: 2px solid #2271b1;
padding-bottom: 10px;
}
.wp-debug-card p {
margin: 10px 0;
}
.wp-debug-card code {
display: block;
background: #f0f0f1;
padding: 5px 10px;
margin: 5px 0;
font-family: monospace;
}
.status-active {
color: #00a32a;
font-weight: bold;
}
.status-inactive {
color: #d63638;
font-weight: bold;
}
.wp-debug-info {
background: #fff;
border: 1px solid #c3c4c7;
padding: 20px;
margin: 20px 0;
}
.wp-debug-info ul {
list-style: none;
padding-left: 0;
}
.wp-debug-info li {
padding: 5px 0;
}
</style>
<?php
}
/**
* Enqueue admin assets
*
* @param string $hook Current admin page hook
*/
public static function enqueue_admin_assets($hook) {
// Only load on our admin page
if ('tools_page_wp-debug' !== $hook) {
return;
}
// Enqueue admin CSS if exists
if (file_exists(WP_DEBUG_PLUGIN_DIR . 'assets/css/admin.css')) {
wp_enqueue_style(
'wp-debug-admin',
WP_DEBUG_PLUGIN_URL . 'assets/css/admin.css',
array(),
WP_DEBUG_VERSION
);
}
// Enqueue admin JS if exists
if (file_exists(WP_DEBUG_PLUGIN_DIR . 'assets/js/admin.js')) {
wp_enqueue_script(
'wp-debug-admin',
WP_DEBUG_PLUGIN_URL . 'assets/js/admin.js',
array('jquery'),
WP_DEBUG_VERSION,
true
);
}
}
}